3 - Monsters
The game as it stands now starts
looking nice, but is still completely trivial, and hence boring to
play. So we need to add some action in the form of monsters
different monsters: one that moves left
and right, one that moves up and down,
and one that moves in four directions.
Each monster should have different images for each way it moves.
Adding the Monsters
a monster is actually very simple. It is an object that starts moving
and changes its direction whenever it hits a wall. When the person
hits a monster, it is killed, the level is restarted and the player
looses a life. Give the person three lives to start with.
create the monster that moves left and right.
It will start moving on create.
collision occurs it reverses its horizontal direction.
To Change the sprite we check if we
are moving left (hspeed < 0) or moving right (hspeed >0)
monster works exactly the same way but this time we start moving
either up or down, when we hit a wall,
we reverse the vertical direction. On the end step we check vspeed
and change the image
third monster is slightly more complicated. It starts moving
either in a horizontal or in a vertical direction on Create
hits a wall it looks whether it can make a left or a right turn. If
both fail it reverses its direction. This looks as follows:
To check if the spot in front of monster
is empty (If position is collision free)
This Part is Optional
If you want to make the direction random try using chance
option before each of the movements.
problems with monsters being slightly too small, uncheck
precise collision checking and modify
the mask to set the bounding box to the full image.
person collides with a monster, we have to make some awful sound,
sleep a while, decrease the number of
lives by one, and then restart
the room. (Note that this order is crucial. Once we restart
the room, the further actions are no longer executed.) The controller
object, in the "no more lives" event, shows the high-score
list, and restarts the game.