Simply replicate the once dominant mobile game 'Flappy Bird' using an Arduino Nano.
Libraries and Initialization:
- The game uses the Adafruit_GFX and Adafruit_SSD1306 libraries for graphics and display control.
- The display is initialized with a specified width and height (128x64 pixels) for rendering graphics.
- Libraries and Initialization: The game uses the Adafruit_GFX and Adafruit_SSD1306 libraries for graphics and display control. The display is initialized with a specified width and height (128x64 pixels) for rendering graphics.
Game Variables:
Bird Parameters:
- The bird starts at a defined
BIRD_X
position (20) and has a defined width and height (8 pixels). - The flap force is set to -2 for upward movement, and gravity is set to 1 to pull the bird down.
- Bird Parameters:The bird starts at a defined
BIRD_X
position (20) and has a defined width and height (8 pixels). The flap force is set to -2 for upward movement, and gravity is set to 1 to pull the bird down.
Pipe Parameters:
- Each pipe is 5 pixels wide with a gap height of 20 pixels.
- Three pipes are displayed at once, and their initial horizontal positions are calculated based on the screen width.
- Pipe Parameters: Each pipe is 5 pixels wide with a gap height of 20 pixels. Three pipes are displayed at once, and their initial horizontal positions are calculated based on the screen width.
Game State:
- The game keeps track of whether it is over (
game_over
), the bird’s vertical position (birdY
), its velocity, and the score. - Game State: The game keeps track of whether it is over (
game_over
), the bird’s vertical position (birdY
), its velocity, and the score. - Game Variables: Bird Parameters: The bird starts at a defined
BIRD_X
position (20) and has a defined width and height (8 pixels). The flap force is set to -2 for upward movement, and gravity is set to 1 to pull the bird down. Pipe Parameters: Each pipe is 5 pixels wide with a gap height of 20 pixels.Three pipes are displayed at once, and their initial horizontal positions are calculated based on the screen width. Game State: The game keeps track of whether it is over (game_over
), the bird’s vertical position (birdY
), its velocity, and the score.
Setup:
- The button input pin is initialized, and the display is cleared.
- The pipes are initialized with random gap heights to create unique layouts for each new game.
- Setup: The button input pin is initialized, and the display is cleared. The pipes are initialized with random gap heights to create unique layouts for each new game.
Game Loop:
The game continuously checks for player input (button press) to flap the bird, adjusting the bird's velocity accordingly.
- The game continuously checks for player input (button press) to flap the bird, adjusting the bird's velocity accordingly.
Each loop iteration updates the bird's position with its current velocity and applies gravity.
- Each loop iteration updates the bird's position with its current velocity and applies gravity.
Pipe Movement:
- Each pipe’s horizontal position is decreased to simulate movement toward the left of the screen.
- If a pipe moves off-screen, it is reinitialized at the right side with a new random gap height, which also increases the score.
- Pipe Movement: Each pipe’s horizontal position is decreased to simulate movement toward the left of the screen. If a pipe moves off-screen, it is reinitialized at the right side with a new random gap height, which also increases the score.
Collision Detection:
- The game checks for collisions between the bird and the pipes. If the bird collides with a pipe, the game is marked as over.
- Collision Detection: The game checks for collisions between the bird and the pipes. If the bird collides with a pipe, the game is marked as over.
- Game Loop: The game continuously checks for player input (button press) to flap the bird, adjusting the bird's velocity accordingly. Each loop iteration updates the bird's position with its current velocity and applies gravity. Pipe Movement: Each pipe’s horizontal position is decreased to simulate movement toward the left of the screen. If a pipe moves off-screen, it is reinitialized at the right side with a new random gap height, which also increases the score. Collision Detection: The game checks for collisions between the bird and the pipes. If the bird collides with a pipe, the game is marked as over.
Display Updates:
- The display is cleared and redrawn with the new positions of the bird and pipes after each update.
- The current score is displayed at the top of the screen.
- Display Updates: The display is cleared and redrawn with the new positions of the bird and pipes after each update. The current score is displayed at the top of the screen.
Game Over Handling:
- If the game ends, a "Game Over" message and the final score are displayed.
- After a short delay, the game resets, initializing the bird’s position, velocity, pipes, and score for a new round.
- Game Over Handling: If the game ends, a "Game Over" message and the final score are displayed. After a short delay, the game resets, initializing the bird’s position, velocity, pipes, and score for a new round.
Random Gap Generation:
- Unique gap heights for pipes are generated to ensure that no two pipes have the same gap height within the current round.
- Random Gap Generation: Unique gap heights for pipes are generated to ensure that no two pipes have the same gap height within the current round.
Comments
Please log in or sign up to comment.