make tile-texture lookup dictioanry-based instead of switch-based
GitOrigin-RevId: 2f0c215bf9e79e92f2c7a5011d8df3d9d80a0dff
This commit is contained in:
parent
c1232d462d
commit
b731e1a785
@ -20,6 +20,18 @@ namespace SemiColinGames {
|
|||||||
readonly Texture2D texture;
|
readonly Texture2D texture;
|
||||||
readonly Rectangle textureSource;
|
readonly Rectangle textureSource;
|
||||||
|
|
||||||
|
static readonly Dictionary<Terrain, Point> terrainToTilePosition =
|
||||||
|
new Dictionary<Terrain, Point>() {
|
||||||
|
{ Terrain.Grass, new Point(3, 0) },
|
||||||
|
{ Terrain.GrassL, new Point(2, 0) },
|
||||||
|
{ Terrain.GrassR, new Point(4, 0) },
|
||||||
|
{ Terrain.Rock, new Point(3, 1) },
|
||||||
|
{ Terrain.RockL, new Point(1, 2) },
|
||||||
|
{ Terrain.RockR, new Point(5, 2) },
|
||||||
|
{ Terrain.Water, new Point(9, 2) },
|
||||||
|
{ Terrain.Block, new Point(6, 3) },
|
||||||
|
};
|
||||||
|
|
||||||
public Tile(Texture2D texture, Terrain terrain, Rectangle position) {
|
public Tile(Texture2D texture, Terrain terrain, Rectangle position) {
|
||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
Terrain = terrain;
|
Terrain = terrain;
|
||||||
@ -37,27 +49,8 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
private Rectangle TextureSource() {
|
private Rectangle TextureSource() {
|
||||||
int size = World.TileSize;
|
int size = World.TileSize;
|
||||||
switch (Terrain) {
|
Point pos = terrainToTilePosition[Terrain];
|
||||||
case Terrain.Grass:
|
return new Rectangle(pos.X * size, pos.Y * size, size, size);
|
||||||
return new Rectangle(3 * size, 0 * size, size, size);
|
|
||||||
case Terrain.GrassL:
|
|
||||||
return new Rectangle(2 * size, 0 * size, size, size);
|
|
||||||
case Terrain.GrassR:
|
|
||||||
return new Rectangle(4 * size, 0 * size, size, size);
|
|
||||||
case Terrain.Rock:
|
|
||||||
return new Rectangle(3 * size, 1 * size, size, size);
|
|
||||||
case Terrain.RockL:
|
|
||||||
return new Rectangle(1 * size, 2 * size, size, size);
|
|
||||||
case Terrain.RockR:
|
|
||||||
return new Rectangle(5 * size, 2 * size, size, size);
|
|
||||||
case Terrain.Water:
|
|
||||||
return new Rectangle(9 * size, 2 * size, size, size);
|
|
||||||
case Terrain.Block:
|
|
||||||
return new Rectangle(6 * size, 3 * size, size, size);
|
|
||||||
default:
|
|
||||||
Debug.WriteLine("Tile.TextureSource(): rectangle not found");
|
|
||||||
return new Rectangle();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user