2022-06-08 23:30:15 +02:00
|
|
|
package Main;
|
|
|
|
|
2022-06-09 19:15:11 +02:00
|
|
|
import java.util.Vector;
|
2022-06-12 17:02:27 +02:00
|
|
|
|
2022-06-09 19:15:11 +02:00
|
|
|
import Control.Controller;
|
|
|
|
import Entity.Enemy;
|
|
|
|
import Entity.Entity;
|
2022-06-12 16:33:04 +02:00
|
|
|
import Game.Battle;
|
|
|
|
import Screen.ScreenBattle;
|
2022-06-16 19:14:46 +02:00
|
|
|
import Screen.ScreenEnd;
|
2022-06-10 18:49:02 +02:00
|
|
|
import Screen.ScreenMap;
|
2022-06-08 23:30:15 +02:00
|
|
|
import Screen.ScreenPlayer;
|
|
|
|
import ch.hevs.gdx2d.desktop.PortableApplication;
|
|
|
|
import ch.hevs.gdx2d.lib.GdxGraphics;
|
|
|
|
|
2022-06-17 10:17:50 +02:00
|
|
|
public class PokeHES extends PortableApplication {
|
2022-06-09 19:15:11 +02:00
|
|
|
|
|
|
|
private ScreenPlayer sp;
|
|
|
|
private Controller controller;
|
|
|
|
private static Vector<Enemy> enemies = new Vector<>();
|
|
|
|
private static Vector<Entity> entities = new Vector<>();
|
2022-06-16 14:24:20 +02:00
|
|
|
private long beginTime;
|
|
|
|
private long lastMesure;
|
2022-06-09 19:15:11 +02:00
|
|
|
|
2022-06-16 23:29:36 +02:00
|
|
|
public static boolean risingFront = false;
|
2022-06-11 21:45:45 +02:00
|
|
|
|
2022-06-08 23:30:15 +02:00
|
|
|
|
|
|
|
public static void main(String[] args) {
|
2022-06-17 10:17:50 +02:00
|
|
|
new PokeHES();
|
2022-06-08 23:30:15 +02:00
|
|
|
}
|
|
|
|
|
2022-06-17 10:17:50 +02:00
|
|
|
PokeHES(){
|
2022-06-08 23:30:15 +02:00
|
|
|
super(Settings.SIDE, Settings.SIDE);
|
2022-06-09 19:15:11 +02:00
|
|
|
controller = new Controller();
|
|
|
|
sp = new ScreenPlayer();
|
2022-06-08 23:30:15 +02:00
|
|
|
}
|
2022-06-09 19:15:11 +02:00
|
|
|
|
|
|
|
public static Vector<Enemy> getEnemies() {
|
|
|
|
return enemies;
|
|
|
|
}
|
2022-06-08 23:30:15 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInit() {
|
2022-06-17 13:26:53 +02:00
|
|
|
setTitle("PokeHES");
|
|
|
|
|
2022-06-09 19:15:11 +02:00
|
|
|
sp.init();
|
|
|
|
controller.init();
|
2022-06-16 14:24:20 +02:00
|
|
|
|
2022-06-12 12:35:08 +02:00
|
|
|
// add player, create and add all enemies in entities
|
2022-06-09 19:15:11 +02:00
|
|
|
entities.add((Entity) sp.p);
|
2022-06-17 07:37:07 +02:00
|
|
|
enemies.add(new Enemy("Gloeckner", 1, 7, "21N307", 600, "allemand"));
|
|
|
|
enemies.add(new Enemy("Nicollier", 4, 2, "21N308", 1600, "mathematique"));
|
|
|
|
enemies.add(new Enemy("Mudry", 5, 11, "21N304", 700, "informatique"));
|
|
|
|
enemies.add(new Enemy("Ellert", 1, 4, "23N215", 300, "physique"));
|
|
|
|
enemies.add(new Enemy("Bianchi", 1, 3, "23N308", 1200, "electricite"));
|
|
|
|
enemies.add(new Enemy("Paciotti", 5, 11, "21N205", 1200, "mecanique"));
|
2022-06-10 18:49:02 +02:00
|
|
|
for (Enemy enemy : enemies) { entities.add(enemy); }
|
2022-06-16 14:24:20 +02:00
|
|
|
|
2022-06-12 12:35:08 +02:00
|
|
|
//Init all entities
|
|
|
|
for (Entity entity : entities) { entity.init(); }
|
2022-06-16 14:24:20 +02:00
|
|
|
|
|
|
|
beginTime = System.currentTimeMillis();
|
|
|
|
lastMesure = beginTime;
|
2022-06-08 23:30:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onGraphicRender(GdxGraphics g) {
|
2022-06-09 19:15:11 +02:00
|
|
|
g.clear();
|
2022-06-17 13:26:53 +02:00
|
|
|
|
2022-06-12 12:35:08 +02:00
|
|
|
boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class);
|
2022-06-12 16:33:04 +02:00
|
|
|
boolean onBattleScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenBattle.class);
|
2022-06-16 19:14:46 +02:00
|
|
|
boolean onEndScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenEnd.class);
|
2022-06-16 14:24:20 +02:00
|
|
|
|
2022-06-16 16:09:30 +02:00
|
|
|
long timeNow = System.currentTimeMillis();
|
2022-06-17 09:21:07 +02:00
|
|
|
if((timeNow-lastMesure) >= 1000 && !onEndScreen){ // one second during the game
|
2022-06-16 14:24:20 +02:00
|
|
|
lastMesure = timeNow;
|
2022-06-16 16:59:02 +02:00
|
|
|
sp.p.removedPv(1);
|
2022-06-16 14:24:20 +02:00
|
|
|
for (Enemy enemy : enemies) { enemy.recoveredTime++; }
|
|
|
|
}
|
2022-06-12 12:35:08 +02:00
|
|
|
|
|
|
|
if(onMapScreen) sp.p.manageEntity(sp.sm, controller);
|
2022-06-10 18:49:02 +02:00
|
|
|
|
2022-06-17 13:26:53 +02:00
|
|
|
// Switch to battle
|
|
|
|
if (sp.p.onEnemy && onMapScreen){ // if player is onEnemy and on map screen
|
|
|
|
sp.e = sp.p.lastEnemy; // Get this enemy
|
|
|
|
|
|
|
|
int pv = sp.e.getPv(); // get how many pv have the enemy
|
2022-06-16 14:24:20 +02:00
|
|
|
boolean recovered = sp.e.recoveredTime>=Settings.RECOVERED;
|
2022-06-17 13:26:53 +02:00
|
|
|
|
|
|
|
// if the enemy is alive and have recovered, switch to Battle
|
2022-06-16 14:24:20 +02:00
|
|
|
if (pv>0 && recovered) {
|
2022-06-15 16:49:33 +02:00
|
|
|
sp.b = new Battle(sp.e);
|
2022-06-16 15:46:34 +02:00
|
|
|
sp.sb = sp.screenManager.getScreenBattle();
|
2022-06-16 07:38:35 +02:00
|
|
|
|
|
|
|
//set pv and xp to display
|
|
|
|
sp.b.setXpPlayer(sp.p.getXp());
|
2022-06-17 13:26:53 +02:00
|
|
|
|
2022-06-16 14:24:20 +02:00
|
|
|
g.zoom(1);
|
2022-06-15 16:49:33 +02:00
|
|
|
g.resetCamera();
|
|
|
|
} else {
|
|
|
|
sp.p.onEnemy = false;
|
|
|
|
}
|
2022-06-16 07:38:35 +02:00
|
|
|
|
2022-06-10 18:49:02 +02:00
|
|
|
}
|
2022-06-12 16:33:04 +02:00
|
|
|
|
|
|
|
|
2022-06-17 13:26:53 +02:00
|
|
|
if(onBattleScreen) sp.sb.manage(controller, sp.b);
|
2022-06-15 09:53:54 +02:00
|
|
|
|
2022-06-17 13:26:53 +02:00
|
|
|
// switch to Map
|
2022-06-15 09:53:54 +02:00
|
|
|
if(!sp.b.getScreenBattleOn() && onBattleScreen){
|
|
|
|
//addXp for the player
|
2022-06-15 08:20:28 +02:00
|
|
|
sp.p.addXp(sp.b.getNewXp());
|
2022-06-15 09:53:54 +02:00
|
|
|
//remove pv of the enemy
|
2022-06-15 08:20:28 +02:00
|
|
|
sp.e.removedPv(sp.b.getNewXp());
|
2022-06-14 12:51:47 +02:00
|
|
|
|
2022-06-13 21:38:00 +02:00
|
|
|
sp.p.onEnemy = false;
|
|
|
|
sp.sm = sp.screenManager.getScreenMap();
|
|
|
|
}
|
|
|
|
|
2022-06-17 13:26:53 +02:00
|
|
|
// End of the game
|
|
|
|
if((sp.p.getPv() <= 0 || sp.p.getXp() >= sp.p.getXpMax() ) && !onEndScreen ) {
|
|
|
|
g.zoom(1);
|
|
|
|
g.resetCamera();
|
|
|
|
sp.se = sp.screenManager.getScreenEnd();
|
|
|
|
System.out.println("Game finished");
|
|
|
|
}
|
|
|
|
|
2022-06-12 16:33:04 +02:00
|
|
|
// 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);
|
|
|
|
}
|
2022-06-08 23:30:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//key gestion
|
|
|
|
@Override
|
|
|
|
public void onKeyDown(int keycode) {
|
|
|
|
super.onKeyDown(keycode);
|
2022-06-16 23:29:36 +02:00
|
|
|
risingFront = true;
|
2022-06-09 19:15:11 +02:00
|
|
|
controller.keyStatus.put(keycode, true);
|
|
|
|
sp.screenManager.getActiveScreen().onKeyUp(keycode);
|
2022-06-08 23:30:15 +02:00
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onKeyUp(int keycode) {
|
|
|
|
super.onKeyUp(keycode);
|
2022-06-16 23:29:36 +02:00
|
|
|
risingFront = false;
|
2022-06-09 19:15:11 +02:00
|
|
|
controller.keyStatus.put(keycode, false);
|
|
|
|
sp.screenManager.getActiveScreen().onKeyDown(keycode);
|
2022-06-08 23:30:15 +02:00
|
|
|
}
|
|
|
|
}
|