1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2024-11-30 04:33:27 +00:00

Merge pull request #36 from Klagarge:time

finish to add time
This commit is contained in:
Rémi Heredero 2022-06-16 14:30:39 +02:00 committed by GitHub
commit ca902bb277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 30 additions and 38 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

View File

@ -1,23 +1,9 @@
package Control; package Control;
import com.badlogic.gdx.Input;
import Screen.ScreenPlayer; import Screen.ScreenPlayer;
public class Keyboard { public class Keyboard {
public void keyDown(int keycode, ScreenPlayer sp, Controller c) { 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); c.keyStatus.put(keycode, true);
} }
public void onKeyUp(int keycode, ScreenPlayer sp, Controller c) { public void onKeyUp(int keycode, ScreenPlayer sp, Controller c) {

View File

@ -1,10 +1,13 @@
package Entity; package Entity;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import Main.Settings;
public class Enemy extends Character{ public class Enemy extends Character{
private String branch; private String branch;
public int recoveredTime = Settings.RECOVERED;

View File

@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Vector2;
import Control.Controller; import Control.Controller;
import Main.PokeMudry; import Main.PokeMudry;
import Main.Settings;
import Screen.ScreenMap; import Screen.ScreenMap;
public class Player extends Character{ public class Player extends Character{
@ -77,6 +78,8 @@ public class Player extends Character{
if(onDoor){ if(onDoor){
long time = System.currentTimeMillis();
while (System.currentTimeMillis()-time < Settings.SWITCHMAPTIME) { }
String nMap = null; String nMap = null;
Integer x = null; Integer x = null;
Integer y = null; Integer y = null;

View File

@ -45,6 +45,7 @@ public class Battle {
} }
else if( getLineSpeech() == 5 || getLineSpeech() == 6){ else if( getLineSpeech() == 5 || getLineSpeech() == 6){
finish(); finish();
e.recoveredTime = 0;
} }
else if(0 < getLineSpeech() && getLineSpeech() < 4){ else if(0 < getLineSpeech() && getLineSpeech() < 4){
checkAnswer(answer); checkAnswer(answer);

View File

@ -1,12 +1,11 @@
package Main; package Main;
import java.util.Vector; import java.util.Vector;
import com.badlogic.gdx.Input;
import Control.Controller; import Control.Controller;
import Entity.Character.Direction;
import Entity.Enemy; import Entity.Enemy;
import Entity.Entity; import Entity.Entity;
import Entity.Character.Direction;
import Game.Battle; import Game.Battle;
import Screen.ScreenBattle; import Screen.ScreenBattle;
import Screen.ScreenMap; import Screen.ScreenMap;
@ -20,6 +19,8 @@ public class PokeMudry extends PortableApplication {
private Controller controller; private Controller controller;
private static Vector<Enemy> enemies = new Vector<>(); private static Vector<Enemy> enemies = new Vector<>();
private static Vector<Entity> entities = new Vector<>(); private static Vector<Entity> entities = new Vector<>();
private long beginTime;
private long lastMesure;
public static boolean front_montant = false; public static boolean front_montant = false;
@ -42,7 +43,7 @@ public class PokeMudry extends PortableApplication {
public void onInit() { public void onInit() {
sp.init(); sp.init();
controller.init(); controller.init();
// add player, create and add all enemies in entities // add player, create and add all enemies in entities
entities.add((Entity) sp.p); entities.add((Entity) sp.p);
enemies.add(new Enemy("Mudry", 5, 11, "lumberjack_sheet32", "21N304", 25, "informatique", Direction.DOWN)); enemies.add(new Enemy("Mudry", 5, 11, "lumberjack_sheet32", "21N304", 25, "informatique", Direction.DOWN));
@ -51,11 +52,13 @@ public class PokeMudry extends PortableApplication {
enemies.add(new Enemy("Bianchi", 1, 3, "lumberjack_sheet32", "23N308", 0, "electricite", Direction.RIGHT)); enemies.add(new Enemy("Bianchi", 1, 3, "lumberjack_sheet32", "23N308", 0, "electricite", Direction.RIGHT));
enemies.add(new Enemy("Nicollier", 4, 2, "lumberjack_sheet32", "21N308", 0, "mathematique", Direction.LEFT)); enemies.add(new Enemy("Nicollier", 4, 2, "lumberjack_sheet32", "21N308", 0, "mathematique", Direction.LEFT));
enemies.add(new Enemy("Ellert", 1, 4, "lumberjack_sheet32", "23N215", 0, "physique", Direction.RIGHT)); enemies.add(new Enemy("Ellert", 1, 4, "lumberjack_sheet32", "23N215", 0, "physique", Direction.RIGHT));
for (Enemy enemy : enemies) { entities.add(enemy); } for (Enemy enemy : enemies) { entities.add(enemy); }
//Init all entities //Init all entities
for (Entity entity : entities) { entity.init(); } for (Entity entity : entities) { entity.init(); }
beginTime = System.currentTimeMillis();
lastMesure = beginTime;
} }
@Override @Override
@ -63,6 +66,14 @@ public class PokeMudry extends PortableApplication {
g.clear(); g.clear();
boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class); boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class);
boolean onBattleScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenBattle.class); boolean onBattleScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenBattle.class);
long timeNow = System.currentTimeMillis();
if((timeNow-lastMesure) >= 1000){
lastMesure = timeNow;
for (Enemy enemy : enemies) { enemy.recoveredTime++; }
}
if((timeNow-beginTime)/1000 >= 60 * Settings.TIME) System.out.println("Game finished");
if(onMapScreen) sp.p.manageEntity(sp.sm, controller); if(onMapScreen) sp.p.manageEntity(sp.sm, controller);
@ -71,14 +82,16 @@ public class PokeMudry extends PortableApplication {
sp.e = sp.p.lastEnemy; sp.e = sp.p.lastEnemy;
int pv = sp.e.getPv(); int pv = sp.e.getPv();
boolean recovered = sp.e.recoveredTime>=Settings.RECOVERED;
if (pv>0) { if (pv>0 && recovered) {
sp.sb = sp.screenManager.getScreenBattle(); sp.sb = sp.screenManager.getScreenBattle();
sp.b = new Battle(sp.e); sp.b = new Battle(sp.e);
//set pv and xp to display //set pv and xp to display
sp.b.setXpPlayer(sp.p.getXp()); sp.b.setXpPlayer(sp.p.getXp());
g.zoom(1);
g.resetCamera(); g.resetCamera();
} else { } else {
sp.p.onEnemy = false; sp.p.onEnemy = false;
@ -114,17 +127,6 @@ public class PokeMudry extends PortableApplication {
public void onKeyDown(int keycode) { public void onKeyDown(int keycode) {
super.onKeyDown(keycode); super.onKeyDown(keycode);
front_montant = true; front_montant = true;
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;
}
controller.keyStatus.put(keycode, true); controller.keyStatus.put(keycode, true);
sp.screenManager.getActiveScreen().onKeyUp(keycode); sp.screenManager.getActiveScreen().onKeyUp(keycode);
} }

View File

@ -5,6 +5,8 @@ public class Settings {
public static final boolean ANDROID = false; public static final boolean ANDROID = false;
public static final int PLAYERS = 1; public static final int PLAYERS = 1;
public static final int TIME = 10; // number of minutes for kill all enemy public static final int TIME = 10; // number of minutes for kill all enemy
public static final int RECOVERED = 30; // number of seconds an enemy need for recovered
public static final int SWITCHMAPTIME = 250; // Number of milliseconds the player wait for switch map
public static final int SIDE = 800; public static final int SIDE = 800;

View File

@ -16,7 +16,6 @@ import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import Entity.Character.Direction;
import Entity.Character; import Entity.Character;
import Entity.Player; import Entity.Player;
import ch.hevs.gdx2d.components.screen_management.RenderingScreen; import ch.hevs.gdx2d.components.screen_management.RenderingScreen;
@ -30,7 +29,6 @@ public class ScreenMap extends RenderingScreen{
Map<String,TiledMap> tMap = new TreeMap<String,TiledMap>(); Map<String,TiledMap> tMap = new TreeMap<String,TiledMap>();
Map<String,TiledMapRenderer> tMapRenderer = new TreeMap<String,TiledMapRenderer>(); Map<String,TiledMapRenderer> tMapRenderer = new TreeMap<String,TiledMapRenderer>();
public String map; public String map;
public float zoom;
private int width; private int width;
public int tileWidth; public int tileWidth;
private int height; private int height;
@ -46,7 +44,6 @@ public class ScreenMap extends RenderingScreen{
@Override @Override
public void onInit() { public void onInit() {
// Set initial zoom // Set initial zoom
zoom = 1;
try { map = player.getMap(); } catch (Exception e) {} try { map = player.getMap(); } catch (Exception e) {}
@ -107,13 +104,11 @@ public class ScreenMap extends RenderingScreen{
// Render the tileMap // Render the tileMap
g.zoom(zoom); g.zoom(0.5f);
g.moveCamera((int)player.getPosition().x, (int)player.getPosition().y, width * tileWidth, height * tileHeight); g.moveCamera((int)player.getPosition().x, (int)player.getPosition().y, width * tileWidth, height * tileHeight);
tMapRenderer.get(map).setView(g.getCamera()); tMapRenderer.get(map).setView(g.getCamera());
tMapRenderer.get(map).render(); tMapRenderer.get(map).render();
g.drawFPS();
} }