Now that the cat can explore the maze, it needs a challenge. It's a good idea to give it a specific goal to search for.
We will draw a sprite that will be the goal for the cat to reach. What this goal will look like is not really important. The important thing is that it is exactly 20 x 20 pixels in size, so it will fit a tile segment perfectly.
I choose to represent the goal as a "magical" warp panel consisting of bright, blue rings. You can create the same or design your own goal sprite.
Once done, name the sprite as exit
. This will give us the following screenshot:
This sprite will have the same two broadcast listeners as the cat to start working. When the maze is drawn, we will hide the sprite, and when the game starts, we will show it by performing the following steps:
Do these steps look familiar? They should. It's effectively the same script as the cat is using in the findStartPosition
function, barring the use of the list. Since the exit tile doesn't move, we don't need to save its position.
To let the player know when he or she has reached the exit and has won this (part of a) game, we add some feedback to the cat sprite. We will add a few additional actions to the takeStep
function as follows:
This is starting to feel more like a game already.
With this simple addition, we brought a feeling of gameplay to the program. Before this step, it was more like a movement simulator or a keyboard test, but now, there is actually something to achieve. All it required was copying a script, writing another script that we might just as well have copied and changed, and writing a simple collision check and effect.
Some steps in programming can be really difficult, but once the basics are set it's quite easy to add improvements.
18.118.137.67