Repository navigation
Cross-platform scroll wheel support + argparse display/fps + safer serve timer - #1
Open
TheCodingSoldier wants to merge 1 commit into
Open
TheCodingSoldier wants to merge 1 commit into
TheCodingSoldier wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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
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
argparseoptions 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 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)") |
| """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 on lines
+209
to
210
| player_paddle.y -= round(scroll_accum * PADDLE_SPEED) | ||
| scroll_accum = 0.0 |
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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.pywith no arguments on the Pi = zero behaviour change.Changes (safe, additive only)
1.
argparseCLI arguments (all default to current Pi values)2.
is_pi_framebuffer()platform detection/dev/fb0(only exists on Linux framebuffer systems like Pi)3.
round()instead ofint()for scroll accumulationint(scroll_accum * PADDLE_SPEED)silently drops small fractional scroll inputsround()preserves them → paddle feels more responsive on high-precision mice4. Timestamp-based serve timer (
pygame.time.get_ticks())serve_timer -= dt— could behave inconsistently ifdtspikes on first frameserve_until = now + SERVE_DELAY_MS/if now < serve_until:— rock solid on all hardware5.
AI_PADDLE_Xmoved insiderun()WIDTHargparseso it correctly uses whatever--widthis passed480 - 10 - 8 = 462What was NOT changed
WIN_SCORE,PADDLE_SPEED,AI_SPEED,BALL_SPEED_*) — untouchedmake_bg_surface(),reset_ball(),bounce_ball(),clamp_paddle()— logic unchangedpygame.SCALED+ vsync fallback chain — identicalpygame.display.update()— kept (correct for Pi framebuffer)SERVE_DELAY_MS = 800— same valueTesting
python3 pong.pyon Pi Zero 2 W + Kuman 3.5" displaypython3 pong.pyon desktop Linuxpython3 pong.py --fps 60on desktoppython3 pong.py --width 800 --height 480on desktop