Dana Vrajitoru
B583/C490 Game Programming and Design

Homework 10

Due date: Tuesday, November 29, 2011.

In this homework we're implementing a 3 dimenisional maze.

Ex. 1. a. Download one of the following archives depending on your system and decompress it. It should create a folder called "maze" pr "maze4":

maze.zip
maze4.zip

For Xcode 3, you can then move the file maze.txt from the top level directory to the place where the executable is (build / debug / etc.). For Xcode 4, you'll have to look for the absolute path of the file maze.txt in the code (just do a search in the whole project) and replace the absolute path with the absolute path to your directory where the file is. Compile the program and run it to make sure everything works. The up and down arrow keys let you move the player (represented by the orange octahedron) for or backwards depending on its orientation. The left and right arrow keys let you turn around.

a. Add two functions to the Player class for strafing left and right. They should be implemented in a way that is similar to moving forward (it should depend on the speed) and keep in mind that a rotation by 90 degrees in the xy plane swaps the values of the coordinates and takes the negative for one of them (not both). Add functionality to the movePlayer function in the GameController class and to the keyDown function in the class MyOpenGLView for the keys wasd, where w and s work the same way as the up and down arrow keys, but a and d are used for strafing.

b. Add a function onWall to the class Maze taking two real parameters x and y for the position of the player and returning a boolean that is true if the given position is inside a wall cell. You can use a simple conversion form real to integer to map the real coordinates to a cell of the maze.

c. Modify the function movePlayer such that after every move changing position (this does not apply to turning) you verify that the player is not on a wall. If they are, then turn back to the previous position. You can do this by either moving in the opposite direction, or by storing the previous position in a temporary Point3f object before the move and restoring it after the move if you need to. The second solution doesn't need to be personalized to every type of move.

d. Add a class called Target that represents an object to be the target of the game. The player will have to look for the target in the maze. Use any geometrical representation for the target, as long as it's easy to notice on the screen. Add a class attribute in the class GameController that stores a reference to a target object and make sure it is initialized properly. After the maze has been read from the file, update the position of the target with the values stored in the object amaze that have been initialized form the file. Add a test for the target and the player being in the same cell in the maze and modify the program to detect the winning condition and communicate it to the player some way (I leave that up to you).

e. Add a function that randomizes the target's position in a similar way to the function randomizing the player. Modify the function newGame in the GameController class to randomize the player and the target.

Note. Steps taken to put this application in place.