From 74956e5e0b11eb80a8b356e0087ba6bc1515c205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 10 Jun 2022 19:36:22 +0200 Subject: [PATCH 1/2] first pass --- src/Entity/Player.java | 1 - src/Main/PokeMudry.java | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Entity/Player.java b/src/Entity/Player.java index ed31a4b..61ba43b 100644 --- a/src/Entity/Player.java +++ b/src/Entity/Player.java @@ -1,6 +1,5 @@ package Entity; -import java.util.TreeMap; import java.util.Vector; import com.badlogic.gdx.Input; diff --git a/src/Main/PokeMudry.java b/src/Main/PokeMudry.java index 094fdbe..fdc75cd 100644 --- a/src/Main/PokeMudry.java +++ b/src/Main/PokeMudry.java @@ -2,10 +2,7 @@ package Main; import java.util.Vector; -import java.util.Map.Entry; - import com.badlogic.gdx.Input; - import Control.Controller; import Entity.Enemy; import Entity.Entity; @@ -60,6 +57,8 @@ public class PokeMudry extends PortableApplication { if (entity.getMap().equals(sp.sm.map) && sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class)) entity.graphicRender(g); + + } if (sp.p.frontOfEnemy && sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class)){ From 5008b6e18a2bd1698faa40f357abcca61a4aab20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Sun, 12 Jun 2022 12:35:08 +0200 Subject: [PATCH 2/2] polish and bug fix --- src/Control/Keyboard.java | 26 ++++++++++++++++++++++++++ src/Entity/Character.java | 10 +++++++++- src/Entity/Entity.java | 13 +++++++++++++ src/Entity/Player.java | 4 ++-- src/Main/PokeMudry.java | 27 +++++++++++++++------------ src/Screen/ScreenMap.java | 13 ++++--------- src/Screen/ScreenPlayer.java | 4 ++++ 7 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 src/Control/Keyboard.java diff --git a/src/Control/Keyboard.java b/src/Control/Keyboard.java new file mode 100644 index 0000000..56721ac --- /dev/null +++ b/src/Control/Keyboard.java @@ -0,0 +1,26 @@ +package Control; + +import com.badlogic.gdx.Input; + +import Screen.ScreenPlayer; + +public class Keyboard { + public void keyDown(int keycode, ScreenPlayer sp, Controller c) { + switch (keycode) { + case Input.Keys.Z: + if (sp.sm.zoom == 1.0) { + sp.sm.zoom = 0.5f; + } else { + sp.sm.zoom = 1; + } + return; + + default: + break; + } + c.keyStatus.put(keycode, true); + } + public void onKeyUp(int keycode, ScreenPlayer sp, Controller c) { + c.keyStatus.put(keycode, false); + } +} diff --git a/src/Entity/Character.java b/src/Entity/Character.java index 934736d..d94aa6b 100644 --- a/src/Entity/Character.java +++ b/src/Entity/Character.java @@ -32,6 +32,14 @@ public abstract class Character extends Entity{ protected int pv; + /** + * Create a character on the world + * @param name Name of the new character + * @param x initial x position + * @param y initial y position + * @param img the name of the spritesheet for this character + * @param map the initial map + */ public Character(String name, int x, int y, String img, String map){ super(name, x, y, map); this.img = img; @@ -87,7 +95,7 @@ public abstract class Character extends Entity{ } /** - * @param speed The new speed of the hero. + * @param speed The new speed of the character. */ public void setSpeed(float speed){ this.speed = speed; diff --git a/src/Entity/Entity.java b/src/Entity/Entity.java index 9d69b21..f9f6280 100644 --- a/src/Entity/Entity.java +++ b/src/Entity/Entity.java @@ -22,10 +22,23 @@ public abstract class Entity implements DrawableObject { protected boolean move = false; + /** + * Create an entity + * @param name The name of this new entity + * @param x The initial x position + * @param y The initial y position + * @param map The initial map + */ public Entity(String name, int x, int y, String map){ this(name, new Vector2(SPRITE_WIDTH * x, SPRITE_HEIGHT * y), map); } + /** + * Create an entity + * @param name The name of this new entity + * @param initialPosition The initial position by a Vector2 + * @param map The initial map + */ public Entity(String name, Vector2 initialPosition, String map){ this.name = name; lastPosition = new Vector2(initialPosition); diff --git a/src/Entity/Player.java b/src/Entity/Player.java index 61ba43b..d4aa5ac 100644 --- a/src/Entity/Player.java +++ b/src/Entity/Player.java @@ -56,7 +56,7 @@ public class Player extends Character{ if (sm.isWalkable(nextCell)) { if (enemy(sm, nextPos)) { - //turn(goalDirection); + turn(goalDirection); System.out.println("It's a enemy !!"); } else { setSpeed(sm.getSpeed(nextCell)); @@ -94,7 +94,7 @@ public class Player extends Character{ int pY = (int) nextPos.y/sm.tileHeight; int eX = (int) enemy.position.x/sm.tileWidth; int eY = (int) enemy.position.y/sm.tileHeight; - //System.out.println("Player: " + pX + " x " + pY + " - Enemy: " + eX + " x " + eY); + if(bMap && pX==eX && pY==eY) { lastEnemy = enemy; frontOfEnemy = true; diff --git a/src/Main/PokeMudry.java b/src/Main/PokeMudry.java index fdc75cd..da6063b 100644 --- a/src/Main/PokeMudry.java +++ b/src/Main/PokeMudry.java @@ -37,31 +37,34 @@ public class PokeMudry extends PortableApplication { public void onInit() { sp.init(); controller.init(); + + // add player, create and add all enemies in entities entities.add((Entity) sp.p); enemies.add(new Enemy("Mudry", 10, 15, "lumberjack_sheet32", "desert")); enemies.add(new Enemy("Pignat", 5, 1, "lumberjack_sheet32", "test")); - for (Enemy enemy : enemies) { entities.add(enemy); } - for (Entity entity : entities) { entity.init(); } + //Init all entities + for (Entity entity : entities) { entity.init(); } } @Override public void onGraphicRender(GdxGraphics g) { g.clear(); - sp.p.manageEntity(sp.sm, controller); - sp.render(g); - System.out.println(sp.screenManager.getActiveScreen().getClass()); - //System.out.println(ScreenMap.class); - for (Entity entity : entities) { - - if (entity.getMap().equals(sp.sm.map) && sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class)) - entity.graphicRender(g); - + boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class); + + if(onMapScreen) sp.p.manageEntity(sp.sm, controller); + sp.render(g); + + for (Entity entity : entities) { + // Render only entities on the good map + if (entity.getMap().equals(sp.sm.map) && onMapScreen) + entity.graphicRender(g); } - if (sp.p.frontOfEnemy && sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class)){ + // Switch screen + if (sp.p.frontOfEnemy && onMapScreen){ sp.e = sp.p.lastEnemy; System.out.println("switch screen"); sp.screenManager.activateNextScreen(); diff --git a/src/Screen/ScreenMap.java b/src/Screen/ScreenMap.java index 9cd2527..09c2a9f 100644 --- a/src/Screen/ScreenMap.java +++ b/src/Screen/ScreenMap.java @@ -27,7 +27,7 @@ public class ScreenMap extends RenderingScreen{ private MapObjects doors; Map tMap = new TreeMap(); Map tMapRenderer = new TreeMap(); - public String map = "test_couloir"; + public String map; public float zoom; private int width; public int tileWidth; @@ -35,8 +35,6 @@ public class ScreenMap extends RenderingScreen{ public int tileHeight; private Player player; - - private void createMap(String name){ TiledMap tm =new TmxMapLoader().load("./resources/map/"+ name + ".tmx"); tMap.put(name,tm); @@ -79,12 +77,9 @@ public class ScreenMap extends RenderingScreen{ // Render the tileMap - try { - g.zoom(zoom); - g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight); - } catch (Exception e) { - //TODO: handle exception - } + 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");} tMapRenderer.get(map).setView(g.getCamera()); tMapRenderer.get(map).render(); diff --git a/src/Screen/ScreenPlayer.java b/src/Screen/ScreenPlayer.java index a445491..4b81b84 100644 --- a/src/Screen/ScreenPlayer.java +++ b/src/Screen/ScreenPlayer.java @@ -12,7 +12,11 @@ public class ScreenPlayer { public ScreenBattle sb; public void init(){ + + // One player by ScreenPlayer p = new Player(8, 15, "desert"); + + // Create both type of screen and record for reuse screenManager.registerScreen(ScreenMap.class); screenManager.registerScreen(ScreenBattle.class); sb = screenManager.getScreenBattle();