Game Development Reference
In-Depth Information
class TileField : GameObjectGrid
1
{
2
public TileField( int rows, int columns, int layer = 0, string id = "")
3
: base (rows, columns, layer, id)
4
{
5
}
6
7
8
public TileType GetTileType( int x, int y)
{
9
if (x < 0 || x >= Columns)
10
return TileType.Normal;
11
if (y<0||y>=Rows)
12
return TileType.Background;
13
Tile current = this .Objects[x, y] as Tile;
14
return current.TileType;
15
}
16
}
17
Listing 27.1
The TileField class
Player player = new Player(startPosition);
this .Add(player);
Finally, we still need to make an actual tile here that can be stored in the grid,
since each character should represent a tile. In this case, we can simply create a
background tile, which is placed where the player is standing:
return new Tile();
27.4 Jumping . . .
We have already seen how we can walk to the left or to the right. How can we deal
with jumping and falling? By pressing either the arrow up key or the space bar,
the character should jump. Jumping basically means that the character will have a
negative y -velocity. This can be easily done inside the HandleInput method of the
Player class:
if (inputHelper.KeyPressed(Keys.Space) || inputHelper.KeyPressed(Keys.Up))
Jump();
The Jump method is given as follows:
Search WWH ::




Custom Search