Game Development Reference
In-Depth Information
We don't need to make many changes to the funcion. The movement part works perfectly
as it is. It's exactly the same way the cat can move. We only need to remove the last part of
the script that deals with touching
exit
. The knight is not allowed to escape the level.
1. Grab the
if
statement with the cursor and drag down to separate it from the script.
2. Drag the script part to the left and drop it in the toolbox to remove it.
3. Alternaively, we could also right-click on the part and choose
delete
. This also
removes the script.
Now we have to call the funcion to actually make the knight move. We will also add an
interesing feature based on which level we are playing. For each level, the number of knights
will be increased by one. So level 1 will have one knight, level 2 will have two, and so on.
1. We create a new script staring with a
when I receive <startGame>
block.
2. Then, we add
repeat ()
.
3. We fill the slot with the
level
variable to repeat as many imes as the level we
want to play.
4.
Then, we place the sprite with a
go to x:() y:()
block.
We want to pick a random ile on the map, so we have to make a calculaion based on a
random number. Luckily, we designed the iles in such a way that the middle segment is
always free, so we won't have to check for collisions with walls.
1. For the x posiion, the formula will be:
ile width * random ile in row - (half the stage
width - half the ile width)
. This translates to
(60) * pick random (0) to (7) - (210)
.
2. For the y posiion, the formula becomes:
ile height * random ile in column - (half
the stage height - half the ile height)
. This translates to
(60) * pick random (0) to
(5) - (150)
.
3. When that's setled, we can use the
create clone of <myself>
block.
4. Next, we wipe the
xySave
list clean with a
delete <all> of <xySave>
block.
5. We use the
add x posiion to <xySave>
block.
6. We also use the
add y posiion to <xySave>
block.