Game Development Reference
In-Depth Information
public bool Completed
{
get
{
SpriteGameObject exitObj = this .Find("exit") as SpriteGameObject;
Player player = this .Find("player") as Player;
if (!exitObj.CollidesWith(player))
return false ;
GameObjectList waterdrops = this .Find("waterdrops") as GameObjectList;
foreach (GameObject d in waterdrops.Objects)
if (d.Visible)
return false ;
return true ;
}
}
Inside the Update method of the Level class, we then check if the level was com-
pleted. If so, we call the LevelFinished method in the Player class, which plays the
'celebration' animation:
if ( this .Completed && timer.Running)
{
player.LevelFinished();
timer.Running = false ;
}
Inside the PlayingState class, we then deal with switching to other states depending
on the state of the level. These lines of code in the Update method are responsible
for that:
public virtual void Update(GameTime gameTime)
{
CurrentLevel.Update(gameTime);
if (CurrentLevel.GameOver)
GameEnvironment.GameStateManager.SwitchTo("gameOverState");
else if (CurrentLevel.Completed)
{
CurrentLevel.Solved = true ;
GameEnvironment.GameStateManager.SwitchTo("levelFinishedState");
}
}
The code for dealing with transitions between levels is fairly straightforward and
is almost a copy of the code used in the Penguin Pairs game. And that means that
we have now completely shown you how to build a platform game with commonly
occurring elements such as collecting items, avoiding enemies, game physics, going
from one level to another, and so on. So does it end here? Well, that depends on
you. In order to make Tick Tick a game that is commercially viable, a lot of work still
Search WWH ::




Custom Search