A simple, text-based lunar landing simulation game written in JavaScript and designed to run with the Bun runtime. Test your piloting skills by safely landing a lunar module on the moon!
This script simulates the final descent phase of a lunar landing. You control the lander's thrust to counteract gravity and slow down for a soft touchdown. Manage your fuel carefully and watch your velocity!
- Physics Simulation: Basic physics model including lunar gravity, thrust acceleration, and fuel consumption.
- Real-time Updates: Game state updates at a regular interval (
SIMULATION_TICK_RATE_MS). - User Input: Control the lander's thrust percentage via interactive console input.
- Customizable Missions: Set initial altitude, velocity, fuel, and the maximum safe landing speed before each attempt.
- State Tracking: Monitors altitude, velocity, fuel, and landing/crash status.
- Colorized Output: Uses ANSI color codes for better readability and status indication (e.g., velocity warnings, fuel empty).
- Graceful Exit: Handles Ctrl+C interrupts to show a final report.
- Cross-Platform: Uses standard ANSI escape codes for screen clearing and colors.
- Bun (v1.0 or later recommended)
- Clone the repository:
gh repo clone kriptotekar/bun-moon cd bun-moon or git repo clone kriptotekar/bun-moon cd bun-moon
- Make the script executable (optional but recommended):
chmod +x moon-landing.js
- Run the script using Bun:
Or, if you made it executable:
bun run moon-landing.js
./moon-landing.js
- Parameter Setup: Before launch, you'll be prompted to enter the mission parameters:
- Initial Altitude (meters)
- Initial Downward Velocity (m/s)
- Initial Fuel (kg)
- Maximum Safe Landing Speed (m/s) - This defines your target! (You can press Enter to accept the default values)
- Countdown: A brief countdown sequence will initiate the descent.
- Control Thrust: The simulation will start, displaying the lander's status (Altitude, Velocity, Fuel, Thrust). You will be prompted to enter a thrust percentage (0-100).
- Enter a number between 0 and 100 and press Enter.
- Higher thrust counteracts gravity more but consumes fuel faster.
- Lower thrust conserves fuel but allows gravity to increase your downward speed.
- Monitor Status: Keep an eye on your altitude and velocity. The velocity will be colored:
- Green: Velocity is at or below the safe landing speed you defined.
- Red: Velocity is higher than the safe landing speed.
- Objective: Land the module (
Altitude <= 0) with a finalVelocityless than or equal to theMaximum Safe Landing Speedyou set before running out of fuel. - Outcome:
- Successful Landing: You landed safely within the velocity limit.
- Crash: You hit the surface too fast!
- Out of Fuel: Your engine cuts out if fuel reaches zero. Landing safely becomes much harder!
- Interrupted: If you press Ctrl+C, the simulation ends.
MIT