Easter Egg Hunt – Multiple Cameras Added and Bonus Eggs Implemented

Four picture-in-picture cameras have been added, which display each of the rabbits and the eggs that each has collected.  Each camera is a child of the Player object, so that it stays locked at the same position in front of the rabbit.  This gives a good view of the eggs collected, but can be jarring when the player suddenly rotates a large amount, such as going directly left to directly right.  I figured out that I can specify the size of the camera on screen in pixels by setting the pixelRect property of the camera.  In the Unity inspector, I have only been able to set relative sizes and positions.

The method for placing eggs was updated, to ensure that eggs are evenly spread out over the gameplay area.  Previously, the lower left portion of the gameplay area had few eggs because of an error using 360 degrees instead of 2 Pi radians with the Sin and Cos functions.  To evenly distribute the eggs, I calculated the start of the radian range for an egg by dividing 2 Pi by the number of eggs, and then multiplied by the current egg number.  The end of the radian range is the same, except using the egg number plus 1.  Then I generated a random float from 10f to 19f for the radius length from the center of the gameplay area to the egg, which ensures that the eggs don’t clump up in the center and don’t lie on the oustide edge of the gameplay area.  The radius of the gameply area is 20f.  The x position of each egg is calculated by radius * Cos(2 * Mathf.Pi * radians) and the z position is radius * Sin(2 * Pi * radians).  This method divides the circle into even slices based on the total number of eggs.

A new Bonus class (different that the Quest class that I removed) was added to track the bonus color and multiplier.  I made a list of int, which currently just holds 2 and 5, and the multiplier is selected from that list.  I added additional code to ensure that if the 2 multiplier is selected, then exactly 3 bonus eggs will be generated.  If the multiplier is 5, then only one bonus egg is generated.  When the regular eggs are created, if the random color equals the bonus egg color, then it loops and keeps generating a random color for that egg, until it doesn’t equal the bonus color.  It seems like with the bonuses added, there are far fewer tie outcomes in the game.  Since there are just a few bonus eggs, I placed them at any valid location on the gameplay area.  If more bonus eggs were instantiated, then I would use a method to spread them out like I did with the other eggs.

Easter Egg Hunt – End game state conditions added, updated animations

In the latest update to Easter Egg Hunt, I added checks to see if all of the eggs are collected and if time has expired.  Then the player or players who have the most eggs are declared the winners.

Two animations were added for the rabbits for standing and walking, and animation transitions were applied based on the rabbit’s speed.  The camera zooms in on one of the winning players.

The game area was also changed to a circular shape, and the formula to distribute eggs on the game area was updated to use a random radius and angle.  Invisible walls were added to prevent the player from dropping off the gameplay area.

Fonts were updated for the text displaying the score, timer, and winner text.