Skip to main content

Overview

Space Birds uses a state machine with three primary states to manage game flow. Each state has distinct visuals, controls, and behaviors.

State Machine

The game uses the GameState enum with three states:
  • MENU: Starting point and main menu
  • PLAYING: Active gameplay
  • GAME_OVER: End screen with final score

State Diagram

The game starts in MENU state when launched and cycles through these states until the application is closed.

Description

The initial state where players can start a new game. This is the default state when the game first launches or after returning from GAME_OVER.

Visual Elements

ElementDescription
BackgroundSpace logo image (space.jpg) filling entire screen
Text Line 1”Pulsa ESPACIO o ENTER para comenzar”
Text Line 2”Controles: FLECHAS para mover, ESPACIO para disparar”
Text Line 3”ENTER para ver puntuación durante el juego”
MusicAngry Birds theme (angry-birds.mp3) looping at 50% volume

Available Controls

SPACE Key

Starts the game → PLAYING

ENTER Key

Starts the game → PLAYING

Touch Screen

Starts the game → PLAYING

State Initialization

When entering MENU state:
  • Background menu music starts playing
  • Game logo is displayed
  • Control instructions are shown
  • Player object exists but is not active
The MENU state does not update obstacles or process gameplay logic. It’s purely a waiting state.

PLAYING State

Description

The active gameplay state where the player controls the bird, shoots bullets, avoids pigs, and accumulates score.

Visual Elements

ElementLocationDescription
BackgroundFull screenNight sky image (noche.jpg)
Player BirdBottom centerRed bird (64×64px) that moves based on input
PigsFalling from topEnemy pigs (62×48px) spawning every 0.5s
BulletsMoving upwardRed projectiles (10×20px) from player
TimerTop-right”Tiempo: Xs” showing survival time
Kill CountTop-right”Asteroides: X” showing pigs destroyed
ScoreTop-right”Puntos: X” showing current total
StatusCenter-bottom”Jugando…” in red text
InstructionsTop-leftESC and ENTER key reminders
Flash EffectFull screenWhite flash when shooting (0.1s duration)

Active Systems

Movement System

Processes keyboard, touch, and mouse input for player movement within screen boundaries

Shooting System

Handles bullet creation with 0.3s cooldown, bullet movement, and removal when off-screen

Spawn System

Generates new pigs every 0.5 seconds at random horizontal positions

Collision System

Detects bullet-pig and bird-pig collisions

Available Controls

InputAction
Arrow KeysMove bird (↑↓←→)
SPACEShoot bullet
Right ClickShoot bullet (alternative)
TouchMove bird toward touch position
ENTERShow score screen overlay
ESCQuit to game over

State Updates

Every frame during PLAYING:
  1. Delta time is calculated
  2. Game time increases
  3. Spawn timer increases (pigs spawn at 0.5s intervals)
  4. Player updates (position, bullets, cooldown)
  5. Obstacles update (position, removal if off-screen)
  6. Collision detection runs for bullets and bird
  7. Flash effect timer decreases if active

Music

Battle music (battle.mp3) loops at 150% volume during PLAYING state.
The music pauses when you open the score screen with ENTER and resumes when you close it.

GAME_OVER State

Description

The end state displayed when the player dies (collision) or quits (ESC). Shows final score and allows return to menu.

Visual Elements

ElementDescription
BackgroundRed screen (solid red fill)
Title Text”GAME OVER” in yellow (center-top)
Score Text”Puntuación final: X” in yellow (center)
Instruction”Pulsa ENTER para volver al menú” (center-bottom)

Score Calculation

When transitioning to GAME_OVER, the final score is calculated:
int tiempoPuntos = (int) gameTime;           // 1 point per second
int asteroidesPuntos = asteroidsDestroyed * 10; // 10 points per kill
score = tiempoPuntos + asteroidesPuntos;
The score is locked in at the moment of game over and cannot change in this state.

Available Controls

ENTER Key Only

Pressing ENTER returns to MENU state
Touch and other inputs are disabled in GAME_OVER state. Only ENTER works.

State Cleanup

The GAME_OVER state does not perform cleanup. When ENTER is pressed and the game returns to MENU, the cleanup happens:
  • All obstacles are cleared from memory
  • Game music stops
  • Menu music starts
  • Score resets to 0
  • Kill counter resets to 0
  • Game time resets to 0
  • Spawn timer resets to 0

State Transitions

Triggers: SPACE key, ENTER key, or Touch input Actions:
  1. Menu music pauses
  2. Battle music starts
  3. Player activates (engine sound plays)
  4. Game time resets to 0
  5. Spawn timer resets to 0
  6. All obstacles cleared
  7. State changes to PLAYING
This transition prepares a fresh game session with clean counters and cleared obstacles.

PLAYING → GAME_OVER

Triggers:
  • Player collision with pig (automatic)
  • ESC key pressed (manual quit)
Actions:
  1. Final score calculated
  2. State changes to GAME_OVER
  3. Game music continues playing until ENTER pressed
  4. Red screen displayed
  5. Score shown
When a collision occurs, the game immediately transitions to GAME_OVER without any “death animation” or delay.

GAME_OVER → MENU

Trigger: ENTER key Actions:
  1. Game music stops
  2. Menu music starts
  3. All obstacles cleared
  4. Score resets to 0
  5. Kill counter resets to 0
  6. Game time resets to 0
  7. Spawn timer resets to 0
  8. State changes to MENU
This transition performs a complete game reset, so you start fresh when entering PLAYING again.

State Management Implementation

State Change Mechanism

The game uses a two-variable system:
private GameState gameState;      // Current active state
private GameState nextGameState;  // Pending state for next frame
private boolean gameStateChanged; // Flag indicating transition pending

Transition Process

1

Trigger Detected

When a state transition is triggered (button press, collision), the game sets:
  • nextGameState to the target state
  • gameStateChanged to true
2

Frame Completes

Current frame finishes rendering with the old state
3

State Change Processed

At the end of the render cycle, if gameStateChanged is true:
  • Cleanup/initialization code runs
  • gameState = nextGameState
  • gameStateChanged = false
4

Next Frame Begins

Next frame renders with the new state
This deferred transition system prevents state changes mid-frame, which could cause rendering glitches or logic errors.

Special State Features

Score Screen Overlay

While in PLAYING state, pressing ENTER shows a score screen overlay:
  • Does NOT change the game state
  • Pauses background music
  • Shows detailed score information
  • Can be dismissed to resume
  • Gameplay continues in background (not paused)
This is not a true “pause” - pigs keep spawning and moving while the score screen is shown!

Pause State

The game has a gamePaused boolean variable, but it’s only used for the score screen overlay feature:
private boolean gamePaused;
This does NOT implement true game pausing - it only tracks UI state.
There is no built-in pause function that stops gameplay. Pressing ESC immediately ends the game.

State-Specific Music

StateMusicVolumeLooping
MENUangry-birds.mp350%Yes
PLAYINGbattle.mp3150%Yes
GAME_OVER(continues previous)--
The battle music volume is set to 150% for an intense gameplay atmosphere. The menu music is gentler at 50%.

Build docs developers (and LLMs) love