From 2eb3aa7ecf7b27525d3c34eb32060c159874160f Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 18 May 2020 14:16:32 +0200 Subject: [PATCH] added test path --- core/src/netwerkprog/game/MainGame.java | 18 +++++++++++---- .../game/client/map/MapRenderer.java | 22 +++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/core/src/netwerkprog/game/MainGame.java b/core/src/netwerkprog/game/MainGame.java index 49e7c92..632520c 100644 --- a/core/src/netwerkprog/game/MainGame.java +++ b/core/src/netwerkprog/game/MainGame.java @@ -32,9 +32,19 @@ public class MainGame extends ApplicationAdapter { String[] strings = new String[]{ - "####", - "# #", - "####" + "#########################", + "#xxxx #", + "# x #", + "# xxxx #", + "# xx #", + "# x #", + "# x #", + "# x #", + "# x #", + "# xxxxxx #", + "# x #", + "# x xxxx x x #", + "#########################" }; map = new Map(strings); mapRenderer = new MapRenderer(map,32,batch); @@ -69,7 +79,7 @@ public class MainGame extends ApplicationAdapter { public void render() { update(); // clear screen - Gdx.gl.glClearColor(1, 1, 1, 0); + Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); mapRenderer.render(); frameRate.render(); diff --git a/core/src/netwerkprog/game/client/map/MapRenderer.java b/core/src/netwerkprog/game/client/map/MapRenderer.java index dfaa8b1..c12e7fb 100644 --- a/core/src/netwerkprog/game/client/map/MapRenderer.java +++ b/core/src/netwerkprog/game/client/map/MapRenderer.java @@ -12,24 +12,31 @@ public class MapRenderer implements Renderable { private Map map; private SpriteBatch batch; private static String tilePath = "core/assets/map/scifitiles-sheet.png"; - public static TextureRegion FLOOR_TILE; - public static TextureRegion WALL_TILE; private OrthographicCamera cam; private static int x = 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) { this.map = map; this.tileWidth = tileWidth; this.batch = batch; cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + makeTiles(); + } + + private void makeTiles() { Texture texture = new Texture(Gdx.files.internal(tilePath)); TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32); FLOOR_TILE = tiles[1][6]; WALL_TILE = tiles[0][4]; - System.out.println(map); - System.out.println(map.getHeight()); - System.out.println(map.getWidth()); + PATH_TILE = tiles[4][6]; + } public int getTileWidth() { @@ -51,8 +58,7 @@ public class MapRenderer implements Renderable { @Override public void render() { batch.begin(); - - for (int row = 0; row < map.getHeight(); row++) { + for (int row = map.getHeight(); row >= 0; row--) { y += 32; x = 0; for (int col = 0; col < map.getWidth(); col++) { @@ -60,6 +66,8 @@ public class MapRenderer implements Renderable { batch.draw(FLOOR_TILE, x, y); } else if (map.get(row, col) == '#') { batch.draw(WALL_TILE, x, y); + } else if (map.get(row,col) == 'x') { + batch.draw(PATH_TILE,x,y); } x += 32; }