C# Class ThreadedPlatformer.Level

A uniform grid of tiles with collections of gems and enemies. The level owns the player and controls the game's win and lose conditions as well as scoring.
Inheritance: IDisposable
显示文件 Open project: sq/Fracture Class Usage Examples

Public Methods

Method Description
Dispose ( ) : void

Unloads the level content.

Draw ( GameTime gameTime, Frame frame, DefaultMaterialSet materials ) : void

Draw everything in the level from background to foreground.

GetBounds ( int x, int y ) : Rectangle

Gets the bounding rectangle of a tile in world space.

GetCollision ( int x, int y ) : TileCollision

Gets the collision mode of the tile at a particular location. This method handles tiles outside of the levels boundries by making it impossible to escape past the left or right edges, but allowing things to jump beyond the top of the level and fall off the bottom.

Level ( IServiceProvider serviceProvider, string path ) : System

Constructs a new level.

StartNewLife ( ) : void

Restores the player to the starting point to try the level again.

Update ( GameTime gameTime ) : void

Updates all objects in the world, performs collision between them, and handles the time limit with scoring.

Private Methods

Method Description
DrawTiles ( BitmapBatch batch ) : void

Draws each tile in the level.

LoadEnemyTile ( int x, int y, string spriteSet ) : Tile

Instantiates an enemy and puts him in the level.

LoadExitTile ( int x, int y ) : Tile

Remembers the location of the level's exit.

LoadGemTile ( int x, int y ) : Tile

Instantiates a gem and puts it in the level.

LoadStartTile ( int x, int y ) : Tile

Instantiates a player, puts him in the level, and remembers where to put him when he is resurrected.

LoadTile ( char tileType, int x, int y ) : Tile

Loads an individual tile's appearance and behavior.

LoadTile ( string name, TileCollision collision ) : Tile

Creates a new tile. The other tile loading methods typically chain to this method after performing their special logic.

LoadTiles ( string path ) : void

Iterates over every tile in the structure file and loads its appearance and behavior. This method also validates that the file is well-formed with a player start point, exit, etc.

LoadVarietyTile ( string baseName, int variationCount, TileCollision collision ) : Tile

Loads a tile with a random appearance.

OnExitReached ( ) : void

Called when the player reaches the level's exit.

OnGemCollected ( Gem gem, Player collectedBy ) : void

Called when a gem is collected.

OnPlayerKilled ( Enemy killedBy ) : void

Called when the player is killed.

UpdateEnemies ( GameTime gameTime ) : void

Animates each enemy and allow them to kill the player.

UpdateGems ( GameTime gameTime ) : void

Animates each gem and checks to allows the player to collect them.

Method Details

Dispose() public method

Unloads the level content.
public Dispose ( ) : void
return void

Draw() public method

Draw everything in the level from background to foreground.
public Draw ( GameTime gameTime, Frame frame, DefaultMaterialSet materials ) : void
gameTime Microsoft.Xna.Framework.GameTime
frame Frame
materials DefaultMaterialSet
return void

GetBounds() public method

Gets the bounding rectangle of a tile in world space.
public GetBounds ( int x, int y ) : Rectangle
x int
y int
return Microsoft.Xna.Framework.Rectangle

GetCollision() public method

Gets the collision mode of the tile at a particular location. This method handles tiles outside of the levels boundries by making it impossible to escape past the left or right edges, but allowing things to jump beyond the top of the level and fall off the bottom.
public GetCollision ( int x, int y ) : TileCollision
x int
y int
return TileCollision

Level() public method

Constructs a new level.
public Level ( IServiceProvider serviceProvider, string path ) : System
serviceProvider IServiceProvider /// The service provider that will be used to construct a ContentManager. ///
path string /// The absolute path to the level file to be loaded. ///
return System

StartNewLife() public method

Restores the player to the starting point to try the level again.
public StartNewLife ( ) : void
return void

Update() public method

Updates all objects in the world, performs collision between them, and handles the time limit with scoring.
public Update ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime
return void