From e71d23dd810bfd8f4cb8c019ede2c596eb7c702d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Mon, 13 Jun 2022 19:26:52 +0200 Subject: [PATCH] fix bug !!! (hallelujah) --- src/Entity/Player.java | 8 ++++---- src/Main/PokeMudry.java | 2 +- src/Screen/ScreenMap.java | 14 +++++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Entity/Player.java b/src/Entity/Player.java index d5fa801..57d3b3f 100644 --- a/src/Entity/Player.java +++ b/src/Entity/Player.java @@ -14,10 +14,10 @@ public class Player extends Character{ private int xp; public Enemy lastEnemy = null; - public boolean frontOfEnemy = false; + public boolean onEnemy = false; public Player(int x, int y, String map) { - super("Player", x, y, "Character", map); + super("Player", x, y, "character", map); } public void addXp(int xp){ @@ -32,7 +32,7 @@ public class Player extends Character{ // Compute direction and next cell Vector nextCell = new Vector<>(); Player.Direction goalDirection = Player.Direction.NULL; - Vector2 nextPos = position; + Vector2 nextPos = new Vector2(position); if (c.keyStatus.get(Input.Keys.RIGHT)) { goalDirection = Player.Direction.RIGHT; @@ -98,7 +98,7 @@ public class Player extends Character{ if(bMap && pX==eX && pY==eY) { lastEnemy = enemy; - frontOfEnemy = true; + onEnemy = true; return true; } } diff --git a/src/Main/PokeMudry.java b/src/Main/PokeMudry.java index 4ff97e1..372370d 100644 --- a/src/Main/PokeMudry.java +++ b/src/Main/PokeMudry.java @@ -62,7 +62,7 @@ public class PokeMudry extends PortableApplication { if(onMapScreen) sp.p.manageEntity(sp.sm, controller); // Switch screen - if (sp.p.frontOfEnemy && onMapScreen){ + if (sp.p.onEnemy && onMapScreen){ sp.e = sp.p.lastEnemy; sp.sb = sp.screenManager.getScreenBattle(); sp.b = new Battle(sp.e); diff --git a/src/Screen/ScreenMap.java b/src/Screen/ScreenMap.java index 5f27e08..e6cc804 100644 --- a/src/Screen/ScreenMap.java +++ b/src/Screen/ScreenMap.java @@ -59,19 +59,24 @@ public class ScreenMap extends RenderingScreen{ tiledLayer.clear(); + // Get actual map of the player try { map = player.getMap(); } catch (Exception e) { System.out.println("error for get map");} - for (int i = 0; i < 50; i++) { + // Get all layers on the current map + for (int i = 0; i < 50; i++) { try { tiledLayer.add((TiledMapTileLayer) tMap.get(map).getLayers().get(i)); } catch (Exception e) { } } - if (tiledLayer.size() <= 0) System.out.println("TiledLayer empty !!!"); + + // Get heigh and width of tiles and the size of the tiles TiledMapTileLayer tl = tiledLayer.get(0); width = tl.getWidth(); tileWidth = (int) tl.getTileWidth(); height = tl.getHeight(); tileHeight = (int) tl.getTileHeight(); - //System.out.println(width + " x " + height + " - " + tileWidth + " x " + tileHeight); + // System.out.println(width + " x " + height + " - " + tileWidth + " x " + tileHeight); + + // Get all doors on the current map try { doors = tMap.get(map).getLayers().get("door").getObjects(); } catch (Exception e) { doors = null; } @@ -79,8 +84,7 @@ public class ScreenMap extends RenderingScreen{ // Render the tileMap g.zoom(zoom); - try {g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight);} - catch (Exception e) {System.out.println("Fail to move camera");} + g.moveCamera((int)player.getPosition().x, (int)player.getPosition().y, width * tileWidth, height * tileHeight); tMapRenderer.get(map).setView(g.getCamera()); tMapRenderer.get(map).render();