diff --git a/app/src/main/java/Screen/ScreenMap.java b/app/src/main/java/Screen/ScreenMap.java index b17e20b..48fa8c8 100644 --- a/app/src/main/java/Screen/ScreenMap.java +++ b/app/src/main/java/Screen/ScreenMap.java @@ -26,13 +26,14 @@ public class ScreenMap { private MapObjects doors; Map tMap = new TreeMap(); Map tMapRenderer = new TreeMap(); - private String map = "test_couloir"; + private String map = "desert"; public float zoom; private int width; private int tileWidth; private int height; private int tileHeight; + // position Vector2 pannel = new Vector2(30, 30); @@ -59,14 +60,17 @@ public class ScreenMap { // create map createMap("test"); createMap("test_couloir"); + createMap("desert"); } public void graphicRender(GdxGraphics g) { g.clear(); - for (int i = 0; i < 100; i++) { + tiledLayer.clear(); + for (int i = 0; i < 50; i++) { try { tiledLayer.add((TiledMapTileLayer) tMap.get(map).getLayers().get(i)); } catch (Exception e) { } } + //System.out.println(tiledLayer.size() + " layers imported"); TiledMapTileLayer tl = tiledLayer.get(0); width = tl.getWidth(); tileWidth = (int) tl.getTileWidth(); @@ -75,11 +79,11 @@ public class ScreenMap { //System.out.println(width + " x " + height + " - " + tileWidth + " x " + tileHeight); try { doors = tMap.get(map).getLayers().get("door").getObjects(); - } catch (Exception e) { } + } catch (Exception e) { doors = null; } // Hero activity manageHero(); - // System.out.println(hero.getPosition().x + " - " + hero.getPosition().y); + System.out.println("Hero: " + (int)hero.getPosition().x/tileWidth + " x " + (int)hero.getPosition().y/tileHeight); // Camera follows the hero g.zoom(zoom); @@ -99,20 +103,13 @@ public class ScreenMap { private Vector getTile(Vector2 position, int offsetX, int offsetY) { Vector tiles = new Vector<>(); for (TiledMapTileLayer tl : tiledLayer) { - int x = (int) (position.x / width) + offsetX; - int y = (int) (position.y / height) + offsetY; - System.out.println("tl: " + tl); + int x = (int) (position.x / tileWidth) + offsetX; + int y = (int) (position.y / tileHeight) + offsetY; try { - System.out.println("begin"); - System.out.println( tl.getName()); Cell cell = tl.getCell(x, y); - System.out.println("cell: "+ cell); - if (tl.getCell(x, y) == null) continue; - System.out.println("not null"); - TiledMapTile t = cell.getTile(); - System.out.println("t: " + t); - tiles.add(t); - } catch (Exception e) { System.out.println("shit");} + if (cell == null) continue; + tiles.add(cell.getTile()); + } catch (Exception e) { } } return tiles; @@ -121,15 +118,10 @@ public class ScreenMap { private boolean isWalkable(Vector tile) { if (tile == null) return false; boolean walkable = false; - System.out.println("tile: " + tile); - for (TiledMapTile tiledMapTile : tile) { - System.out.println("tiledMapTile: " + tiledMapTile); Object test = tiledMapTile.getProperties().get("walkable"); walkable = Boolean.parseBoolean(test.toString()) ? true:walkable; } - - //System.out.println(" walkable: " + walkable); return walkable; } @@ -143,20 +135,16 @@ public class ScreenMap { return speed; } - private String getName(TiledMap tile) { - Object test = tile.getProperties().get("name"); - return test.toString(); - } - private boolean isDoor(Vector2 position) { + if (doors == null) return false; boolean onDoor = false; Integer x = null; Integer y = null; int ox = 0; int oy = 0; try { - x = (int) (position.x / 32); //tiledLayer.getTileWidth() - y = (int) (position.y / 32); //tiledLayer.getTileHeight() + x = (int) (position.x / tileWidth); + y = (int) (position.y / tileHeight); } catch (Exception e) { } for (MapObject object : doors){ @@ -165,17 +153,15 @@ public class ScreenMap { try { ox = (int) ((float) mapProperties.get("x")); } catch (Exception e) { } try { oy = (int) ((float) mapProperties.get("y")); } catch (Exception e) { } - oy-=288; - oy/=-1; + ox /= tileWidth; + oy /= tileHeight; - ox /= 32; - oy /= 32; - - String id = null; - try { id = mapProperties.get("id").toString(); } catch (Exception e) { } - //if(x != null && y != null) System.out.println(id + ": " + x + " x " + y + " - " + ox + " x " + oy); - - if (x != null || y != null) onDoor = (x == ox && y == oy) ? true:onDoor; + if ((x != null || y != null) && (x == ox && y == oy)) { + onDoor = true; + try { Door.nextMap = mapProperties.get("nextMap").toString(); } catch (Exception e) { System.out.println("shit 1"); } + try { Door.nextX = Integer.parseInt(mapProperties.get("nextX").toString()); } catch (Exception e) { System.out.println("shit 2"); } + try { Door.nextY = Integer.parseInt(mapProperties.get("nextY").toString()); } catch (Exception e) { System.out.println("shit 3"); } + } } return onDoor; @@ -216,23 +202,33 @@ public class ScreenMap { if(isDoor(hero.getPosition())){ - /* - switch(getName(tMap.get(map))){ - case "test": - if(hero.getPosition().x == 32 && hero.getPosition().y == 288){ - hero.setPosition(576, 256); - map = "desert"; - } - break; - default: - - break; - } - */ - - System.out.println("it's a door"); + String nMap = null; + Integer x = null; + Integer y = null; + try { + nMap = Door.nextMap; + x = Door.nextX; + y = Door.nextY; + } catch (Exception e) { } + Door.reset(); + if (nMap == null || x == null || y == null) return; + map = nMap; + hero.setPosition(x*tileWidth, y*tileHeight); + System.out.println("Go to: " + map + " in " + x + " x " + y); } } } + static class Door { + static String nextMap; + static Integer nextX; + static Integer nextY; + + static void reset(){ + nextMap = null; + nextX = null; + nextY = null; + } + } + } diff --git a/app/src/main/java/testHER.java b/app/src/main/java/testHER.java index 03b5f7f..5bf95d0 100644 --- a/app/src/main/java/testHER.java +++ b/app/src/main/java/testHER.java @@ -38,9 +38,9 @@ public class testHER extends PortableApplication{ switch (keycode) { case Input.Keys.Z: if (sm.zoom == 1.0) { - sm.zoom = 2.0f; - } else if (sm.zoom == 2.0) { - sm.zoom = 4; + sm.zoom = 0.5f; + } else if (sm.zoom == 0.5) { + sm.zoom = 0.25f; } else { sm.zoom = 1; } diff --git a/app/src/main/resources/map/desert.tmx b/app/src/main/resources/map/desert.tmx new file mode 100644 index 0000000..f7cdc35 --- /dev/null +++ b/app/src/main/resources/map/desert.tmx @@ -0,0 +1,485 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eJztmNtOwzAMQAPjPi4DJK5idCvsAgP6/1+HK2rJMlliO03Xhz4cbc3S5sR22nRT59w0I5fAFTBJuMYRcJyJi8bvPNLvRDDHXRKKb6rfAXCfyEOCX2z80LX3gH1gRNpeA/1jftTlkMX+EXhS8AycAmfAWOm0zW/iace2GTBXUGb0WwF3LH/o9wZ8AO879PMxI+NK4inxk9QixslX64vMflrXmop5cb+N+6v/r47yi6wix7F48boM+UljxR2wjcYPv8f8eFzbit+SHaOPNn6588s9Oesmf1I+lX6+nNP9Az6LQoyE/ZCXgJ+kBul9D+caYizs5zvPsj7ofe8auIlwK+znOy/mUgR+i9Ve1xRbYtwnz6JDH8verAuv7+ZTcu+kz5+ypfGlSPxqp6rp26XfTyY/rBlLLfC6zuHH91MpdSvxo/sLjR+foza3Uj/tOHQ/gHu6jTGGFr/KeH3L2soRv5Cfdu1Y9mZWvzrHdI+css7bop6/7323dP/f61IoEh19eVg7W076Do+V9n+jvngPDAz4+QU9mLB5 + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/resources/map/test_couloir.tmx b/app/src/main/resources/map/test_couloir.tmx index 1a13639..3cbe8b4 100644 --- a/app/src/main/resources/map/test_couloir.tmx +++ b/app/src/main/resources/map/test_couloir.tmx @@ -8996,26 +8996,30 @@ - + + - + + - + + - + +