How to Make a Two-Player Racing Game

Материал из Поле цифровой дидактики
Файл:Racing track.png
An example backdrop
Файл:Racing track finished.png
Add in cars and edit the track as shown here when it is finished.

A two player racing game is a project that lets one compete in racing against another person.

Шаблон:Note

Preparation

Create three sprites:

  • Player 1
  • Player 2
  • Finish Line

Player 1

First, create a new sprite, then change the costume to a car in the Sprites Library where there are sprites, add a if <> then block, then a Point in Direction block, and then add a Шаблон:B block. It should look like this:

 
if <key (right arrow v) pressed> then
point in direction (0)
move (10) steps
end

Continue to do this with the left arrow, down arrow, and so on. Then, place the scripts in a forever block, and under a when green flag clicked block. It should look like this once finished:

when gf clicked
go to x: (. . .::grey) y: (. . .::grey)
forever
if <key (right arrow v) pressed> then
point in direction (0)
move (10) steps
end
if <key (left arrow v) pressed> then
point in direction (-90)
move (10) steps
end
 if <key (down arrow v) pressed> then
point in direction (180)
move (10) steps
end
if <key (up arrow v) pressed> then
point in direction (0)
move (10) steps
end
end

Player 2

For the second player, get another car from the sprites library. Do the same thing as done with player one, only using the W (up), A (left), S (down), and D (right) keys. Once finished, it will look like this:

when gf clicked
go to x: (. . .::grey) y: (. . .::grey)
forever
if <key (w v) pressed> then
point in direction (0)
move (10) steps
end
if <key (s v) pressed> then
point in direction (180)
move (10) steps
end
if <key (a v) pressed> then
point in direction (-90)
move (10) steps
end
if <key (d v) pressed >then
point in direction (90)
move (10) steps
end
end

Backdrop

Go into Paint Editor and paint a backdrop.

Players

Once the backdrop is finished, add the following code to both players:

when gf clicked
forever
if <touching (Finish Line v)?> then
say [I win!] for (.5) seconds
stop [all v]
end
end

Instructions

Player 1 will move with the up, down, left and right keys, and Player 2 will move with the W, A, S and D keys.