Scratch Part 1: Rocket Girl

Open project

Read text instructions. Select Sprite 2 (text), right click text and delete.

Understand: the screen is arranged with point [0,0] in the centre; the stage is 480 units wide by 360 units high so the top left corner is [-240, 180], the bottom left is [-240, -180], the top right is [240, 180] and the bottom right is [240, -180].

Select JetPack sprite. Click Script tab to view scripts, Costumes & Sounds to see what has been added there.

Script

The first code block is a 'When Clicked' with green flag for run. This sets the size of the sprite and its costume. The costumes change during game play. The code uses a Forever block, which runs the code inside until the game is stopped. The code sets a variable xspeed to be xspeed -xspeed/10. The last piece of code then changes the x position (horizontal) by the value of xspeed. At this stage xspeed is zero so the sprite does not move.

The second code block is another 'When Clicked' with green flag for run: in other words when the game is started this code will run. It uses a Forever block so for the duration of the game this code will carry out its instructions. Inside the Forever structure an If statement that checks to see if the left arrow key has been pressed: this construction is the basis of much games play. If the left arrow has been pressed then the x position of the sprite is changed by the amount in the formula - this formula can be changed to make the game run faster or slower. The second instruction sets the value of the direction variable to 1, which means the sprite is facing left.

The third block of code does the same as the second but this time for the right arrow. The last instruction sets the direction variable to 0, which means the sprite is facing right.

As you might have guessed, the fourth and fifth blocks of code check to see if the up arrow key has been pressed (the down arrow key is not needed: can you see why?) The code now becomes quite complex. If the up arrow key is pressed then the code first changes the y speed variable (vertical) so the sprite rises; a sound is also played (easy to change). If the arrow key was not pressed then the else part of the code is run, which includes a further if..else construction. If the sprite is touching something black (sprite 2 has been made black for this purpose) then the y speed is set to zero and the sprite does not move except by 2 steps, caused by the next line. If the sprite is not touching black (else part) then a further test is done to see if it touching the edge of the game area, in which case the y speed is changed and the sprite goes no further. The last instruction is always executed: the sprite's x position increases.

The last block of code also acts on an up key press. This section of code deals with the current direction of the sprite and its costume. If the direction variable is 0 then the sprite is facing right and the costume changes to right-facing with the fire pack lit, otherwise (the direction was 1) the costume changes to left-facing with the fire-pack lit. The second part of the code (else) deals with the situation where the up arrow key has not been pressed, in which case the sprite switches back to plain, facing left or right according to the value of direction.

Extensions

How can you develop this game?

Show the variables so you can check their value during game play.

Edit sprite 2 to make it more interesting (and give it a better name).

Experiment with the speed of the sprite by changing the formulae.

Add a score variable and display it; work out a way to and and take away scores.

One way to change the score would be to add new sprites and have the main sprite touch them.  (Write the script for this in the new sprites area; use a green flag run condition and set the conditions for the duration of the game. Make the new sprite move when hit to a new random location.

Introduce obstacles for the main sprite e.g. a new colour that kills it or a new sprite that kills it.

Add a new key press that fires missiles at objects.