Top Banner
20

In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Mar 31, 2015

Download

Documents

Donovan Sanburn
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.
Page 2: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

In this tutorial, we are going to create: A race car that the user can control with the arrow

keys for direction and speed. A simulated road with a striped line down the center

showing "speed" and "motion" of car. Obstacles for the car to avoid

Page 3: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

To begin with, we are going to create the stage for our race car game.

Select the Stage, click the Backgrounds tab, then click the Edit button.

Page 4: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Draw a racetrack background similar to the image as shown to the right.

Page 5: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Now that we have our stage, we can begin to create our race car.

Click the Paint new sprite button and draw a racecar from the perspective of looking down at the car from above, similar to the image to the right.

Page 6: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Our race car will be controlled using the Up Arrow, Down Arrow, Left Arrow, and Right Arrow keys. Thus, we need to create scripts for each key.

To begin with, create the Up Arrow script as shown in the image to the right.

This simply moves the car up by 10 when the up arrow is pressed.

Page 7: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Next, create the Down Arrow script as shown in the image to the right.

This script moves the car down by 10 when the down arrow is pressed.

Page 8: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

To simulate a real car, we are going to make the sprite rotate slightly whenever the user presses the left or right arrow keys

Create the Right Arrow script as shown in the image to the right.

Page 9: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Lastly, create the Left Arrow script as shown in the image to the right.

Page 10: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Test all of your arrow keys to ensure your race car is working as intended.

Page 11: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Next we are going to keep track of the racecar’s speed.

Create a new variablevariable (for all sprites) called SpeedSpeed.

Page 12: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Create the script as shown in the image to the right to keep track of the racecar’s speed.

Page 13: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

The next step in this tutorial is to simulate movement and speed.

To do this, click the Paint new sprite button and draw a sprite similar to the image in the right.

Page 14: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

We want our striped line to continually move downwards.

To do this, create the script as shown in the image to the right.

Page 15: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Next, we want the line to appear at the top of the screen once it reaches the bottom of the screen.

To do this, create the script as shown in the image to the right.

You may need to adjust how long to wait depending on how you drew your line sprite.

Page 16: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

The final step in this tutorial is to create obstacles for our racecar to avoid.

Create a new sprite and draw an obstacle.

In this tutorial, we will use a puddle of oil as an example.

Page 17: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

We want the obstacle to repeatedly and randomly appear on the screen.

To accomplish this, create the script as shown to the right.

Page 18: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Lastly, we want our racecar to spin out of control if it touches the oil.

To do this, click your Car sprite and create the script as shown to the right.

Page 19: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Congratulations! You’ve finished your racecar game.

Don’t forget to test your game to ensure everything works properly.

See the next slide for additional challenges to complete.

Page 20: In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.

Add sounds to your gameAdd a score variable that increases by 1

every 3 seconds, but decreases by 5 whenever the car hits the oil, and/or whenever the car leaves the road and drives on the grass.

Add more obstaclesBe creative!