5 - Blocks and Holes
create something else that will enable us to make more complicated
puzzles. We will create blocks that can be pushed by the player into
we will use the parent option, this will make all collision on our
wall apply to the block.
Note: I used
8 because my speed is 4..... (8 * 4) = 32 which is the size of my
block. If your character speed is not 4 figure out the value by dividing
32 by your speed.
speed is 5 then 32/5 = 6.4 so replace 8 by 6.4
we make holes that the player cannot cross but that can be filled
with the blocks to create new passages.
for many possibilities. Blocks have to be pushed in a particular way
to create passages. And you can catch monsters using the blocks.
is a solid object. Because a collision event is defined between the
person and the wall and not between the person and the block, that
event is executed, stopping the person. This is not what we want.
To solve this we put a dummy action (just a comment) in the collision
event of the person with the block. Now this event is executed instead,
which does not stop the person. (To be precise, the new collision
event overrides the collision event of the parent. As indicated before,
you can use this to give child objects slightly different behavior
than their parents.
is a solid object. When it collides with the block it destroys itself
and the block. We also make the corner wall its parent to let it behave
like a wall.
blocks and holes you can create many intriguing rooms. There is though
a little problem. You can easily lock yourself up such that the room
can no longer be solved. So we need to give the player the possibility
to restart the level, at the cost of one life. To do this set the
key R to restart. In this keyboard event for the controller we simply
subtract one from the lives and restart the room.
bonuses: one to give you 100 points and the other to give you an extra
life. They are both extremely simple. When they person collides play
a sound, destroy bonus object , and either add some points to the
score or 1 to the number of lives.