Course: Game Programming (SEM252)
Objective: Master 2D Graphics, Parallax Scrolling, and Frame-based Animation.
- Python 3.11+
- Pygame CE / Pygame
pip install -r requirements.txt
python main.py- SPACE / Left Mouse: Flap / Thrust upwards
- R: Restart when Game Over
- ESC: Quit application
Infinite Flyer is an endless side-scrolling survival game. The player controls a red plane navigating through procedurally generated obstacles while collecting coins. The game features a dynamic difficulty system that increases speed and obstacle frequency over time.
The background consists of 3 distinct layers moving at different relative speeds to create an illusion of depth:
- Layer 1 (Sky): Moves at 15% of the base speed.
- Layer 2 (Mountains): Moves at 35% of the base speed.
- Layer 3 (Ground): Moves at 100% of the base speed, matching the obstacles.
The Math:
To ensure seamless looping without gaps, each layer uses the Modulo Operator (%).
The horizontal offset is calculated as:
self.offset = (self.offset + scroll_speed * relative_speed * dt) % image_width
When drawing, the image is blitted twice (at x = -offset and x = -offset + image_width) to ensure that as one image leaves the screen, the next is already visible.
Animations are decoupled from the application's frame rate using deltaTime. The Animation class tracks a time_accumulator. When the accumulator exceeds the 1 / FPS threshold, the frame index increments. This ensures the plane flaps at the same speed regardless of whether the game is running at 30 FPS or 144 FPS.
To optimize performance and prevent frequent memory allocation/garbage collection, the game utilizes an Object Pool for obstacles and collectibles.
- When an entity moves off-screen to the left, it is not deleted. Instead, it is released back into the pool.
- When a new entity needs to spawn on the right, it is acquired from the pool and reset with new coordinates.
- Dynamic Obstacles: Obstacles move vertically using a Sine wave function (
math.sin(phase)) to create a challenging "moving gate" effect. - Difficulty Scaling: The game tracks elapsed time; every 12 seconds, the "Level" increases, which raises the
scroll_speedand decreases thespawn_interval. - Particle Systems: A custom particle engine emits "exhaust" particles whenever the player flaps, providing visual feedback for player input.
src/core: Engine-level helpers, Object Pool, and Base Entity.src/states: Menu, Play, and Game Over state logic.src/entities: Player, Obstacle, and Collectible logic.src/environment: Parallax background and procedural spawner.src/systems: Animation, Collision, Difficulty, and Particles.src/ui: HUD and text rendering.assets/images: Sprite sheets and background textures.
- Player & Obstacles: "Tappy Plane" by Kenney.nl (CC0).
- Background Layers: "Background Elements" by Kenney.nl (CC0).
- Collectibles: "Spinning Coin" by thepeeps191 (itch.io).
- Sound Effects: "Modern Technology select" from mixkit. "swoosh 4" by Makoto-AE. "Pixel" by Robloxuer. "Coins" by SoundReality.