diff --git a/src/Main/PokeMudry.java b/src/Main/PokeMudry.java index 7fe5f30..f057f66 100644 --- a/src/Main/PokeMudry.java +++ b/src/Main/PokeMudry.java @@ -10,6 +10,8 @@ import com.badlogic.gdx.Input; import Control.Controller; import Entity.Enemy; import Entity.Entity; +import Game.Battle; +import Screen.ScreenBattle; import Screen.ScreenMap; import Screen.ScreenPlayer; import ch.hevs.gdx2d.desktop.PortableApplication; @@ -57,28 +59,29 @@ public class PokeMudry extends PortableApplication { @Override public void onGraphicRender(GdxGraphics g) { g.clear(); - sp.p.manageEntity(sp.sm, controller); - sp.sb.manage(controller); - sp.render(g); - //System.out.println(ScreenMap.class); - boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class); + boolean onBattleScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenBattle.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); - } // Switch screen if (sp.p.frontOfEnemy && onMapScreen){ sp.e = sp.p.lastEnemy; - sp.screenManager.activateNextScreen(); + //sp.screenManager.activateNextScreen(); + sp.sb = sp.screenManager.getScreenBattle(); + sp.b = new Battle(sp.e); g.resetCamera(); } + + if(onBattleScreen) sp.sb.manage(controller, sp.b); + + // Graphics render + 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); + } } diff --git a/src/Screen/ScreenBattle.java b/src/Screen/ScreenBattle.java index 9d8e94f..c8d79a6 100644 --- a/src/Screen/ScreenBattle.java +++ b/src/Screen/ScreenBattle.java @@ -30,7 +30,7 @@ public class ScreenBattle extends RenderingScreen{ private BitmapFont optimus40; - private Battle battle; + private Battle b = null; private Enemy enemy; @@ -38,7 +38,7 @@ public class ScreenBattle extends RenderingScreen{ @Override public void onInit() { //new battle game - battle = new Battle(enemy); + //battle = new Battle(enemy); //display the question generateFont("resources/font/OptimusPrinceps.ttf", 40, Color.BLACK); @@ -52,7 +52,7 @@ public class ScreenBattle extends RenderingScreen{ displayDialog(g); - System.out.println("render: " + battle.getLineSpeech()); + //System.out.println("render: " + battle.getLineSpeech()); } @Override @@ -60,7 +60,13 @@ public class ScreenBattle extends RenderingScreen{ optimus40.dispose(); } + + public void setBattle(Battle battle) { + this.b = battle; + } + public void generateFont(String file, int height, Color c ){ + //Generate font with the file .ttf FileHandle fileHandle = Gdx.files.internal(file); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); @@ -77,7 +83,8 @@ public class ScreenBattle extends RenderingScreen{ g.drawFilledRectangle(Settings.SIDE/2, HEIGHT_DIALOG/2 + EDGE, WIDTH_DIALOG, HEIGHT_DIALOG, 0); //dialog - g.drawString(15, 245 ,battle.getLine() , optimus40); + + if(b != null) g.drawString(15, 245 ,b.getLine() , optimus40); @@ -95,7 +102,7 @@ public class ScreenBattle extends RenderingScreen{ //TODO afficher le joueur } - public void manage(Controller c){ + public void manage(Controller c, Battle battle){ if(PokeMudry.front_montant){ System.out.println("manage: " + battle.getLineSpeech()); diff --git a/src/Screen/ScreenPlayer.java b/src/Screen/ScreenPlayer.java index 4b81b84..6eb5ddc 100644 --- a/src/Screen/ScreenPlayer.java +++ b/src/Screen/ScreenPlayer.java @@ -2,14 +2,16 @@ package Screen; import Entity.Enemy; import Entity.Player; +import Game.Battle; import ch.hevs.gdx2d.lib.GdxGraphics; public class ScreenPlayer { public ManagerOfScreen screenManager = new ManagerOfScreen(); - public Player p; - public Enemy e; - public ScreenMap sm; - public ScreenBattle sb; + public Player p = null; + public Enemy e = null; + public Battle b = null; + public ScreenMap sm = null; + public ScreenBattle sb = null; public void init(){ @@ -19,13 +21,18 @@ public class ScreenPlayer { // Create both type of screen and record for reuse screenManager.registerScreen(ScreenMap.class); screenManager.registerScreen(ScreenBattle.class); - sb = screenManager.getScreenBattle(); sm = screenManager.getScreenMap(); + } public void render(GdxGraphics g){ - sb.setEnemy(e); sm.setPlayer(p); + + if(sb != null){ + sb.setEnemy(e); + sb.setBattle(b); + } + screenManager.render(g); }