Skip to content

Cross-platform scroll wheel support + argparse display/fps + safer serve timer - #1

Open
TheCodingSoldier wants to merge 1 commit into
mainfrom
feature/cross-platform-improvements
Open

TheCodingSoldier wants to merge 1 commit into
mainfrom
feature/cross-platform-improvements

Conversation

@TheCodingSoldier

Copy link
Copy Markdown
Owner

What this PR does

Makes Encode-A-Pong work cleanly on any computer with a scroll wheel mouse (Windows, macOS, desktop Linux) while keeping the Raspberry Pi Zero 2 W + Kuman 3.5" experience 100% identical.

Running python3 pong.py with no arguments on the Pi = zero behaviour change.


Changes (safe, additive only)

1. argparse CLI arguments (all default to current Pi values)

python3 pong.py                     # identical to before — 480×320 @ 30fps
python3 pong.py --width 800 --height 480   # custom display
python3 pong.py --fps 60                   # desktop smooth framerate

2. is_pi_framebuffer() platform detection

  • Checks for /dev/fb0 (only exists on Linux framebuffer systems like Pi)
  • Pi: mouse cursor stays hidden (same as before)
  • Desktop: mouse cursor stays visible so the OS cursor doesn't disappear

3. round() instead of int() for scroll accumulation

  • int(scroll_accum * PADDLE_SPEED) silently drops small fractional scroll inputs
  • round() preserves them → paddle feels more responsive on high-precision mice
  • No impact on Pi encoder (which always emits whole integer ticks)

4. Timestamp-based serve timer (pygame.time.get_ticks())

  • Old: serve_timer -= dt — could behave inconsistently if dt spikes on first frame
  • New: serve_until = now + SERVE_DELAY_MS / if now < serve_until: — rock solid on all hardware
  • Same 800 ms delay, same feel

5. AI_PADDLE_X moved inside run()

  • Was a module-level constant using hardcoded WIDTH
  • Now calculated after argparse so it correctly uses whatever --width is passed
  • On Pi with no args: same value 480 - 10 - 8 = 462

What was NOT changed

  • All collision logic — untouched
  • All drawing code — untouched
  • All game constants (WIN_SCORE, PADDLE_SPEED, AI_SPEED, BALL_SPEED_*) — untouched
  • make_bg_surface(), reset_ball(), bounce_ball(), clamp_paddle() — logic unchanged
  • pygame.SCALED + vsync fallback chain — identical
  • pygame.display.update() — kept (correct for Pi framebuffer)
  • SERVE_DELAY_MS = 800 — same value

Testing

  • python3 pong.py on Pi Zero 2 W + Kuman 3.5" display
  • python3 pong.py on desktop Linux
  • python3 pong.py --fps 60 on desktop
  • python3 pong.py --width 800 --height 480 on desktop

Copilot AI lite review requested due to automatic review settings September 19, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The implementation can misidentify desktop Linux, discard fractional scroll input, and accept invalid display dimensions.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 Medium severity · 1 Low severity

Open (4)
What changed in this PR

Adds configurable display size/FPS and cross-platform mouse-wheel behavior while preserving the Raspberry Pi defaults.

Changes:

  • Adds argparse options for width, height, and FPS.
  • Makes paddle positioning and rendering dimension-aware.
  • Replaces frame-delta serve timing with timestamps and updates cursor/scroll handling.
File Description
pong.py Implements CLI configuration, platform detection, dynamic dimensions, scroll handling, and serve timing.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pong.py
Comment on lines +29 to +32
parser.add_argument("--width", type=int, default=480,
help="Display width in pixels (default: 480)")
parser.add_argument("--height", type=int, default=320,
help="Display height in pixels (default: 320)")
Comment thread pong.py
"""Return True when running on a Raspberry Pi framebuffer display.
Detected by the presence of /dev/fb0 (Linux framebuffer device).
On Windows / macOS / desktop Linux this will always return False."""
return os.path.exists("/dev/fb0")
Comment thread pong.py
Comment on lines +209 to 210
player_paddle.y -= round(scroll_accum * PADDLE_SPEED)
scroll_accum = 0.0
Comment thread pong.py
Comment on lines +27 to +35
def parse_args():
parser = argparse.ArgumentParser(description="Encode-A-Pong")
parser.add_argument("--width", type=int, default=480,
help="Display width in pixels (default: 480)")
parser.add_argument("--height", type=int, default=320,
help="Display height in pixels (default: 320)")
parser.add_argument("--fps", type=int, default=30,
help="Target frame rate (default: 30)")
return parser.parse_args()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants