1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2025-03-15 07:14:31 +00:00
PokeHES/src/Screen/ScreenBattle.java

151 lines
3.2 KiB
Java
Raw Normal View History

2022-06-01 16:47:53 +02:00
package Screen;
2022-06-08 09:53:51 +02:00
import ch.hevs.gdx2d.components.screen_management.RenderingScreen;
import ch.hevs.gdx2d.lib.GdxGraphics;
2022-06-10 19:33:24 +02:00
2022-06-08 09:53:51 +02:00
import com.badlogic.gdx.Gdx;
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-10 19:33:24 +02:00
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.utils.Align;
2022-06-08 09:53:51 +02:00
import Control.Controller;
import Entity.Enemy;
2022-06-10 19:33:24 +02:00
import Entity.Player;
import Text.Line;
import Text.TextEnemy;
import Main.Settings;
2022-06-08 09:53:51 +02:00
public class ScreenBattle extends RenderingScreen{
private static int EDGE = 10;
private static int HEIGHT_DIALOG = Settings.SIDE / 3;
private static int WIDTH_DIALOG = Settings.SIDE - 2*EDGE;
2022-06-10 18:49:02 +02:00
private Enemy e;
private boolean attackOn;
2022-06-09 06:58:49 +02:00
private int numAttack =0;
2022-06-08 09:53:51 +02:00
private BitmapFont optimus40;
2022-06-10 19:33:24 +02:00
private TextEnemy textEnemy;
private int lineSpeech = 0;
private String lineDialog = "";
private int answer = 0;
2022-06-08 09:53:51 +02:00
@Override
public void onInit() {
2022-06-10 19:33:24 +02:00
textEnemy = new TextEnemy("enemi");
textEnemy.generateText();
2022-06-08 09:53:51 +02:00
//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-10 19:33:24 +02:00
//initialize the first line
readNextLine();
2022-06-08 09:53:51 +02:00
}
@Override
public void onGraphicRender(GdxGraphics g) {
g.clear(Color.BLACK);
2022-06-08 09:53:51 +02:00
2022-06-10 19:33:24 +02:00
displayDialog(g);
2022-06-08 09:53:51 +02:00
}
@Override
public void dispose() {
2022-06-10 19:33:24 +02:00
2022-06-08 09:53:51 +02:00
optimus40.dispose();
}
2022-06-10 19:33:24 +02:00
public void generateFont(String file, int height, Color c ){
//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-10 19:33:24 +02:00
public void displayDialog(GdxGraphics g){
//dialog background
g.drawFilledRectangle(Settings.SIDE/2, HEIGHT_DIALOG/2 + EDGE, 1600, HEIGHT_DIALOG, 0);
//dialog
g.drawString(15, 245 ,lineDialog , optimus40);
}
2022-06-10 18:49:02 +02:00
public void setEnemy(Enemy e) {
this.e = e;
}
public void displayEnemy(Enemy e){
2022-06-09 06:58:49 +02:00
// stock his speech
}
2022-06-09 06:58:49 +02:00
2022-06-10 19:33:24 +02:00
public void displayPlayer(Player p){
//TODO afficher le joueur
}
public void readNextLine(){
2022-06-10 19:33:24 +02:00
//display the speech and change line
lineDialog = textEnemy.lines.get(lineSpeech).line;
lineSpeech++;
}
public void manage(Controller c){
if (c.keyStatus.get(Input.Keys.SPACE)){
2022-06-10 19:33:24 +02:00
if(textEnemy.lines.get(lineSpeech).attackOn == false){
readNextLine();
}
}
if (c.keyStatus.get(Input.Keys.NUM_1)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){
readNextLine();
answer = 1;
}
}
if (c.keyStatus.get(Input.Keys.NUM_2)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){
readNextLine();
answer = 2;
}
}
2022-06-10 19:33:24 +02:00
if (c.keyStatus.get(Input.Keys.NUM_3)){
if(textEnemy.lines.get(lineSpeech).attackOn == true){
readNextLine();
answer = 3;
}
}
if (c.keyStatus.get(Input.Keys.NUM_4)){
if(textEnemy.lines.get(lineSpeech).attackOn == false){
readNextLine();
answer = 4;
}
}
}
2022-06-08 09:53:51 +02:00
2022-06-01 16:47:53 +02:00
}