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
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.
For the Stage, go to Choose backdrop from library. Select “space” from the “Space” category.
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!
- Select “Spaceship” from the “Space” theme.
- Go to Costumes at the top of your screen, and rotate the spaceship to face right and center it.
- Adjust the size to your liking. We made it a little smaller to fit our game.
- Rename the sprite to Player1.
- Select “Paddle” from the “Things” category.
- Go to Costumes at the top of your screen, and adjust the size to be a little smaller than your spaceship.
- The “Paddle” is green by default. We changed ours to red by using the color tools.
- Rename the sprite and costume to Laser.
- For your enemy, select “Octopus” from the “Animals” category.
- Go to Costumes at the top of your screen, and adjust the size to your liking.
- 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.
- Make sure the sprite is named Octopus for this game.
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
Before you begin, make sure the Player1 sprite is selected.
Setting Looks, Position, and Data
- Go to Events and drag when flag clicked to our workspace on the right
- Go to Looks and drag switch costume to spaceship-a to the workspace directly below the flag
- Go to Looks and drag switch backdrop to space to the workspace directly below your last block
- Go to Motion and drag set y to 0 to our workspace directly below your last block
- Go to Motion and drag set x to 0 to our workspace directly below your last block
- Change set x to -200 (this sets your spaceship in the same spot at the start of every game)
- Go to Data and drag set Score to 0 to the workspace directly below your last block
- Go to Data and drag set HP to 0 to the workspace directly below your last block
- Go to Data and drag set Level to 0 to the workspace directly below your last block
- Go to Data and drag set MinTimer to 0 to the workspace directly below your last block
- Go to Data and drag set MaxTimer to 0 to the workspace directly below your last block
- Change Score to 0
- Change HP to 3
- Change Level to 1
- Change MinTimer to 1
- 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.
- Go to the Sounds tab at the top of your workspace
- Click Choose sound from library button (looks like a speaker)
- Click the Effects category
- Choose space ripple and click OK
- Go to Scripts tab at the top of your workspace
- 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!