2022-06-01 16:47:53 +02:00
|
|
|
package Screen;
|
|
|
|
|
2022-06-08 09:53:51 +02:00
|
|
|
import com.badlogic.gdx.Gdx;
|
2022-06-08 23:30:15 +02:00
|
|
|
import com.badlogic.gdx.Input;
|
2022-06-08 09:53:51 +02:00
|
|
|
import com.badlogic.gdx.files.FileHandle;
|
|
|
|
import com.badlogic.gdx.graphics.Color;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
|
|
|
|
|
2022-06-08 23:30:15 +02:00
|
|
|
import Control.Controller;
|
|
|
|
import Entity.Enemy;
|
2022-06-10 19:33:24 +02:00
|
|
|
import Entity.Player;
|
2022-06-11 21:45:45 +02:00
|
|
|
import Game.Battle;
|
|
|
|
import Main.PokeMudry;
|
2022-06-10 19:33:24 +02:00
|
|
|
import Main.Settings;
|
2022-06-12 17:02:27 +02:00
|
|
|
import ch.hevs.gdx2d.components.screen_management.RenderingScreen;
|
|
|
|
import ch.hevs.gdx2d.lib.GdxGraphics;
|
2022-06-08 23:30:15 +02:00
|
|
|
|
2022-06-08 09:53:51 +02:00
|
|
|
public class ScreenBattle extends RenderingScreen{
|
|
|
|
|
2022-06-08 23:30:15 +02:00
|
|
|
private static int EDGE = 10;
|
|
|
|
private static int HEIGHT_DIALOG = Settings.SIDE / 3;
|
|
|
|
private static int WIDTH_DIALOG = Settings.SIDE - 2*EDGE;
|
|
|
|
|
|
|
|
|
2022-06-08 09:53:51 +02:00
|
|
|
private BitmapFont optimus40;
|
|
|
|
|
2022-06-12 16:33:04 +02:00
|
|
|
private Battle b = null;
|
2022-06-10 19:33:24 +02:00
|
|
|
|
2022-06-12 12:10:57 +02:00
|
|
|
private Enemy enemy;
|
2022-06-10 19:33:24 +02:00
|
|
|
|
|
|
|
|
2022-06-08 09:53:51 +02:00
|
|
|
@Override
|
|
|
|
public void onInit() {
|
|
|
|
//display the question
|
2022-06-10 19:33:24 +02:00
|
|
|
generateFont("resources/font/OptimusPrinceps.ttf", 40, Color.BLACK);
|
2022-06-08 09:53:51 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-11 21:45:45 +02:00
|
|
|
|
2022-06-08 09:53:51 +02:00
|
|
|
@Override
|
|
|
|
public void onGraphicRender(GdxGraphics g) {
|
2022-06-08 23:30:15 +02:00
|
|
|
g.clear(Color.BLACK);
|
2022-06-08 09:53:51 +02:00
|
|
|
|
2022-06-10 19:33:24 +02:00
|
|
|
displayDialog(g);
|
|
|
|
|
2022-06-12 16:33:04 +02:00
|
|
|
//System.out.println("render: " + battle.getLineSpeech());
|
2022-06-08 09:53:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dispose() {
|
|
|
|
optimus40.dispose();
|
|
|
|
}
|
|
|
|
|
2022-06-12 16:33:04 +02:00
|
|
|
|
|
|
|
public void setBattle(Battle battle) {
|
|
|
|
this.b = battle;
|
|
|
|
}
|
|
|
|
|
2022-06-10 19:33:24 +02:00
|
|
|
public void generateFont(String file, int height, Color c ){
|
2022-06-12 16:33:04 +02:00
|
|
|
|
2022-06-10 19:33:24 +02:00
|
|
|
//Generate font with the file .ttf
|
2022-06-08 09:53:51 +02:00
|
|
|
FileHandle fileHandle = Gdx.files.internal(file);
|
|
|
|
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
|
|
|
|
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fileHandle);
|
|
|
|
parameter.size = generator.scaleForPixelHeight(height);
|
|
|
|
parameter.color = c;
|
|
|
|
optimus40 = generator.generateFont(parameter);
|
|
|
|
generator.dispose();
|
|
|
|
|
|
|
|
}
|
2022-06-08 23:30:15 +02:00
|
|
|
|
2022-06-10 19:33:24 +02:00
|
|
|
public void displayDialog(GdxGraphics g){
|
|
|
|
//dialog background
|
2022-06-11 21:45:45 +02:00
|
|
|
g.drawFilledRectangle(Settings.SIDE/2, HEIGHT_DIALOG/2 + EDGE, WIDTH_DIALOG, HEIGHT_DIALOG, 0);
|
2022-06-10 19:33:24 +02:00
|
|
|
|
|
|
|
//dialog
|
2022-06-12 16:33:04 +02:00
|
|
|
if(b != null) g.drawString(15, 245 ,b.getLine() , optimus40);
|
2022-06-12 12:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-06-10 19:33:24 +02:00
|
|
|
|
2022-06-12 12:10:57 +02:00
|
|
|
public void setEnemy(Enemy enemy){
|
|
|
|
this.enemy = enemy;
|
2022-06-10 19:33:24 +02:00
|
|
|
}
|
2022-06-10 18:49:02 +02:00
|
|
|
|
2022-06-08 23:30:15 +02:00
|
|
|
public void displayEnemy(Enemy e){
|
2022-06-11 19:18:10 +02:00
|
|
|
// TODO affficher l'enemi
|
2022-06-11 21:45:45 +02:00
|
|
|
}
|
2022-06-09 06:58:49 +02:00
|
|
|
|
2022-06-10 19:33:24 +02:00
|
|
|
public void displayPlayer(Player p){
|
2022-06-11 19:18:10 +02:00
|
|
|
//TODO afficher le joueur
|
2022-06-10 19:33:24 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 16:33:04 +02:00
|
|
|
public void manage(Controller c, Battle battle){
|
2022-06-11 21:45:45 +02:00
|
|
|
if(PokeMudry.front_montant){
|
2022-06-12 14:26:02 +02:00
|
|
|
System.out.println("manage: " + battle.getLineSpeech());
|
2022-06-12 12:10:57 +02:00
|
|
|
|
|
|
|
if( battle.getAttackOn() == false){
|
|
|
|
if (c.keyStatus.get(Input.Keys.SPACE)){
|
|
|
|
System.out.println("in");
|
|
|
|
battle.readNextLine();
|
2022-06-11 21:45:45 +02:00
|
|
|
}
|
2022-06-10 19:33:24 +02:00
|
|
|
}
|
2022-06-12 12:10:57 +02:00
|
|
|
|
|
|
|
if(battle.getAttackOn() == true){
|
|
|
|
if (c.keyStatus.get(Input.Keys.NUM_1)){
|
2022-06-13 20:53:09 +02:00
|
|
|
|
|
|
|
battle.checkAnswer(1);
|
2022-06-11 21:45:45 +02:00
|
|
|
}
|
2022-06-12 12:10:57 +02:00
|
|
|
else if (c.keyStatus.get(Input.Keys.NUM_2)){
|
2022-06-13 20:53:09 +02:00
|
|
|
|
|
|
|
battle.checkAnswer(2);
|
2022-06-11 21:45:45 +02:00
|
|
|
}
|
2022-06-12 12:10:57 +02:00
|
|
|
else if (c.keyStatus.get(Input.Keys.NUM_3)){
|
2022-06-13 20:53:09 +02:00
|
|
|
|
|
|
|
battle.checkAnswer(3);
|
2022-06-12 12:10:57 +02:00
|
|
|
}
|
|
|
|
else if (c.keyStatus.get(Input.Keys.NUM_4)){
|
2022-06-13 20:53:09 +02:00
|
|
|
|
|
|
|
battle.checkAnswer(4);
|
2022-06-12 12:10:57 +02:00
|
|
|
|
2022-06-11 21:45:45 +02:00
|
|
|
}
|
2022-06-10 19:33:24 +02:00
|
|
|
}
|
|
|
|
|
2022-06-11 21:45:45 +02:00
|
|
|
//mettre le front à false jusqu'à ce que le bouton soit relâché
|
|
|
|
PokeMudry.front_montant = false;
|
|
|
|
}
|
2022-06-13 20:53:09 +02:00
|
|
|
|
2022-06-08 09:53:51 +02:00
|
|
|
|
|
|
|
|
2022-06-12 12:10:57 +02:00
|
|
|
|
2022-06-01 16:47:53 +02:00
|
|
|
|
2022-06-11 21:45:45 +02:00
|
|
|
}
|
2022-06-01 16:47:53 +02:00
|
|
|
}
|