We're here for Primary Education in Ireland

Scratch Saturday: Platform Games 5


Posted on February 9th, by admin in Scratch. 4 comments

Five weeks into our game, we have set up a number of items in our game. We have created our main character, Mario who can now move around the screen properly. We also have a number of platforms and ladders for him to do this. Last time we created the princess and a love heart for when Mario reaches her. I thought we’d take a closer look at the heart and have a look at some of the lesser used functions in Scratch to make the occasion more romantic.

When the heart comes on screen, it is because of a Broadcast command, which simply shows the heart. I’d like to make the heart pound a little bit. To break this down into programming-speak, I’d like to make the heart grow bigger then smaller a few times. I’m going to need to use a loop to make something repeat.

First of all, I want to make the heart grow so I’m going to make a bit of an animation. I’m going to make the heart grow by 40 pixels but in ten steps of 4. This will give it the appearance of growing. It will also need to decrease back to its normal size so I’ll decrease it by 40 pixels in ten steps of 4, (see right).

Now I need to make the heart beat a few times – let’s say 5 – for the moment. I need to wrap the increasing and decreasing blocks up in another repeat block – repeat 5. This will make the heart beat 5 times.

Ok, so that was easy enough. Now I’m going to add a splash of extra colour to the heart. I’m going to use the block: <Change Colour Effect by x>. This block changes the colour of your sprite to a different colour. Scratch allows 200 different colour effects so you can have a lot of fun here. In my example, I’m having the colour effect change by 10, for every increase and for every decrease. The effect of this is the heart will go through a spectrum of colour changes and end up back to red.

Right, so we’ve done a few things to the heart at this stage and I’m going to play around a little bit more with the heart, just for the fun of it and so you can see some of the results you can have with it. I’m going to play around with the mosaic effect, which, as its name suggests turns your sprite into a mosaic version of itself. I made the mosaic change by 3 then -3 to show lots of love hearts! You can play around with some of the other effects like fish eye lens, whirl and pixelate. The ghost effect is worth mentioning because it makes your sprite fade. If you find your sprite has gone crazy, the block, <clear graphic effects>, will get your sprite back to normal!

In Donkey Kong, unfortunately, life isn’t love hearts for long as our gorilla grabs the princess at the end leaving poor old Mario heartbroken. The love heart sprite has a second costume, which is a broken heart. After the theatrics of the love hearts throbbing and going through its graphic effects, it’s going to fade to nothing and hide.

We need to add more code now and I’m going to change the costume to a broken heart then  use the ghost effect mentioned before to slowly make it fade. It’s easy to change the costume. Simply create a block underneath the code to change to the next costume. Once that’s out of the way, we’re going to slowly make the heart fade over 2 seconds. A fully faded sprite has a change in effect of 100 so we need to fade our heart at a rate of 50 per second. I’m going one step further by fading the heart by 5 every tenth of a second. This means I have 20 repeats of a ghost effect of 5, (20 x 5 = 100). I also want the computer to wait a tenth of a second each time (1 tenth of a second x 20 = 2 seconds). Next, I want to change it back to the previous costume, (no-one will see it), then hide it completely, (in case!) You might think that that’s the job done but have a think about what will happen the next time we run the code.

As the sprite has been set to fade completely, when we run it again in future levels, if we don’t change the code, there will be nothing to see so we’ll need to add one extra block at the beginning – <clear graphic effects>. Pop this after the <show> block and you’re done!

Next time, Donkey Kong will enter the arena. He’s going to make life hard for Mario! Have a go of messing around more with the graphic effects but also try moving the heart around the place or even get Mario and the princess to have a smooch!





  • http://www.neteffects.com.au/it-support IT Support

    Graphic actions
    does make Mario’s life more challenging in the end. Got to try these new scratch tricks.