merge Implement mapdrawing into master #3
@@ -32,9 +32,19 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
|
|
||||||
|
|
||||||
String[] strings = new String[]{
|
String[] strings = new String[]{
|
||||||
"####",
|
"#########################",
|
||||||
"# #",
|
"#xxxx #",
|
||||||
"####"
|
"# x #",
|
||||||
|
"# xxxx #",
|
||||||
|
"# xx #",
|
||||||
|
"# x #",
|
||||||
|
"# x #",
|
||||||
|
"# x #",
|
||||||
|
"# x #",
|
||||||
|
"# xxxxxx #",
|
||||||
|
"# x #",
|
||||||
|
"# x xxxx x x #",
|
||||||
|
"#########################"
|
||||||
};
|
};
|
||||||
map = new Map(strings);
|
map = new Map(strings);
|
||||||
mapRenderer = new MapRenderer(map,32,batch);
|
mapRenderer = new MapRenderer(map,32,batch);
|
||||||
@@ -69,7 +79,7 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
public void render() {
|
public void render() {
|
||||||
update();
|
update();
|
||||||
// clear screen
|
// clear screen
|
||||||
Gdx.gl.glClearColor(1, 1, 1, 0);
|
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
mapRenderer.render();
|
mapRenderer.render();
|
||||||
frameRate.render();
|
frameRate.render();
|
||||||
|
|||||||
@@ -12,24 +12,31 @@ public class MapRenderer implements Renderable {
|
|||||||
private Map map;
|
private Map map;
|
||||||
private SpriteBatch batch;
|
private SpriteBatch batch;
|
||||||
private static String tilePath = "core/assets/map/scifitiles-sheet.png";
|
private static String tilePath = "core/assets/map/scifitiles-sheet.png";
|
||||||
public static TextureRegion FLOOR_TILE;
|
|
||||||
public static TextureRegion WALL_TILE;
|
|
||||||
private OrthographicCamera cam;
|
private OrthographicCamera cam;
|
||||||
private static int x = 0;
|
private static int x = 0;
|
||||||
private static int y = 0;
|
private static int y = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public static TextureRegion FLOOR_TILE;
|
||||||
|
public static TextureRegion WALL_TILE;
|
||||||
|
public static TextureRegion PATH_TILE;
|
||||||
|
|
||||||
|
|
||||||
public MapRenderer(Map map, int tileWidth, SpriteBatch batch) {
|
public MapRenderer(Map map, int tileWidth, SpriteBatch batch) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.tileWidth = tileWidth;
|
this.tileWidth = tileWidth;
|
||||||
this.batch = batch;
|
this.batch = batch;
|
||||||
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
makeTiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeTiles() {
|
||||||
Texture texture = new Texture(Gdx.files.internal(tilePath));
|
Texture texture = new Texture(Gdx.files.internal(tilePath));
|
||||||
TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32);
|
TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32);
|
||||||
FLOOR_TILE = tiles[1][6];
|
FLOOR_TILE = tiles[1][6];
|
||||||
WALL_TILE = tiles[0][4];
|
WALL_TILE = tiles[0][4];
|
||||||
System.out.println(map);
|
PATH_TILE = tiles[4][6];
|
||||||
System.out.println(map.getHeight());
|
|
||||||
System.out.println(map.getWidth());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTileWidth() {
|
public int getTileWidth() {
|
||||||
@@ -51,8 +58,7 @@ public class MapRenderer implements Renderable {
|
|||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
batch.begin();
|
batch.begin();
|
||||||
|
for (int row = map.getHeight(); row >= 0; row--) {
|
||||||
for (int row = 0; row < map.getHeight(); row++) {
|
|
||||||
y += 32;
|
y += 32;
|
||||||
x = 0;
|
x = 0;
|
||||||
for (int col = 0; col < map.getWidth(); col++) {
|
for (int col = 0; col < map.getWidth(); col++) {
|
||||||
@@ -60,6 +66,8 @@ public class MapRenderer implements Renderable {
|
|||||||
batch.draw(FLOOR_TILE, x, y);
|
batch.draw(FLOOR_TILE, x, y);
|
||||||
} else if (map.get(row, col) == '#') {
|
} else if (map.get(row, col) == '#') {
|
||||||
batch.draw(WALL_TILE, x, y);
|
batch.draw(WALL_TILE, x, y);
|
||||||
|
} else if (map.get(row,col) == 'x') {
|
||||||
|
batch.draw(PATH_TILE,x,y);
|
||||||
}
|
}
|
||||||
x += 32;
|
x += 32;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user