Game Development Reference
In-Depth Information
public double Multiplier
{
get { return multiplier; }
set { multiplier = value ;}
}
Unfortunately, TimeSpan objects cannot be multiplied directly with double values.
Therefore, we first calculate the total number of seconds passed times the multiplier
value:
multiplier;
double totalSeconds = gameTime.ElapsedGameTime.TotalSeconds
Then, we convert this value into a TimeSpan object, and we subtract it from the total
time left:
= TimeSpan.FromSeconds(totalSeconds);
timeLeft
Now that we can change the speed at which the time passes, we can do this
depending on the kind of tile that the player is walking on. We already maintain a
variable walkingOnIce , which indicates whether we are walking on an ice tile. In order
to handle hot tiles as well, we define another variable walkingOnHot , in which we will
maintain if we are walking on a hot tile or not. In order to determine the value of this
variable, we follow the exact same approach as we did for the walkingOnIce variable.
In the HandleCollisions method, we initially set this variable to false :
walkingOnHot = false ;
Then, we add one line of code to update the value of the variable depending on the
current tile we are standing on:
walkingOnHot = walkingOnHot || currentTile.Hot;
For the complete code, see the Player class belonging to the TickTick5 example.
Using the walkingOnIce and walkingOnHot variables, we can now update the timer
multiplier. We do this in the Update method of the player:
TimerGameObject timer = GameWorld.Find("timer") as TimerGameObject;
if (walkingOnHot)
timer.Multiplier = 2;
else if (walkingOnIce)
timer.Multiplier = 0.5;
else
timer.Multiplier = 1;
Search WWH ::




Custom Search