Game Development Reference
In-Depth Information
5.
Save the script.
6.
Assign the Sound FX Munching object to the Game Manager's Score Keeper
component's Munching parameter.
7.
Click Play from the StartMenu and test.
At a zombie bunny count of 15 (the value you left the Stop Pop X at), the sound should now turn off.
Adjusting Difficulty
The final bit of functionality for the game is to flesh out the difficulty setting. You have a value
between 1 and 10 that will be used to set the battery life value. A large battery life value equates to
more seconds for the player to complete his task.
At 70-75 seconds of battery life, the game is challenging for casual gamers. At 25 seconds, the
player will really have to be good to eradicate the pests. At 175 seconds, providing the zombie
bunny drops aren't too frequent, most of the pressure is gone. So if you consider the range to be 25
to 175, that gives you a range of 150, which puts the default difficulty at about 50%, or 75 seconds.
Up to this point, where the battery time was fixed, it made sense to track the batteryRemaining ,
or seconds remaining. Now, however, the battery time, batteryFull , will be calculated using fixed
amounts and the Difficulty value, so the battery remaining will require recalculation every time the
player changes the Difficulty setting. Now it makes more sense to track the percent, as it will remain
the same regardless of the total time and time remaining.
Let's begin by substituting percentRemaining for batteryRemaining in a few places.
1.
Open the GameMisc script.
In the LevelPrep function, change the levelManager.batteryRemaining line to
2.
levelManager.percentRemaining = batteryHealth.percentRemaining;
3.
Save the script.
In the BatteryHealth script, set the percentRemaining variable to internal :
4.
internal int percentRemaining = 100; // remaining battery life in percent
5.
Create the new function to calculate the battery charge:
public void UpdateBatteryLife (float newBatteryFull, int newPercentRemaining) {
percentRemaining = newPercentRemaining;
batteryFull = newBatteryFull;
batteryRemaining = (batteryFull * percentRemaining * .01f);
}
 
Search WWH ::




Custom Search