remove Terrain.Empty and clean up TextureSource() switch statement

GitOrigin-RevId: 7de691a440982a027898b123b864ff202ae68ea5
This commit is contained in:
Colin McMillen 2020-02-02 09:33:33 -05:00
parent f7f7d5076e
commit 3286db1c86

View File

@ -1,11 +1,11 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
namespace SemiColinGames {
enum Terrain {
Empty,
Grass,
GrassL,
GrassR,
@ -38,32 +38,24 @@ namespace SemiColinGames {
private Rectangle TextureSource() {
int size = World.TileSize;
switch (Terrain) {
case Terrain.Grass: {
case Terrain.Grass:
return new Rectangle(3 * size, 0 * size, size, size);
}
case Terrain.GrassL: {
case Terrain.GrassL:
return new Rectangle(2 * size, 0 * size, size, size);
}
case Terrain.GrassR: {
case Terrain.GrassR:
return new Rectangle(4 * size, 0 * size, size, size);
}
case Terrain.Rock: {
case Terrain.Rock:
return new Rectangle(3 * size, 1 * size, size, size);
}
case Terrain.RockL: {
case Terrain.RockL:
return new Rectangle(1 * size, 2 * size, size, size);
}
case Terrain.RockR: {
case Terrain.RockR:
return new Rectangle(5 * size, 2 * size, size, size);
}
case Terrain.Water: {
case Terrain.Water:
return new Rectangle(9 * size, 2 * size, size, size);
}
case Terrain.Block: {
case Terrain.Block:
return new Rectangle(6 * size, 3 * size, size, size);
}
case Terrain.Empty:
default:
Debug.WriteLine("Tile.TextureSource(): rectangle not found");
return new Rectangle();
}
}
@ -113,7 +105,7 @@ namespace SemiColinGames {
Debug.WriteLine("world size: {0}x{1}", tileWidth, tileHeight);
for (int i = 0; i < tileWidth; i++) {
for (int j = 0; j < tileHeight; j++) {
Terrain terrain = Terrain.Empty;
Terrain? terrain = null;
if (i < worldDesc[j].Length) {
switch (worldDesc[j][i]) {
case '=':
@ -140,14 +132,11 @@ namespace SemiColinGames {
case 'X':
terrain = Terrain.Block;
break;
default:
terrain = Terrain.Empty;
break;
}
}
if (terrain != Terrain.Empty) {
if (terrain != null) {
var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize);
tilesList.Add(new Tile(texture, terrain, position));
tilesList.Add(new Tile(texture, terrain.Value, position));
}
}
}