7 Something To Do
The player needs something to do in the game. It's fun to jump around for a few minutes but that quickly gets boring if there is no overall goal for the player to complete. In this part of the tutorial, you will see how to place cherries around the room for the player to pick up. When all of the cherries have been picked up, the player can exit the level and move on to the next one.
- stop.gif - the exit object
- cherry.gif - the cherries that the player must collect
- pickup.wav - a sound to play when the item is picked up
- win.wav - a sound to play when the level is complete
Save these resources to your area before proceeding.
Creating Sprites & Sounds
Create sprites for the stop sign and the cherry.
By not having precise collision checking for these sprites we will save a little work for the game engine. We don't need the player to be that exact here.
Also create the sound to play when an object is picked up and when the level is complete.
Create the following objects using the stop and cherry sprites.
Add exactly one stop object to the room.
Add a load of cherries scattered all over the room. Make sure that they are all within reach of the player. It's good to make some quite challenging to reach though.
We'll deal with the cherry & player collision in the obj_cherry object window. Open it up and add a Collision Event with the character object.
There are 3 simple steps required here, increase the score, play the pickup sound and destroy the cherry instance that has been picked up. They are shown below.
Finally we deal with the collision between the player and the stop sign. Here we have to check that all the cherries have been nibbled, if they have we play a victory noise and restart the current room.
Add a Collision Event with the character to the obj_stop object window. We can do this in the character but putting it here will reduce clutter in the character window.
Drag in a Test Instance Count action and fill in the pop-up as shown,
Complete the remainder of the actions as shown,
When there are more levels, you will need to add more code to check whether or not to move to another level. The technique for this is shown in the Blue Balls Of Evil tutorial.
Save the game and test the work that you have done so far.
You could improve the game at this point by adding a different sound to play if the cherries have not all been collected.