Game Development Reference
In-Depth Information
if (CurrentLevel.PlayerWon)
{
CurrentLevel.Solved = true ;
GameEnvironment.GameStateManager.SwitchTo("levelFinishedState");
}
using Microsoft.Xna.Framework;
1
using Microsoft.Xna.Framework.Graphics;
2
using Microsoft.Xna.Framework.Input;
3
4
5
class LevelFinishedState : GameObjectList
{
6
protected IGameLoopObject playingState;
7
8
9
public LevelFinishedState()
{
10
playingState =
11
GameEnvironment.GameStateManager.GetGameState("playingState");
12
13
14
SpriteGameObject overlay =
new SpriteGameObject("Sprites/spr_level_finished", 1, "you_win");
15
overlay.Position = new Vector2(GameEnvironment.Screen.X,
16
GameEnvironment.Screen.Y) / 2
17
overlay.Center;
18
this .Add(overlay);
19
}
20
21
22
public override void HandleInput(InputHelper inputHelper)
{
23
if (!inputHelper.KeyPressed(Keys.Space) &&
24
!inputHelper.MouseLeftButtonPressed())
25
return ;
26
GameEnvironment.GameStateManager.SwitchTo("playingState");
27
(playingState as PlayingState).NextLevel();
28
}
29
30
31
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
32
playingState.Draw(gameTime, spriteBatch);
33
base .Draw(gameTime, spriteBatch);
34
}
35
}
36
Listing 24.2 The state that the game is in when the player has finished a level. This state shows
the playing state with an overlay on top of it
Search WWH ::




Custom Search