Dana Vrajitoru
I355/C490/C590 3D Games Programming

I355/C490/C590 Homework 3

Due Date: Wednesday, September 25, 2024.

In this homework we'll continue Lab 3 and finish the game of Skittles.

Here is an example of the finished game (http://www.cs.iusb.edu/~dvrajito/teach/i355/skitGL/).

Ex. 1. Lab. After you complete the lab, you should have an area delimited by walls, a spinner, and 9 pegs placed in the arena. The spinner is rolled in a randomized way when the game starts.

Ex. 2. Add the following elements to the game.

a. Peg Count.
Add three attributes in the class SpinnerManager, a non-static public int pegCount, initialized as 9 in the function Start, a non-static public int moveNumber, initialized as 0 in the function Start, and a public static int bestScore, initialized as 100 in the declaration (not in the function Start).

Remove the function call to RollSpin from the function Start and move it to the function Update, under a check for keyboard input from the user with the character being a space. Increment the moveNumber in RollSpin. This way, by hitting a space we roll the spinner again.

Make the displayed text show "Pegs: ## Moves: ## Best: ##" with the current number of moves and the value of the best score. For that, declare a variable

public GameObject moveText

Then go back to Unity, click on the spinner object, and set the Move Text property in the script to be the text mesh object you created. Then in the function RollSpin, you can set the text with:

moveText.GetComponent<TextMesh>().text = "Pegs: " + pegCount.ToString() + ...

b. Collisions.
Add the following function to the class SpinManager:

 
void OnCollisionEnter(Collision colInfo)
{
    if (colInfo.collider.tag == "peg" && colInfo.collider.GetComponent<PegManager>().standing)
    {
        pegCount--;
        colInfo.collider.GetComponent<PegManager>().standing = false;
    }
}

Now when you run the game, you should notice that when the spinner hits a peg the first time, it decreases its peg count.

Add a "Player" tag to the spinner. Add a similar collision function to the PegManager class that plays its sound when it collides with an object having the Player tag.

c. Winning the game.
Modify the collision function in the class SpinManager so that after a collision, if the peg number is down to 0, the game is won. In that case, compare the number of moves with the best score. If the number of moves is lower, replace the best score with the new one, and display a message saying that there is a new best score. If not, simply display a winning message.

Extra credit. Up to 3 points for creative additions to the game functionality.

Turn in: all the source files .cs and a zipped build folder for Windows. The build zip file should contain: