Part 1: Create Your Own ‘Alien Attack’ Game on Scratch

Alien Attack - TechWise Academy

In May, we introduced Alien Attack, a game we created to highlight many of the lessons we learned through the first three levels of our instructional courses. In this series, we’re going to walk through how to create the game from start to finish. Our hope is you’ll be able to take the lessons learned from creating this game and add to this game on your own or use them to create your own game.

To follow this tutorial start a brand new Scratch project. This first part only starts with the setup of the game, and you’re encouraged to check the full game at the end of the article for reference.

Setup: Backdrop and Sprites

Alien Attack: Sprites and Backdrop

Click to enlarge.

We wanted the player to drive a rocket in space and fight giant alien octopuses for this game. We needed to set a backdrop and create the necessary sprites and objects.

Stage/Backdrop

For the Stage, go to Choose backdrop from library. Select “space” from the “Space” category.

Sprites

Delete the original sprite. Then select Choose new sprite from library for each of our new sprites.

We have 3 distinct sprites or objects in this game:

  • Player1 – that’s you!
  • Laser
  • Octopus

Spaceship

  1. Select “Spaceship” from the “Space” theme.
  2. Go to Costumes at the top of your screen, and rotate the spaceship to face right and center it.
  3. Adjust the size to your liking. We made it a little smaller to fit our game.
  4. Rename the sprite to Player1.

Laser

  1. Select “Paddle” from the “Things” category.
  2. Go to Costumes at the top of your screen, and adjust the size to be a little smaller than your spaceship.
  3. The “Paddle” is green by default. We changed ours to red by using the color tools.
  4. Rename the sprite and costume to Laser.

Octopus

  1. For your enemy, select “Octopus” from the “Animals” category.
  2. Go to Costumes at the top of your screen, and adjust the size to your liking.
  3. Flip it horizontally. For simplicity, you only need to do this on the first costume called “octopus-a.” We do this so the octopus aliens will be facing your spaceship.
  4. Make sure the sprite is named Octopus for this game.

Setup: Variables

We’re going to need a lot of variables in this game. There are a lot of moving parts, and we want the game to get harder as it goes along. See the list of variables below along with why we need them.

New to variables? You can learn more about variables in our other tutorial.

Create all variables in the Data portion of your scripts. Make sure each variable has the For all sprites button checked.

  • BaseSpeed – this is the basic speed of our octopus aliens
  • HP – this is Player1’s health
  • Level – this is your current level to track your progress
  • MaxSpeed – this is the maximum speed we want our octopus aliens to travel
  • MaxTimer – this is the maximum amount of time in between each octopus alien’s spawn
  • MinSpeed – this is the minimum speed we want our octopus alients to travel
  • MinTimer – this is the minimum amount of time in between each octopus alien’s spawn
  • Player_Y_Position – this keeps track of Player1’s current y position (more on this later)
  • Score – this is Player1’s score
  • Seeker_X_Activate – later in the game we make our octopus aliens movement more difficult so this is important later

Once all variables are created, you’re ready to move on!

Setup: Starting the Game

Alien Attack: When starting the gameIn this final setup, we want certain things to happen when the game starts every time.

Before you begin, make sure the Player1 sprite is selected.

Setting Looks, Position, and Data

  1. Go to Events and drag when flag clicked to our workspace on the right
  2. Go to Looks and drag switch costume to spaceship-a to the workspace directly below the flag
  3. Go to Looks and drag switch backdrop to space to the workspace directly below your last block
  4. Go to Motion and drag set y to 0 to our workspace directly below your last block
  5. Go to Motion and drag set x to 0 to our workspace directly below your last block
  6. Change set x to -200 (this sets your spaceship in the same spot at the start of every game)
  7. Go to Data and drag set Score to 0 to the workspace directly below your last block
  8. Go to Data and drag set HP to 0 to the workspace directly below your last block
  9. Go to Data and drag set Level to 0 to the workspace directly below your last block
  10. Go to Data and drag set MinTimer to 0 to the workspace directly below your last block
  11. Go to Data and drag set MaxTimer to 0 to the workspace directly below your last block
  12. Change Score to 0
  13. Change HP to 3
  14. Change Level to 1
  15. Change MinTimer to 1
  16. Change MaxTimer to 3

Go to Data and check the boxes next to HP, Level, and Score so they’re visible at all times.

Adding Space Ripple Sound Effect

We added a space ripple sound effect to play each time the game starts to add a little flair to the game.

Make sure Player1 is still selected.

  1. Go to the Sounds tab at the top of your workspace
  2. Click Choose sound from library button (looks like a speaker)
  3. Click the Effects category
  4. Choose space ripple and click OK
  5. Go to Scripts tab at the top of your workspace
  6. Go to Sound and drag play sound space ripple to the workspace directly below your last block

Click the green flag above your game and see all the variables get set and your sound play!

Now we’re ready for part 2!

See the Full Game