Realistic physics, procedural terrain, and input fix - #7
Open
incredibleamir-dot wants to merge 10 commits into
Open
Realistic physics, procedural terrain, and input fix#7incredibleamir-dot wants to merge 10 commits into
incredibleamir-dot wants to merge 10 commits into
Conversation
Rework the game around real SI rocket physics: moon gravity (1.62 m/s^2), mass loss as fuel burns, and engine thrust computed from burn rate x exhaust velocity so thrust-to-weight rises over time. Landing succeeds below 3 m/s while upright on the pad. Fix input: pygame.key.get_pressed() is scancode-indexed, so the old enumerate() keys never matched the K_* constants and no key did anything. Add POLLED_KEYS / pressed_keys() to translate scancodes, with a regression test. Other changes: - Track lander position in float _px/_py so sub-pixel motion is not lost (Rect.move() truncates), fixing a frozen-lander bug - READY -> PLAYING -> RESULT state machine; SPACE launches - Procedural terrain: starfield sky, cratered moon, marked landing pad, irregular shaded boulders that avoid the pad - HUD shows fuel (kg), altitude (m), speed (m/s), mass - Tests updated for SI values; 50 passing
…errain Full rework of the PyGame Lunar Lander into a playable, realistic simulation, now packaged as an installable module. Physics (real SI rocket mechanics): - Moon gravity 1.62 m/s^2, mass loss as fuel burns, 10 kN thrust from burn rate x exhaust velocity, rising thrust-to-weight ratio - Float-position tracking so sub-pixel motion is never lost - Mid-frame fuel exhaustion still delivers partial thrust Gameplay and visuals: - READY -> PLAYING -> RESULT state machine; SPACE launches - Procedural terrain: starfield, cratered moon, marked landing pad, irregular shaded boulders - Fuel (kg) / altitude (m) / speed (m/s) HUD Fixes: - Keyboard input: get_pressed() is scancode-indexed; keys are now built from the K_* constants via pressed_keys() with a regression test - V equality uses math.isclose; load_image converts alpha images properly Packaging and quality: - Split into a package (constants, vectors, assets, terrain, sprites, game) - pyproject.toml with lunar-lander console script and ruff/pytest config - Ruff linting, type hints, GitHub Actions CI (pytest matrix + lint) - 51 passing tests; added main.py local launcher
This CI workflow includes jobs for testing and linting with multiple Python versions.
Removed CI badge from README.
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.
Summary
Reworks the lunar lander into a playable, realistic simulation and fixes a
critical input bug that made every key press dead.
What changed
Realistic rocket physics (SI units)
1.62 m/s², world scaled at8 px/mthrust-to-weight ratio rises ~3.2 → 4.1 as the tank empties (like a real rocket)
3 m/swhile upright on the pad (realistic LMtouchdown speed)
_px/_pypositions (was lost byRect.move()truncation, leaving the lander frozen)Procedural terrain
State machine
READY → PLAYING → RESULT; SPACE launches, no more mid-fall surpriseInput fix (critical)
pygame.key.get_pressed()is scancode-indexed, so keys built fromenumerate(...)never matched theK_*constants and no input registered.Added
POLLED_KEYS/pressed_keys()to translate scancodes to keyconstants, with a regression test.
Testing
pytest -q)Controls