Posted on

Scratch Coding – Drive by Avoider

The goal of our game this week is to avoid the traffic obstacles on the road. We will control our vehicle by using the arrow keys.

Backdrop

Start by creating a backdrop that looks like a road. I used the rectangle with fill mode turned on for the road base, then the paint bucket tool for the green sides.

Sprites

Feel free to create as many sprites as you would like, be sure to pick one to be the main character.

Our Main Sprite

We want our main character to move left and right.

Hitting the Green and Resetting

We want to add a cool feature where the character will bounce off the green sides. When we test to see if the sprite hits the side green we want to automatically slide the sprite back to the middle of the road. The player will not be able to control this movement, so hopefully no other objects are falling.

Detecting our Objects

We need to test to see if the main player sprite hits an object, we can setup our forever loop to include some tests to see if we are touching the other sprites.

The Falling Sprites

To make our sprites fall, we are going to use the glide block. We must first set the starting location using the go to x: y: block, we use some numbers at the top of the screen. Then we glide to a position at the bottom of the screen. We then hide and wait for a random amount of time before putting the sprite back on the screen.

Setting the Score

We should add some scoring to the game, each time the player gets past an object we change the score by 1. Be sure to set the score to 0 to start with.

Game Over

When our player hits one of our objects, they should show a game over backdrop and stop the game.

Extra

Each new falling object should have a random delay on the time it takes to fall for the first time.

Notice how the first instruction of one of our obstacles is a wait a random amount of time?

More Ideas:

  • Add at least 5 objects that fall at different times
  • Make the player sprite move forward and backwards using the up and down arrow keys
  • Make a countdown timer that only gives the player a certain amount of time: