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