Report: driving game
In this post, we are going to explain you how we made our driving game work. We used the programme "Scratch", in which you have to combine different blocks to make objects and other things respond to your actions.
We had to create a game using these 10 blocks obligatory:
This is how the game works:
There are two cars, so you can play alone or in pairs. To win, you have to cross the start/finish line 4 times. There are also two other checkpoints, which you have to go through so the round counts. You can move car 1 (the red one with no number) with the up arrow (forward) the left arrow (tu turn left) and the right arrow (to turn right). Car 2 (the yellow one with the number 2 on it) moves forward by pressing the "w", turns right by pressing the "d" and turns left by pressing the "a".
How we made the car move:
As you can see in the picture above, we used variables. To make the game work the way we wanted to, we created 12 variables.
Laps and check variables:
We used these to count how many times the player crosses the finish line, so he can win after the 4th time he does this.
These blocks in this order make that if the finish line is touching the car, and the player has touched both checkpoints (so that variables check 1 and check 2 equal 1), the player laps (another variable) changes by 1. If the player laps is already 3, then a message its sent to the car object that says "won". You can't see this messaje when you are playing, but it makes that the car who recieved the message says "I win!!!". The instructions are twice because each player has their own variables (for example, "Player 1 laps", "Player 2 laps", "Player 1 check 2", etc.). That is because both cars don't have the same information, because they are not performing the same actions. Something extra is that we hid the "check" variables, so the player can't see them.
Speed variables:
What we did to increase the speed of the car was ordering the blocks so that if you are pressing the up arrow or the w arrow (depending on which car you are playing with), the "speed" variable of that car changes by 1. That makes the car go faster, because we put that when you click on a key that makes the car move (the up arrow, for example) it has to move as many steps as the speed is. For example, if "Speed 1" equals 2, then car 1 will move 2 steps. We made that for both cars, so we had to make 2 speed variables.
The car goes much slowlier when it is on the grass. That is because we programmed that if the car is touching the green color, the speed should set to 1, which makes the car only move 1 step. We also made that if you press the down arrow (in car 1) or the "s" (in car 2), the speed changes by -1. When you are in the grass, if your speed was already less than 0, it will change to -1.
Gas:
We made that the cars can run out of gas.
This is how we did it:
Both gas variables start with 5 (so both cars start with 5 liters). The game waits 8 seconds, and after that the gas variable changes by -1. That happens every 8 seconds. To recharge the gas (make the variable "gas" change and be higher), we created a new object (it's called Object 1 and it's the GAS that the player can see on the track). We ordered the blocks so that if the car is touching that object, its respective variable sets to 4 after a few seconds (only if your gas is already less than 4). If you don't recharge your gas, at some point your gas variable will equal 0, and that makes that the variable "finish" to 1 sets. We will explain how this works now.
Finish variables:
We created two finish variables, one for each car, so that the car stops when its "gas" variable is 0 or less (the car doesn't have any gas).
When the game starts, both "finish" variables are set to 0. When the "gas" variable is 0 or less, the "finish" variable of that same car sets to 1. And all the programmes that make the car move have a block before that says that should only happen if the "finish" variable is 0, so if it is 1 none of that will happen.
This is how we did it:
Both gas variables start with 5 (so both cars start with 5 liters). The game waits 8 seconds, and after that the gas variable changes by -1. That happens every 8 seconds. To recharge the gas (make the variable "gas" change and be higher), we created a new object (it's called Object 1 and it's the GAS that the player can see on the track). We ordered the blocks so that if the car is touching that object, its respective variable sets to 4 after a few seconds (only if your gas is already less than 4). If you don't recharge your gas, at some point your gas variable will equal 0, and that makes that the variable "finish" to 1 sets. We will explain how this works now.
Finish variables:
We created two finish variables, one for each car, so that the car stops when its "gas" variable is 0 or less (the car doesn't have any gas).
When the game starts, both "finish" variables are set to 0. When the "gas" variable is 0 or less, the "finish" variable of that same car sets to 1. And all the programmes that make the car move have a block before that says that should only happen if the "finish" variable is 0, so if it is 1 none of that will happen.