Patch #1: Amazing Maze

In this patch, we build create a virtual invisible maze of 10*10 fields. A player can move through the maze using the arrow keys. We use the table object to save the positions of the walls and treasures and the playsf~ object to play back the sounds.

We can imagine the invisible soundscape like this:

We give every virtual field a number, so we easily can easily specify moving in it. A bit like in a chessboard, however, no letters, only numbers:

It is clear, if we would like to move in such a field, a step to the right would equal “+1″, a move to the top would equal “+10″. Similarly, moving down would equal “-10″ and moving left “-1″. We can move in our imagined but agreed upon space like this:

pd-15

 

Due to the constraints of our field, we would have to make sure, the player stays within the the boundaries of 0 to 99.

pd-16

 

This has some problems. If I am at position 97 and I move up, I jump to 99. Also, on a spot like 19, the player can not move to 20, as he/she is standing on an edge. Let’s try simulating this with Pd. We can use % (modulo) for this. Whenever we are a field with a “field number%10=9″ we do not allow to move to the right. Similarly, every field with a “field number%10=0″ does not allow for left movement. We also have to make sure, we allow upwards movement only on fields with a number smaller than 90 and allow downwards movement only for fields with a number bigger than 9. We use spigot to allow or not allow for the movements…

pd-2-17
We now can move through our 10*10 field. Let’s place some walls which they user can not cross or move upon.

Let’s put the walls like this (grey) and define 0 as start and 99 target position.

We can for example save the walls in a table object. We can add a table with a size of 99. Then we define for all spots on the maze if there is nothing special (in this case we put a 0 at this index) or if there is a wall (then we put in a -1 at this index) or if it is the target point (we put in a 1 at this index).

pd-2-18a

Let’s have a look inside:

pd-2-18

 

Now, with every move, we have to check whether there is a wall in the way. If there isn’t, we make the move, if there is one, we don’t and print “Outch!”

pd-2-19

It is now time to have some auditive feedback played with every successful step and some hit-the-wall-sound with every the player hits the wall. We use the [readsf~] object for this:

 

 

pd-2-20

And the complete patch:

 

pd-2-21