5. Let's race!

Let's race

Racing games are as old as the computer. Time to make one ourselves!
You can again use your creativity to design your own game, but as always the basic elements must be in it.

You learn to:

upload a playing field / backdrop (print or photo from eg Google images)

Register before you start the exercise. Click the button below and sign up.

Click here

ORIENTATION

Take a look at the example and consider the following questions:

  • What should I do?
  • What are the goals?
  • What are the expectations?
  • What can I already do?
  • What do I still have to discover?

PREPARATION

Take a look at the steps at 'perform'. Then answer the following questions:

  • Which steps should I follow?
  • Which steps can I follow?
  • How much time do I need?
  • What tools do I need?

PERFORM

Perform the steps one by one. Do you not remember how to do it? View the hints or download the solution.

STEP 1

You already know it: open the online Scratch editor and delete the cat sprite. Choose a suitable backdrop ("playing field"). Preferably take a top view of something or a neutral backdrop. This time, we do not choose a backdrop from the library, but first look for one via Google, for example. You save your chosen photo locally on your computer, for example on the desktop. Then you choose "upload backdrop".

1

Select your playing field so that you can now update your backdrop: after all, you have to draw a "route" on it and a finish.

64

You select the drawing tool "brush" and then thicken the line that you will draw by adjusting the number, at the top left you can also give your line a nice color instead of the boring black standard color. Now draw your own course.

Make up your own finish: that is the place where your car (or other sprite) has to go. To make it easier for you later on, make sure the finish is a different color from the track.

STEP 2

Now find yourself a nice sprite that suits your game. In our example, that's a cool car. However, the car is too big in our case. Possibly also in your game: it must be possible to drive it between the drawn lines! So resize your sprite to the desired size. Do you remember how to do it?

STEP 3

Now at the start of the game we have to make sure that our sprite is at the start of the track. (Remember: the X and Y number at the bottom of your playing field?). We also make the sprite rotate upwards (= 0 degrees) or to the right if you drew your lines horizontally. Then he must focus on the mouse pointer and move at the same time.

Read the above sentences thoroughly and obtain the correct code. Work step by step.

Try to follow your track now. If your sprite doesn't start in the right place, you'll have to adjust your numbers at x and y.

toelichting

You can also start your game by clicking on your sprite. That is easier to start from your starting position. In our case, your sprite will directly target your mouse pointer (and it's on the green flag…).

toelichting

When your sprite reaches your mouse pointer, something crazy happens. Just give it a try. You can avoid this by telling it to stop when it is less than 10 pixels from your pointer.

And ... test it!

STEP 4

You notice that you can still drive / fly / sail through your walls ... Not really a challenge! We are going to have to complete our code so that the appearance of our sprite changes as soon as it touches the color of your obstacle. In addition, we want to go back to the starting position. If we put that in a loop, the computer will constantly check if this is the case.

toelichting

You determine the color by clicking on the colored square in your code and then go to your colored lines with your "hand" and click again. That way you have exactly the same color. You already learned this in  Pong.

Now also choose an additional sprite with your first sprite so that you can change its appearance when you are "hit". We choose a black cross here.6

It is also nice to play an appropriate sound from the library when you collide.
It is good to take a break if your sprite collides, otherwise it will collide many times ...

 

STEP 5

A race without time ?  To enter the time, we will have to create a variable again. Create a variable and name it 'time'.

70

With which code do we ensure that the time is set to 0 and that it increases by 1 per second? You already made a similar code in the exercise "Make your first game".

If you let the time count down by 0.1 sec, what effect does this have?

Can you stop the game when the time is up?

uitdaging

a) Now create your own code that states that, when you reach the finish:

- a sound effect is playing

- everything stops.

Note: The finish cannot be the same color as your obstacles.

b) Can you give three "lives" at the start of each game? Every time the sprite hits the obstacle, a life is lost. When your lives run out, the game ends.

c) When your player reaches the finish, he / she must move to the next level with a more difficult backdrop ...

achtergrond

REFLECT

Look back at the project you just made. Ask yourself the following questions:

  • Does the program work as I expected? Why / why not?
  • What works well?
  • What works less well?
  • How can I approach it differently?

Download

Click on the link below to download a sample solution.

 

Upload the project in the Scratch environment. Click the button below and follow the steps.

Click here