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 {
|
enum Terrain {
|
||||||
Empty,
|
Empty,
|
||||||
Grass,
|
Grass,
|
||||||
Rock
|
GrassL,
|
||||||
|
GrassR,
|
||||||
|
Rock,
|
||||||
|
Water
|
||||||
}
|
}
|
||||||
|
|
||||||
class Tile {
|
class Tile {
|
||||||
@ -33,11 +36,26 @@ namespace Jumpy {
|
|||||||
spriteBatch.Draw(texture, position, source, Color.White);
|
spriteBatch.Draw(texture, position, source, Color.White);
|
||||||
break;
|
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: {
|
case Terrain.Rock: {
|
||||||
Rectangle source = new Rectangle(3 * size, 1 * size, size, size);
|
Rectangle source = new Rectangle(3 * size, 1 * size, size, size);
|
||||||
spriteBatch.Draw(texture, position, source, Color.White);
|
spriteBatch.Draw(texture, position, source, Color.White);
|
||||||
break;
|
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:
|
case Terrain.Empty:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -55,31 +73,48 @@ namespace Jumpy {
|
|||||||
public int Width { get; }
|
public int Width { get; }
|
||||||
public int Height { get; }
|
public int Height { get; }
|
||||||
|
|
||||||
|
string[] worldDesc = new string[] {
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" <=> ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" <=> <=> ",
|
||||||
|
" = ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
"=============> <===",
|
||||||
|
"..............~~~~~." };
|
||||||
|
|
||||||
public World(Texture2D texture) {
|
public World(Texture2D texture) {
|
||||||
width = Camera.Width / TileSize;
|
// TODO: better error handling for if the string[] isn't rectangular.
|
||||||
height = Camera.Height / TileSize + 1;
|
width = worldDesc[0].Length;
|
||||||
|
height = worldDesc.Length;
|
||||||
tiles = new Tile[width, height];
|
tiles = new Tile[width, height];
|
||||||
for (int j = 0; j < height; j++) {
|
for (int j = 0; j < height; j++) {
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
Terrain terrain;
|
Terrain terrain;
|
||||||
if (j < height - 2) {
|
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;
|
terrain = Terrain.Empty;
|
||||||
} else if (j == height - 2) {
|
break;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize);
|
var position = new Rectangle(i * TileSize, j * TileSize, TileSize, TileSize);
|
||||||
tiles[i, j] = new Tile(texture, terrain, position);
|
tiles[i, j] = new Tile(texture, terrain, position);
|
||||||
|
Loading…
Reference in New Issue
Block a user