1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2024-11-23 09:53:28 +00:00

switch screen

This commit is contained in:
Rémi Heredero 2022-06-10 18:49:02 +02:00
parent df732ad57f
commit 697c9e659f
6 changed files with 44 additions and 22 deletions

View File

@ -1,5 +1,6 @@
package Entity; package Entity;
import java.util.TreeMap;
import java.util.Vector; import java.util.Vector;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
@ -13,9 +14,11 @@ import Screen.ScreenMap;
public class Player extends Character{ public class Player extends Character{
private int xp; private int xp;
public Enemy lastEnemy = null;
public boolean frontOfEnemy = false;
public Player(int x, int y, String map) { public Player(int x, int y, String map) {
super("Player", x, y, "lumberjack_sheet32", map); super("Player", x, y, "Character", map);
} }
public void addXp(int xp){ public void addXp(int xp){
@ -54,6 +57,7 @@ public class Player extends Character{
if (sm.isWalkable(nextCell)) { if (sm.isWalkable(nextCell)) {
if (enemy(sm, nextPos)) { if (enemy(sm, nextPos)) {
//turn(goalDirection);
System.out.println("It's a enemy !!"); System.out.println("It's a enemy !!");
} else { } else {
setSpeed(sm.getSpeed(nextCell)); setSpeed(sm.getSpeed(nextCell));
@ -92,19 +96,15 @@ public class Player extends Character{
int eX = (int) enemy.position.x/sm.tileWidth; int eX = (int) enemy.position.x/sm.tileWidth;
int eY = (int) enemy.position.y/sm.tileHeight; int eY = (int) enemy.position.y/sm.tileHeight;
//System.out.println("Player: " + pX + " x " + pY + " - Enemy: " + eX + " x " + eY); //System.out.println("Player: " + pX + " x " + pY + " - Enemy: " + eX + " x " + eY);
if(bMap && pX==eX && pY==eY) return true; if(bMap && pX==eX && pY==eY) {
lastEnemy = enemy;
frontOfEnemy = true;
return true;
}
} }
return false; return false;
} }
public void move(int x, int y){
}
public void move(Vector2 vMove){
move((int)vMove.x, (int)vMove.y);
}
@Override @Override
protected void removedPv(int pv) { protected void removedPv(int pv) {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -2,12 +2,14 @@ package Main;
import java.util.Vector; import java.util.Vector;
import java.util.Map.Entry;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import Control.Controller; import Control.Controller;
import Entity.Enemy; import Entity.Enemy;
import Entity.Entity; import Entity.Entity;
import Screen.ScreenMap;
import Screen.ScreenPlayer; import Screen.ScreenPlayer;
import ch.hevs.gdx2d.desktop.PortableApplication; import ch.hevs.gdx2d.desktop.PortableApplication;
import ch.hevs.gdx2d.lib.GdxGraphics; import ch.hevs.gdx2d.lib.GdxGraphics;
@ -42,13 +44,9 @@ public class PokeMudry extends PortableApplication {
enemies.add(new Enemy("Mudry", 10, 15, "lumberjack_sheet32", "desert")); enemies.add(new Enemy("Mudry", 10, 15, "lumberjack_sheet32", "desert"));
enemies.add(new Enemy("Pignat", 5, 1, "lumberjack_sheet32", "test")); enemies.add(new Enemy("Pignat", 5, 1, "lumberjack_sheet32", "test"));
for (Enemy enemy : enemies) { for (Enemy enemy : enemies) { entities.add(enemy); }
entities.add(enemy);
}
for (Entity entity : entities) { for (Entity entity : entities) { entity.init(); }
entity.init();
}
} }
@Override @Override
@ -56,9 +54,19 @@ public class PokeMudry extends PortableApplication {
g.clear(); g.clear();
sp.p.manageEntity(sp.sm, controller); sp.p.manageEntity(sp.sm, controller);
sp.render(g); sp.render(g);
System.out.println(sp.screenManager.getActiveScreen().getClass());
//System.out.println(ScreenMap.class);
for (Entity entity : entities) { for (Entity entity : entities) {
if (entity.getMap().equals(sp.sm.map)) entity.graphicRender(g);
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)){
sp.e = sp.p.lastEnemy;
System.out.println("switch screen");
sp.screenManager.activateNextScreen();
}
} }

View File

@ -4,15 +4,14 @@ import ch.hevs.gdx2d.lib.ScreenManager;
public class ManagerOfScreen extends ScreenManager{ public class ManagerOfScreen extends ScreenManager{
ManagerOfScreen(){ ManagerOfScreen(){
} }
ScreenMap getScreenMap(){ public ScreenMap getScreenMap(){
this.activateScreen(0); this.activateScreen(0);
return (ScreenMap)this.getActiveScreen(); return (ScreenMap)this.getActiveScreen();
} }
ScreenBattle getScreenBattle(){ public ScreenBattle getScreenBattle(){
this.activateScreen(1); this.activateScreen(1);
return (ScreenBattle)this.getActiveScreen(); return (ScreenBattle)this.getActiveScreen();
} }

View File

@ -20,6 +20,7 @@ public class ScreenBattle extends RenderingScreen{
private static int EDGE = 10; private static int EDGE = 10;
private static int HEIGHT_DIALOG = Settings.SIDE / 3; private static int HEIGHT_DIALOG = Settings.SIDE / 3;
private static int WIDTH_DIALOG = Settings.SIDE - 2*EDGE; private static int WIDTH_DIALOG = Settings.SIDE - 2*EDGE;
private Enemy e;
private boolean attackOn; private boolean attackOn;
private int numAttack =0; private int numAttack =0;
@ -60,6 +61,10 @@ public class ScreenBattle extends RenderingScreen{
} }
public void setEnemy(Enemy e) {
this.e = e;
}
public void displayEnemy(Enemy e){ public void displayEnemy(Enemy e){
// stock his speech // stock his speech

View File

@ -79,8 +79,13 @@ public class ScreenMap extends RenderingScreen{
// Render the tileMap // Render the tileMap
g.zoom(zoom); try {
g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight); g.zoom(zoom);
g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight);
} catch (Exception e) {
//TODO: handle exception
}
tMapRenderer.get(map).setView(g.getCamera()); tMapRenderer.get(map).setView(g.getCamera());
tMapRenderer.get(map).render(); tMapRenderer.get(map).render();

View File

@ -1,21 +1,26 @@
package Screen; package Screen;
import Entity.Enemy;
import Entity.Player; import Entity.Player;
import ch.hevs.gdx2d.lib.GdxGraphics; import ch.hevs.gdx2d.lib.GdxGraphics;
public class ScreenPlayer { public class ScreenPlayer {
public ManagerOfScreen screenManager = new ManagerOfScreen(); public ManagerOfScreen screenManager = new ManagerOfScreen();
public Player p; public Player p;
public Enemy e;
public ScreenMap sm; public ScreenMap sm;
public ScreenBattle sb;
public void init(){ public void init(){
p = new Player(8, 15, "desert"); p = new Player(8, 15, "desert");
screenManager.registerScreen(ScreenMap.class); screenManager.registerScreen(ScreenMap.class);
screenManager.registerScreen(ScreenBattle.class); screenManager.registerScreen(ScreenBattle.class);
sb = screenManager.getScreenBattle();
sm = screenManager.getScreenMap(); sm = screenManager.getScreenMap();
} }
public void render(GdxGraphics g){ public void render(GdxGraphics g){
sb.setEnemy(e);
sm.setPlayer(p); sm.setPlayer(p);
screenManager.render(g); screenManager.render(g);
} }