Last edited 13dec09 by Cori Johnson, Math 198

# 3D Labyrinth

This game is similar to the wooden board game Labyrinth. As the board tilts, the ball rolls. The goal is to make it through the maze without falling in the holes. My version of the game is different from this. In my game, there are holes that should be avoided and obstacles in the way of the end. I chose to make this game because I use to play the board game all the time and I thought it would be fun to turn it into a computer game.

This program is written in Vpython.

## How To Play:

Use the arrow keys to tilt the board to get the ball in the blue hole. The player has two tries to beat the two levels. The player loses a try if the ball falls into a black hole. The player wins when both levels are beat.

## How The Game Works:

The board tilts on two of its axes. To do this, everytime an arrow key is pushed, the key is read and the board rotates the correct direction pi/16 radians around its center. The ball's position is updated by a small distance (velocity*dt) everytime the program runs through the while loop controlling the game. This means that the ball looks as if it has a velocity. Velocity is a vector in the direction of the board's axis. To update the position, the following code is used

ball.pos=ball.pos+direction*ball.velocityx*dt
ball.pos=ball.pos+direction*ball.velocityy*dt

The variable direction is determined by which key was pressed and how far the board is tilted in that specific direction. The sign of direction allows the ball to move either backward or forward in the x-direction, or left or right in the y-direction. The magnitude of direction depends on how far the board has already rotated and gives the ball more speed as the board is tilted more, and less as the board is tilted less. To check if the ball has gone in the winning hole or the losing hole, the ball's position is compared with the position of the hole, and the appropriate actions are taken.

I also took advantage of frames in Vpython while making this program. I made a frame called world_fr. By having everything on board be a part of this frame, it allows everything to be moved and rotated together. This is helpful because when the board is rotated, you do not have to move each piece seperately, but you can rotate just the frame, and everything will stay with it.

## Things to Improve:

make the board tilt with the mouse instead of the arrow keys.
make it so when the ball hits the block obstacle, it has a smoother bounce off and fall back down.
add a complete maze for the player to navigate through, like the board game.