From 3d05c1e5fa6f96fd05abba5688608aa35d02745e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Thu, 9 Jun 2022 17:32:47 +0200 Subject: [PATCH] done --- src/Entity/Enemy.java | 17 ++++-- src/Entity/Player.java | 17 ++---- src/PokeMudry.java | 64 ++++++++++++++++++++--- src/Screen/ManagerOfScreen.java | 19 +++++++ src/Screen/ScreenMap.java | 22 ++++---- src/Screen/ScreenPlayer.java | 18 +++---- src/testHER.java | 91 --------------------------------- 7 files changed, 115 insertions(+), 133 deletions(-) create mode 100644 src/Screen/ManagerOfScreen.java delete mode 100644 src/testHER.java diff --git a/src/Entity/Enemy.java b/src/Entity/Enemy.java index 5fb1d14..658c27e 100644 --- a/src/Entity/Enemy.java +++ b/src/Entity/Enemy.java @@ -7,11 +7,13 @@ import com.badlogic.gdx.math.Vector2; import ch.hevs.gdx2d.lib.GdxGraphics; public class Enemy extends Character{ + private String map; public FightData fightData; - public Enemy(String name, int x, int y, String img) { + public Enemy(String name, int x, int y, String img, String map) { super(name, x, y, img); + this.map = map; turn(Character.Direction.DOWN); //generate the vector of fight @@ -20,12 +22,17 @@ public class Enemy extends Character{ } - public void setPosition(int x, int y){ - + public String getMap() { + return map; } - public void setPosition(Vector2 vPosition){ - setPosition((int)vPosition.x, (int)vPosition.y); + public void setPosition(int x, int y, String map){ + position.set(x, y); + this.map = map; + } + + public void setPosition(Vector2 vPosition, String map){ + setPosition((int)vPosition.x, (int)vPosition.y, map); } @Override diff --git a/src/Entity/Player.java b/src/Entity/Player.java index ff577ed..06c6d45 100644 --- a/src/Entity/Player.java +++ b/src/Entity/Player.java @@ -46,13 +46,8 @@ public class Player extends Character{ // Is the move valid ? if (sm.isWalkable(nextCell)) { - if(!enemy()){ - // Go - setSpeed(sm.getSpeed(nextCell)); - go(goalDirection); - } else { - - } + setSpeed(sm.getSpeed(nextCell)); + go(goalDirection); } else { // Face the wall turn(goalDirection); @@ -78,12 +73,10 @@ public class Player extends Character{ } private boolean enemy() { - /* - Vector entities = testHER.getEntities; - for (Entity entity : entities) { + //Vector enemies = PokeMudry.getEnemies; + //for (Enemy enemy : enemies) { - } - */ + //} return false; } diff --git a/src/PokeMudry.java b/src/PokeMudry.java index a777dca..b9009a3 100644 --- a/src/PokeMudry.java +++ b/src/PokeMudry.java @@ -1,3 +1,12 @@ +import java.util.Vector; + +import com.badlogic.gdx.Input; + +import Control.Controller; +import Entity.Enemy; +import Entity.Entity; +import Entity.Player; +import Screen.ScreenMap; import Screen.ScreenPlayer; import ch.hevs.gdx2d.desktop.PortableApplication; import ch.hevs.gdx2d.lib.GdxGraphics; @@ -7,7 +16,11 @@ public class PokeMudry extends PortableApplication { public final int PLAYERS = 1; public static final int TIME = 10; // number of minutes for kill all enemy - private ScreenPlayer screenPlayer = new ScreenPlayer(); + private ScreenPlayer sp; + private Controller controller; + //private Player p1; + private static Vector enemies = new Vector<>(); + private static Vector entities = new Vector<>(); public static void main(String[] args) { @@ -16,29 +29,68 @@ public class PokeMudry extends PortableApplication { PokeMudry(){ super(1000, 800); + controller = new Controller(); + sp = new ScreenPlayer(); } - + + public static Vector getEnemies() { + return enemies; + } @Override public void onInit() { - screenPlayer.init(); + sp.init(); + controller.init(); + entities.add((Entity) sp.p); + enemies.add(new Enemy("Mudry", 10, 15, "lumberjack_sheet32", "desert")); + enemies.add(new Enemy("Pignat", 12, 15, "lumberjack_sheet32", "desert")); + + for (Enemy enemy : enemies) { + entities.add(enemy); + } + + for (Entity entity : entities) { + entity.init(); + } } @Override public void onGraphicRender(GdxGraphics g) { - screenPlayer.render(g); + g.clear(); + sp.p.manageEntity(sp.sm, controller); + sp.render(g); + for (Entity entity : entities) { + entity.graphicRender(g); + } } //key gestion @Override public void onKeyDown(int keycode) { - screenPlayer.screenManager.getActiveScreen().onKeyDown(keycode); super.onKeyDown(keycode); + + switch (keycode) { + case Input.Keys.Z: + if (sp.sm.zoom == 1.0) { + sp.sm.zoom = 0.5f; + } else if (sp.sm.zoom == 0.5) { + sp.sm.zoom = 0.25f; + } else { + sp.sm.zoom = 1; + } + return; + + default: + break; + } + controller.keyStatus.put(keycode, true); + sp.screenManager.getActiveScreen().onKeyUp(keycode); } @Override public void onKeyUp(int keycode) { - screenPlayer.screenManager.getActiveScreen().onKeyUp(keycode); super.onKeyUp(keycode); + controller.keyStatus.put(keycode, false); + sp.screenManager.getActiveScreen().onKeyDown(keycode); } } diff --git a/src/Screen/ManagerOfScreen.java b/src/Screen/ManagerOfScreen.java new file mode 100644 index 0000000..e53db94 --- /dev/null +++ b/src/Screen/ManagerOfScreen.java @@ -0,0 +1,19 @@ +package Screen; + +import ch.hevs.gdx2d.lib.ScreenManager; + +public class ManagerOfScreen extends ScreenManager{ + ManagerOfScreen(){ + + } + + ScreenMap getScreenMap(){ + this.activateScreen(0); + return (ScreenMap)this.getActiveScreen(); + } + + ScreenBattle getScreenBattle(){ + this.activateScreen(1); + return (ScreenBattle)this.getActiveScreen(); + } +} \ No newline at end of file diff --git a/src/Screen/ScreenMap.java b/src/Screen/ScreenMap.java index 4e9f955..9a109db 100644 --- a/src/Screen/ScreenMap.java +++ b/src/Screen/ScreenMap.java @@ -55,7 +55,7 @@ public class ScreenMap extends RenderingScreen{ @Override public void onGraphicRender(GdxGraphics g) { - + tiledLayer.clear(); for (int i = 0; i < 50; i++) { try { tiledLayer.add((TiledMapTileLayer) tMap.get(map).getLayers().get(i)); } catch (Exception e) { } @@ -65,25 +65,30 @@ public class ScreenMap extends RenderingScreen{ tileWidth = (int) tl.getTileWidth(); height = tl.getHeight(); tileHeight = (int) tl.getTileHeight(); + //System.out.println(width + " x " + height + " - " + tileWidth + " x " + tileHeight); try { - doors = tMap.get(map).getLayers().get("door").getObjects(); + doors = tMap.get(map).getLayers().get("door").getObjects(); } catch (Exception e) { doors = null; } - - // Camera follows the hero - g.zoom(zoom); - //g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight); + // Render the tileMap tMapRenderer.get(map).setView(g.getCamera()); tMapRenderer.get(map).render(); - + g.drawFPS(); } + void camera(GdxGraphics g, Player player){ + g.zoom(zoom); + g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight); + + } + public Vector getTile(Vector2 position, int offsetX, int offsetY) { Vector tiles = new Vector<>(); + for (TiledMapTileLayer tl : tiledLayer) { int x = (int) (position.x / tileWidth) + offsetX; int y = (int) (position.y / tileHeight) + offsetY; @@ -91,7 +96,7 @@ public class ScreenMap extends RenderingScreen{ Cell cell = tl.getCell(x, y); if (cell == null) continue; tiles.add(cell.getTile()); - } catch (Exception e) { } + } catch (Exception e) { System.out.println("error: cell");} } return tiles; @@ -160,5 +165,4 @@ public class ScreenMap extends RenderingScreen{ nextY = null; } } - } diff --git a/src/Screen/ScreenPlayer.java b/src/Screen/ScreenPlayer.java index ce5fde5..042a75e 100644 --- a/src/Screen/ScreenPlayer.java +++ b/src/Screen/ScreenPlayer.java @@ -2,25 +2,23 @@ package Screen; import Entity.Player; import ch.hevs.gdx2d.lib.GdxGraphics; -import ch.hevs.gdx2d.lib.ScreenManager; public class ScreenPlayer { - public ScreenManager screenManager = new ScreenManager(); + public ManagerOfScreen screenManager = new ManagerOfScreen(); + public Player p; + public ScreenMap sm; - private Player player; public void init(){ - - player = new Player(8, 15); - - screenManager.registerScreen(ScreenMap.class); screenManager.registerScreen(ScreenBattle.class); - + sm = screenManager.getScreenMap(); + p = new Player(8, 15); } public void render(GdxGraphics g){ screenManager.render(g); - + sm.camera(g, p); } -} + +} \ No newline at end of file diff --git a/src/testHER.java b/src/testHER.java deleted file mode 100644 index a11d713..0000000 --- a/src/testHER.java +++ /dev/null @@ -1,91 +0,0 @@ -import java.util.Vector; - -import com.badlogic.gdx.Input; - -import Control.Controller; -import Entity.Enemy; -import Entity.Entity; -import Entity.Player; -import Screen.ScreenMap; -import ch.hevs.gdx2d.desktop.PortableApplication; -import ch.hevs.gdx2d.lib.GdxGraphics; - - -public class testHER extends PortableApplication{ - - private Controller controller; - private ScreenMap sm; - private Player p1; - private static Vector entities = new Vector<>(); - private static Vector players = new Vector<>(); - - - public testHER(){ - controller = new Controller(); - sm = new ScreenMap(); - } - - public static Vector getEntities() { - return entities; - } - - - - public static void main(String[] args) { - new testHER(); - } - - @Override - public void onInit() { - controller.init(); - sm.init(); - p1 = new Player(8, 15); - entities.add((Entity) p1); - entities.add(new Enemy("Mudry", 10, 15, "lumberjack_sheet32")); - entities.add(new Enemy("Pignat", 12, 15, "lumberjack_sheet32")); - - for (Entity entity : entities) { - entity.init(); - } - } - - @Override - public void onGraphicRender(GdxGraphics g) { - g.clear(); - p1.manageEntity(sm, controller); - sm.graphicRender(g, p1); - - for (Entity entity : entities) { - entity.graphicRender(g); - } - } - - @Override - public void onKeyUp(int keycode) { - super.onKeyUp(keycode); - - controller.keyStatus.put(keycode, false); - } - - @Override - public void onKeyDown(int keycode) { - super.onKeyDown(keycode); - - switch (keycode) { - case Input.Keys.Z: - if (sm.zoom == 1.0) { - sm.zoom = 0.5f; - } else if (sm.zoom == 0.5) { - sm.zoom = 0.25f; - } else { - sm.zoom = 1; - } - return; - - default: - break; - } - controller.keyStatus.put(keycode, true); - } - -}