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 (variables) in the class spinner_body class: peg_count, initialized as 9 in the function _ready, moves_number, initialized as 0 in the function _ready, and best_score, initialized as 100 in the declaration (not in the function _ready).

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

Make the displayed text show "Moves: ## Best: ##" with the current number of moves and the value of the best score. You will need to use the reference to the text object to do this.

b. Collisions.
Add a reference to the spinner object in the peg_body script:

Connect the body_entered signal for the spinner with the spinner_body script and the corresponding function. In this function, check if the name of the body contains "peg" and if yes, play the bump sound.

To count the pegs, in the same function, after playing the sound, check if body.standing is still true. If it is, set its value to false, then decrease the value of peg_count.

Move Count and Display

Add a reference to the text label in the spinner script:

@onready var show_count: RichTextLabel = $"../showCount"

Then in the function roll_spin, after increasing the number of moves, update the text shown by this label like:

show_count.text = "Moves: %d Pegs left: %d" %[moves_number, peg_count]

Add it to the function _on_body_entered as well after you decrease the peg count.

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.

Add an extra trigger for the new game on pressing the key N in case the button doesn't show up properly on the screen in the build (it happens sometime).

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

Turn in: all the source files .gd, all the scenes .tscn, and a snap shot of the playing game.