Super St Patrick

Scratch GameGeographyNormal

St Patrick was legendary for banishing all the snakes from Ireland. In this "Super St Patrick" project we create a game where St Patrick needs to kick out all the snakes from Ireland!

1

Create a Scratch project

Create a Scratch project and delete the cat sprite.

2

Upload the St Patrick and Ireland sprites

Included with this step are 2 sprite files:

  1. a St Patrick character
  2. the island of Ireland

Save these to your computer and then upload them into your project.

3

Add the Snake sprite

Open up the sprite library and add the Snake sprite.


4

Position the island of Ireland

Add the following code to the Ireland sprite to center it and put it behind the other sprites.

when green flag clicked go to x [0] y [0] // place it in the center go to [back v] layer // make it appear behind everything else

We also want to make the backdrop blue to look like to sea. Follow these steps to fill it in blue:

  1. Click on the backdrop in the Backdrop list
  2. Click on the Backdrops tab
  3. Click the Convert to Bitmap button
  4. Select the colour blue in the colour selector tool
  5. Select the Fill tool (paint bucket)
  6. Click on the white of the backdrop to change it to blue

5

Make St Patrick move

Next we will add some code to the St Patrick sprite so that we can make him move around using the arrow keys on our keyboard.

First though add the following code to shrink him and set him up for the start of the game:

when green flag clicked point in direction [90] go to x [0] y [0] // place him in the center set rotation style [left-right v] // this prevents him going upside down when you move him set size to [15] %

Next add the following code so that you can move him up, down, left and right. (Tip: once you have added the code to make him move up, duplicate the block of code 3 times and change it for down, left and right)

when green flag clicked forever if < key (up arrow v) pressed?> then point in direction (0) move (3) steps end end when green flag clicked forever if < key (down arrow v) pressed?> then point in direction (180) move (3) steps end end when green flag clicked forever if < key (left arrow v) pressed?> then point in direction (-90) move (3) steps end end when green flag clicked forever if < key (right arrow v) pressed?> then point in direction (90) move (3) steps end end

Click on the green flag to check your code works by testing to see if you can move him up, down, left and right.



6

Make the snakes attack!

Now lets make lots of snakes attack Ireland! We're going to add code to the snake sprite that will:

  1. create a new snake every few seconds (by creating clones)
  2. change it's appearance
  3. put it in a random position
  4. make it move towards Ireland

Add the following code to the snake sprite:

when green flag clicked set size to (30)% hide // don't show them yet forever change [color v] effect by (25) // change it's colour next costume // there's 3 costumes in this sprite wait (pick random (3) to (8)) seconds create clone of (myself v) // create a new one every 3 to 8 seconds end when I start as a clone go to (random position v) point towards (ireland v) show forever if < touching (ireland v) ?> then move (0) steps // stop the snake once it's touching Ireland else move (2) steps // else keep moving towards Ireland end end

Once you've added this code, click on the green flag to test that the snakes are being created and are attacking Ireland. If anything is not working properly go back and check that your code is the same as the instructions in this step.


7

Banish the snakes and score points

Finally let's add some code to banish the snakes and score points.

Create a variable called 'score'.

Add the 'set score to 0' block to the St Patrick sprite, underneath 'set size to 15 %':

when green flag clicked point in direction [90] go to x [0] y [0] set rotation style [left-right v] set size to [15] % // add new code under here set [score v] to (0) // set the score to 0 at the start

Next we need to add some code to the Snake sprite to detect when St Patrick hits them. Add the following code inside the 'forever block'. Be careful to put it in the right place!

when I start as a clone go to (random position v) point towards (ireland v) show forever if < touching (ireland v) ?> then move (0) steps else move (2) steps end if < touching (st patrick v) ? > then // add this new code change [score v] by (1) // get a point each time you hit a snake delete this clone end end


8

Add a sound effect

Finally let's add a sound effect and make St Patrick move his staff when you press the Space bar on your keyboard.

Add the following code to the St Patrick sprite:

when [space v] key pressed start sound [Whiz v] // you'll need to add this sound effect from the sound library switch costume to (hit v) wait (0.3) seconds switch costume to (normal v)

That's it you've finished all the steps! Have fun playing the game :)


9

Any ideas of your own?

Have you any ideas on how you could make the game better? Try and come up with an idea and add the code to put your idea into the game!

End of lesson
Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu