Scratch: How to make A Space Dodger Game in 5 minutes

Everyone likes to play Star War game with Spaceship Shooting. In this article, we will cover how to make a simple space dodger game. Let discuss creating of the game.

Space Dodger Game Play

Once upon a time, in our Space, there is spaceship moving around by a pilot to avoid being hit by space rock.

  1. Add a Space backdrop and change the backdrop1 background color to be red.
Space backdrop
Space backdrop
  1. Next create 3 Sprites character – spaceship, rock and a BOOM.
Space SpriteS
Space SpriteS
  1. Add the following variables – avoided, blaster, gap time, score and warp speed.
variables
variables

Rock sprite code

  1. In green flag event, set the size to 22% and hide.
  2. Create clone of myself and waited gap time variable second.
  3. In the blaster fired event, delete the rock clone.
rock code1
rock code1
  1. In the start clone event, set the size of rock randomly from 20 ~50%
  2. If the pick random between 1 to 10 is 1,
    1. Switch the costume of rock to space dog.
    2. Remember space dog is another costume in the rock.
  3. Next, go to x:200 and y: random 1 to -240 to 240.
  4. Turn clockwise 15 degrees and change the x by -1* warp speed.
  5. If x position < -240, then change avoided by 1 and broadcast update score event.
  6. Finally, delete the rock clone.
rock code2
rock code2

SpaceShip sprite code

  1. In green flag event, if touching the rock, broadcast gameover event.
  2. And in another green flag event, we will change the costume (next costume) for every 0.2 seconds.
  3. When space key pressed event, if blaster value >0 then
    1. Play laser2 sound
    2. Change the blaster by -1
    3. Change the backdrop to red color background
    4. Wait for 0.05 seconds and change back to space backdrop.
    5. Finally, broadcast blaster fired event.
SpaceShip code1
SpaceShip code1
  1. In the main green flag, we will switch the backdrop to space.
  2. Go to x: -200, y: 0 and set point to 180 directions.
  3. Next, set the variables default value
    1. warp speed = 5;
    2. score and avoided = 0;
    3. gap time = 2;
    4. blaster = 3;
  4. Detect up arrow and down arrow to change the y by 10 and -10.
  5. When I receive update score.,
    1. If avoided mod 5 = 0,
      1. change score to 1
    2. if gap time > 0.5 seconds
      1. set gap time to 0.9* gap time.
SpaceShip code2
SpaceShip code2

BOOM explosion

  1. In the green flag, hide the BOOM.
  2. Next, in the gamoever event, go to x:0, y:0 and show the sprite.
  3. Then, stop all script.
boom code
boom code

Let play our game and here is the link to the code.

Space dodger demo
Space dodger demo

Thanks for reading and enjoy your day.

Leave a comment