Let's Make A Game!

Introduction
Part 1: Lets Scratch!
Part 2: Lets Move!
Part 3: Let's Broadcast Variable Messages!
Part 5: Let's Get A Job! A Fizz Buzz programming test.

With what we have seen so far we should be able to make a very simple game. To keep things simple we will use three of the sprites that come with Scratch.

  Set the Scene: The Basketball Of Death and the Lamp Shade Of Doom.

You have been sent to the Moon to pick off any invading aliens that may show up. Due to drastic budget cuts your equipment is limited to a lamp shade and a basketball which you will need to fashion into a cannon and a bomb in order to save the planet Earth.

You can play the game here.

  Set the Stage

Select New from the File menu. Select the Stage icon and click on the Backgrounds tab. Click on the Edit button and then the Import button. Select the Nature folder and scroll down to the Moon image and click OK and OK again.

  Load the sprites

To add a new sprite click the middle button (with a folder) below the stage:

Select the Fantasy folder and scroll down to the image called Fantasy6. Click OK. Add another sprite; this time select the Lamp from the Things folder and then the Basketball also from the Things folder. As we will not be needing the Cat right click on it and select Delete from the menu. Rename the Fantasy6 sprite as alien, the Basketball as bomb and the Lamp as cannon.

 Write the scripts

With the Alien sprite selected add a When Green Flag Clicked block to the scripts section. Add a Set X To and Set Y To to position the Alien in the middle (X = 0) near the top (y = 130). As the sprite is too large for our purposes we can reduce its size with a Set Size To 100% block changing the 100 to 40%.

We want the Alien to move back and forth across the screen until we manage to hit it with our basketball of death fired from our lamp shade of doom so we use the Repeat Until and add a Touching block that we set to bomb from the drop down menu.

Inside the Repeat Until block add a Move 10. Above that in the Repeat Until block add two If blocks. Set the If conditions to Greater than > and less than < and check for the X Position of alien is not > 200 or < -200. If the value is outside the range we point the Alien in the opposite direction.

If you do not want the alien flipping upside down when it is moving left you will need to click the middle rotation button. Adding sound will heighten the sense of impending doom. Add a Set Instrument to and select 8 from the drop down menu. Add a Play Note 60 for 0.5 beats to the If blocks above the Point In Direction blocks. Set the value of one to 48 and the other to 50 and set both to play for 0.1 beats.

That will loop our alien back and forth until it is hit by the bomb. When it is hit it will jump out of the Repeat Until loop and look for further instructions..

Select the Cannon sprite and in its Scripts section add a When Green Flag Clicked, Set Size To 60% and a Set X To 0 and Set Y To -180

Select the bomb and add When Green Flag Clicked to its Scripts and Set Size To 20%. Start another script with a When Space Key Pressed block and a Point In Direction which we set to 0/Up. Add a Repeat Until with a Greater than > check for the Y Position of bomb to 130. Add a Move 10 inside the Repeat Until.

Click on the Sounds tab and then the Import button. In the Percussion folder select the DrumBuzz sound and click OK. Back to the Scripts tab and add a Play Sound and select DrumBuzz from the drop down menu.

If you try this the bomb will shoot up and stop. The alien will then hit the bomb and stop. We can add a Hide instruction to the end of the script so when the Repeat Until loop is finished if nothing has been beeen hit then the bomb vanishes. While the bomb is hidden we can put it back at the bottom ready for the next shot with a Set Y to -140. Having hidden the bomb we need to ensure that we show it again when we press the Space bar with a Show block. We can also Set X to the X Position of cannon so the bomb is aligned with the cannon.

Add a Repeat 10 block to the end of the script. Unlike the Repeat Until which keeps looping until a specified condition is met this block sets a number of loops to repeat and then it ends the loop. Change the 10 to a 5 and add a Change Colour Effect By 25 block. Change Colour to Pixellate from the drop down menu and change the 25 to 15. This will cause the alien to disintergrate with each loop. ALternatively you could try the Ghost effect which causes the alien to fade away. To ensure the alien is completely gone add a Hide to the end of the script. The hide should be balanced with a Show block at the start of the script.

As the aliens death is far too quick for us to fully enjoy we can play sounds which add a slight delay to each loop. We can make a variable to adjust the pitch each time we go around the loop. Make a variable called Pitch. Add a set pitch to 0 block to the alien's script before the Repeat 5. Add a Play Note 60 for 0.5 beats in the Repeat loop. Pop a   +   into the 60 slot. Type 55 into the first space and drag the pitch into the second space. Change the .5 beats to .2 beats. Add a Change pitch by 1 block after the Play Note block and change the 1 to -3.

To finish off our little game we can let the player move the Lamp Shade of Doom left and right because we have mastered all that stuff. Do not forget to click the middle rotation button at the top so the lamp is not flipped upside down.

Video Coming Soon!

Introduction
Part 1: Lets Scratch!
Part 2: Lets Move!
Part 3: Let's Broadcast Variable Messages!
Part 5: Let's Get A Job! A Fizz Buzz programming test.

duncanmoran.net