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]) {
|
||||||
terrain = Terrain.Empty;
|
case '=':
|
||||||
} else if (j == height - 2) {
|
terrain = Terrain.Grass;
|
||||||
terrain = Terrain.Grass;
|
break;
|
||||||
} else {
|
case '<':
|
||||||
terrain = Terrain.Rock;
|
terrain = Terrain.GrassL;
|
||||||
}
|
break;
|
||||||
if (j == 6 && 11 < i && i < 16) {
|
case '>':
|
||||||
terrain = Terrain.Grass;
|
terrain = Terrain.GrassR;
|
||||||
}
|
break;
|
||||||
if (j == 3 && 15 < i && i < 19) {
|
case '.':
|
||||||
terrain = Terrain.Grass;
|
terrain = Terrain.Rock;
|
||||||
}
|
break;
|
||||||
if (j == 7 && i == 5) {
|
case '~':
|
||||||
terrain = Terrain.Grass;
|
terrain = Terrain.Water;
|
||||||
}
|
break;
|
||||||
if (7 <= j && j <= 10 && i == 12) {
|
case ' ':
|
||||||
terrain = Terrain.Rock;
|
default:
|
||||||
|
terrain = Terrain.Empty;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
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