Dana Vrajitoru
B583/C490 Game Programming and Design

B583/C490/I400 Homework 9

Due Date: Wednesday, November 16, 2022.

In this homework we will continue Lab 8 to implement the game Key Master. Here is an an example (http://www.cs.iusb.edu/~danav/teach/b583/zodaGL/index.html) of the intended result.

This game will be composed of 5 levels. In each level, the player moves through a maze and must open a number of doors. In order to open a door, the player must acquire first a key of the same color.

Ex. 1. Create another scene called end, similar to start but displaying the end image instead. The caption on the button should say "New Game". The action can be the same as for the first scene.

Set the aspect of the whole game to 3:2 and the size of the application window to 750x500. Arrange the quads in the start and end scene so that they cover the entire viewport.

Ex. 2. a. Add a feature to the PlayerController.cs class such that when the player moves to the left and right, the creature is rotated that way, and when it moves backwards, it faces the screen. Hint: check the values of the player's speed in Update or FixedUpdate. Normally, the rotation is stored in the transformation in quaternions. To apply a rotation to the player using the 3 angles for x, y, and z, you can do

transform.eulerAngles = new Vector3(0f, 90f, 0f);

b. Add 5 keys and doors to the scene and set their material with a different color such that each door is matched by a key. Then in the Start function of the game master, deactivate all the doors and all the keys, and let the function placing doors and key activate the ones it needs.

Implement a function that takes one parameter for the number of doors and places that many doors with corresponding keys on the maze on cells that are spaces. Make sure that each key is accessible for the player starting from the center of the maze before the matching door.

This can be accomplished for example by starting from the center of the maze, and walking away on a random path using spaces for a given number of steps, and then placing a door there. Starting again from the center and following another random path can lead to another position where the matching key can be placed, and so on.

Add a collision function for a key with the player that shrinks it and attaches it to the player. You must apply a scale to the captured key, by a factor of 0.5 for example. You must assign the position of the key based on the current position of the player, with some small translation to make the key visible. Then you must make the key a child of the player so that it follows its movement. For example, if the objects are key and player, then you'd attach it by doing

key.transform.parent = player.transform;

One of the objects will most likely be the one whose class is responsible for this (player class or key control class), in which case that object becomes the current gameObject or can be omitted.

Store the original position and scale of the key so that you can drop it if you change your mind. Implement a function that drops the key when the spacebar is pressed while the player has a key and places it back to its original place in the maze.

Implement a collision function of the player with a door where it checks if the player has a key and if the key has the same color as the door. In that case, both the key and the door objects should be deactivated and an attribute in the game master class should be decreased.

c.Implement 5 levels in the game, from 1 to 5. In each level, generate a maze with a size equal to 5 +level*3. In each level, place a number of doors and keys equal to the level number. Have the function Start of the game master initialize the maze and doors based on the level number. In this same class, check in the function Update if the number of doors to be found has become 0, and in that case increment the level number. If the level is at most 5, then load the scene maze again (with the updated level). If not, load the end scene. The program should be starting from the start scene.

Add a button to the maze scene that starts a new game. This can be done by resetting the level to 1 and reloading the scene maze.

Turn in to Canvas: a zip file with a Windows build and the script files.