Scratch Saturday: Platform Games 6
Enter Kong! This week, we’re introducing a new sprite to the game – the one who gives his name to the famous series – Donkey Kong! You can download the sprite here. I designed my Donkey Kong Sprite based on the original sprite from the game and attempted to copy how he looked. One thing I noticed in the game from the animation was one of Donkey Kong’s feet was slightly raised higher than the other. When I was designing his second costume, I copied the first one and then mirrored it. When you flip between the two costumes it makes Donkey Kong look like he’s stomping.
I’m going to make a piece of code to do this. Whenever Donkey Kong is about to throw a barrel, he’s going to stomp for a couple of seconds in a temper. If you remember our code for our love heart last week, this is very similar. Donkey Kong is going to stomp 10 times in 2 seconds. The code is very easy. It’s a simple repetition of moving to his next costume. We’ll leave this code to the side for the time being.
OK, that’s Donkey Kong introduced to the game. Before we get him to start throwing barrels, there’s a couple of things I’m going to do. Firstly, I’m going to create another sprite, which is a barrel of burning oil that will stand at the bottom platform. Not only will this be to be in line with what the game looks like, it will also serve a couple of functions, which we’ll see later. For now, it’s just going to burn! I’m going to show you how I made it using the image editor.
Now we need to make a copy of the bin and gradually add fire to the sprite. I’m just going to the paintbrush tool to do it. I’m going to make about 5 images building the fire up. I’m then going to copy the images to make the fire go down. Next, I’m going to create a function that will make the fire burn all through the game. The function is exactly the same as the one above except instead of the block <repeat 10>, I’m using <forever>, because the fire is going to burn no matter what, (unless, of course, I decide to stop it at any time.)
Until now, this game has no end as Mario is immortal. We’re going to need to find some ways to make him die. Since we haven’t got any barrels yet, the only other way he can die is if Donkey Kong touches him. I’m also going to set you a challenge. The code for Mario dying when he touches Donkey Kong is easy to set up and we’ll also be able to use a new block.
In this example, the whole game is going to end if Mario touches Donkey Kong. We’ll be changing this later as we’ll be adding in scores and lives but for the moment the game is simply going to end (see left). If you run the program like this, if Mario touches Kong, the game just stops and it may confuse people. We could add a sound like a screech, (we’ll be adding sound later), but what about people who don’t have sound or want to play the game without sound? We’re going to have to get Mario to look like he’s dying. I’m going to get him to bounce backwards and lie flat on the ground. It’s useful to note that Mario will only approach Donkey Kong from the left so keep this in mind.
To get Mario to bounce backwards, I’m going to have to get him to move up and left then down and left. Once he’s hit the ground, I’m going to rotate him into a “dead” position. Let’s see the code in action.
First of all I want to make Mario rotate anti-clockwise by 90 degrees gradually. I’m going to do this by rotating 4.5 degrees, 20 times (4.5 x 20 = 90). I’m then going to make Mario move left by 2 pixels then up by 4 then left again by 3. This will make Mario move a total of 100 pixels left and 80 pixels upwards. Once that ordeal is over, Mario should find himself lying down mid air. We now exit the loop and stop the program. However, before the program ends, we have to wait a few seconds to give gravity a chance to do its thing and let Mario fall to the ground. I’ve given 2 seconds. The final block is to stop everything.
Later, we’ll be getting rid of this final block as we’ll be adding extra lives to Mario. Until then, my challenge to you is to make a more elaborate death for Mario. Why not use some of the image effects from the previous lesson – pixelating will be a good one! In the next lesson, we’re going to introduce the other thing that can kill Mario – the barrels that Donkey Kong rolls down the screen.