🚀 Space Pirates

Learn Variables, Functions, Events and Game Design by building a complete game.

Step 1: Create the Start Screen

Goal: Create the screen players see before the game begins.

Carefully recreate the blocks shown in the screenshot.

  1. Choose a space background.
  2. Show a title screen and set the title to Space Pirates.
  3. Create a START button sprite.
  4. Create four variables: tutorialStage, hasInitGame, gameStarted and score.
  5. Set their starting values exactly as shown.
Why? Every game needs a starting screen. We also reset all variables so every new game begins in a clean state.
Check Your Work: You should see the title, a START button, and no spaceship yet.

Function: initGame()

Goal: Create a function that prepares the game world.
  1. Create a function called initGame.
  2. Hide the title screen.
  3. Create the player's spaceship.
  4. Set its size to 50.
  5. Make the spaceship draggable.
  6. Create 3 stars and set their size to 30.
Why use a function? Later, we can restart the game simply by calling initGame() instead of rebuilding everything again.

Step 2: Start Button Event

Goal: Start the tutorial when the player clicks START.
  1. Create a "when START clicked" event.
  2. Play a sound.
  3. Remove the START button.
  4. Set hasInitGame to true.
  5. Call initGame().
  6. Show a tutorial message teaching the player how to move.
Check Your Work: Clicking START should create the spaceship and stars.

Function: startGame()

Goal: Create a function that begins the real gameplay.
  1. Create an alien enemy.
  2. Make it wander around the screen.
  3. Show the score variable.
  4. Reset the score to 0.
  5. Hide the tutorial screen.
Keeping gameplay inside its own function makes the project easier to understand and maintain.

Step 3: Build the Tutorial System

Goal: Teach the player how to play before the game starts.
  1. When Space is pressed, increase tutorialStage by 1.
  2. Show different tutorial messages for stages 1, 2 and 3.
  3. At stage 4, call startGame().
  4. Set gameStarted to true.
The gameStarted variable prevents the player from creating multiple aliens by repeatedly pressing Space.

Step 4: Collecting Stars and Increasing Difficulty

Goal: Award points and make the game harder over time.
  1. When the spaceship touches a star, move the star to a random location.
  2. Play a collection sound.
  3. Increase score by 1.
  4. At 10 points, increase the alien speed.
  5. At 20 points, create a second alien.
Check Your Work: The score should increase whenever a star is collected.

Step 5: Create the Game Over Screen

Goal: End the game when the player touches an alien.
  1. Set gameStarted to false.
  2. Set hasInitGame to false.
  3. Remove all sprites.
  4. Show the Game Over title screen.
  5. Display the final score.
  6. Tell the player to press Space to play again.
Resetting the variables allows the game to restart properly.
Check Your Work: Touching an alien should end the game immediately.

🎉 Congratulations!

You Did It! You have completed the Space Pirates project.

By finishing this game, you have learned:

  • ✅ Variables
  • ✅ Functions
  • ✅ Events
  • ✅ Collision Detection
  • ✅ Game States
  • ✅ Difficulty Progression

Keep experimenting! Try adding more aliens, power-ups, levels, or a high score system.

🏆