parse World from string, add GrassL, GrassR, and Water terrains
GitOrigin-RevId: 40497e34785fe279980831f3e2b8e2155a7bfc8a
This commit is contained in:
parent
f364a9c6ff
commit
873d35dcfb
@ -7,7 +7,10 @@ namespace Jumpy {
|
||||
enum Terrain {
|
||||
Empty,
|
||||
Grass,
|
||||
Rock
|
||||
GrassL,
|
||||
GrassR,
|
||||
Rock,
|
||||
Water
|
||||
}
|
||||
|
||||
class Tile {
|
||||
@ -33,11 +36,26 @@ namespace Jumpy {
|
||||
spriteBatch.Draw(texture, position, source, Color.White);
|
||||
break;
|
||||
}
|
||||
case Terrain.GrassL: {
|
||||
Rectangle source = new Rectangle(2 * size, 0 * size, size, size);
|
||||
spriteBatch.Draw(texture, position, source, Color.White);
|
||||
break;
|
||||
}
|
||||
case Terrain.GrassR: {
|
||||
Rectangle source = new Rectangle(4 * size, 0 * size, size, size);
|
||||
spriteBatch.Draw(texture, position, source, Color.White);
|
||||
break;
|
||||
}
|
||||
case Terrain.Rock: {
|
||||
Rectangle source = new Rectangle(3 * size, 1 * size, size, size);
|
||||
spriteBatch.Draw(texture, position, source, Color.White);
|
||||
break;
|
||||
}
|
||||
case Terrain.Water: {
|
||||
Rectangle source = new Rectangle(9 * size, 2 * size, size, size);
|
||||
spriteBatch.Draw(texture, position, source, Color.White);
|
||||
break;
|
||||
}
|
||||
case Terrain.Empty:
|
||||
default:
|
||||
break;
|
||||
@ -55,31 +73,48 @@ namespace Jumpy {
|
||||
public int Width { get; }
|
||||
public int Height { get; }
|
||||
|
||||
string[] worldDesc = new string[] {
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" <=> ",
|
||||
" ",
|
||||
" ",
|
||||
" <=> <=> ",
|
||||
" = ",
|
||||
" ",
|
||||
" ",
|
||||
"=============> <===",
|
||||
"..............~~~~~." };
|
||||
|
||||
public World(Texture2D texture) {
|
||||
width = Camera.Width / TileSize;
|
||||
height = Camera.Height / TileSize + 1;
|
||||
// TODO: better error handling for if the string[] isn't rectangular.
|
||||
width = worldDesc[0].Length;
|
||||
height = worldDesc.Length;
|
||||
tiles = new Tile[width, height];
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
Terrain terrain;
|
||||
if (j < height - 2) {
|
||||
terrain = Terrain.Empty;
|
||||
} else if (j == height - 2) {
|
||||
terrain = Terrain.Grass;
|
||||
} else {
|
||||
terrain = Terrain.Rock;
|
||||
}
|
||||
if (j == 6 && 11 < i && i < 16) {
|
||||
terrain = Terrain.Grass;
|
||||
}
|
||||
if (j == 3 && 15 < i && i < 19) {
|
||||
terrain = Terrain.Grass;
|
||||
}
|
||||
if (j == 7 && i == 5) {
|
||||
terrain = Terrain.Grass;
|
||||
}
|
||||
if (7 <= j && j <= 10 && i == 12) {
|
||||
terrain = Terrain.Rock;
|
||||
switch (worldDesc[j][i]) {
|
||||
case '=':
|
||||
terrain = Terrain.Grass;
|
||||
break;
|
||||
case '<':
|
||||
terrain = Terrain.GrassL;
|
||||
break;
|
||||
case '>':
|
||||
terrain = Terrain.GrassR;
|
||||
break;
|
||||
case '.':
|
||||
terrain = Terrain.Rock;
|
||||
break;
|
||||
case '~':
|
||||
terrain = Terrain.Water;
|
||||
break;
|
||||
case ' ':
|
||||
default:
|
||||
terrain = Terrain.Empty;
|
||||
break;
|
||||
}
|
||||
var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize);
|
||||
tiles[i, j] = new Tile(texture, terrain, position);
|
||||
|
Loading…
Reference in New Issue
Block a user