1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2024-11-26 19:13:27 +00:00

Merge pull request #13 from Klagarge/dialog-screen-battle

dialog ok
This commit is contained in:
Rémi Heredero 2022-06-10 19:41:37 +02:00 committed by GitHub
commit eb6e6dac79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 151 additions and 63 deletions

View File

@ -1,7 +1,7 @@
attaque,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,1 attaque1,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,1
df,sdfs,dfs,df,sdf,10 attaque2,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,10
sdf,sdf,sd,sdf,sdfs,3 attaque3,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,3
sdf,sdf,fsd,sdf,dfs,45 attaque4,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,45
sd,fsdf,fsd,f,dfsd,4 attaque5,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,4
sdfsf,df,sdf,sdf,fsdf,6 attaque6,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,6
sdf,sdf,sdf,sdfs,df,3 attaque7,contre-attaque 1,contre-attaque 2,contre-attaque 3,contre-attaque 4,3

1 attaque attaque1 contre-attaque 1 contre-attaque 2 contre-attaque 3 contre-attaque 4 1
2 df attaque2 sdfs contre-attaque 1 dfs contre-attaque 2 df contre-attaque 3 sdf contre-attaque 4 10
3 sdf attaque3 sdf contre-attaque 1 sd contre-attaque 2 sdf contre-attaque 3 sdfs contre-attaque 4 3
4 sdf attaque4 sdf contre-attaque 1 fsd contre-attaque 2 sdf contre-attaque 3 dfs contre-attaque 4 45
5 sd attaque5 fsdf contre-attaque 1 fsd contre-attaque 2 f contre-attaque 3 dfsd contre-attaque 4 4
6 sdfsf attaque6 df contre-attaque 1 sdf contre-attaque 2 sdf contre-attaque 3 fsdf contre-attaque 4 6
7 sdf attaque7 sdf contre-attaque 1 sdf contre-attaque 2 sdfs contre-attaque 3 df contre-attaque 4 3

View File

@ -1,7 +1,7 @@
introduction text introduction text
attack 1 attack 1 :
attack 2 attack 2 :
attack 3 attack 3 :
attack 4 attack 4 :
death death
win win

View File

@ -1,18 +1,16 @@
package Entity; package Entity;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import Text.TextEnemy;
public class Enemy extends Character{ public class Enemy extends Character{
public TextEnemy textEnemy;
public Enemy(String name, int x, int y, String img, String map) { public Enemy(String name, int x, int y, String img, String map) {
super(name, x, y, img, map); super(name, x, y, img, map);
//generate his text //generate his text
this.textEnemy = new TextEnemy("enemi"); //TODO should be name
textEnemy.generateText(); this.map = map;
turn(Character.Direction.DOWN); turn(Character.Direction.DOWN);
//generate the vector of fight //generate the vector of fight

12
src/Game/Battle.java Normal file
View File

@ -0,0 +1,12 @@
package Game;
public class Battle {
//TODO faire la logique du combat :$
/*
* les points
* réponses juste
* barre de vie
*/
}

View File

@ -1,9 +1,8 @@
package Screen; package Screen;
import Main.Settings;
import ch.hevs.gdx2d.components.screen_management.RenderingScreen; import ch.hevs.gdx2d.components.screen_management.RenderingScreen;
import ch.hevs.gdx2d.lib.GdxGraphics; import ch.hevs.gdx2d.lib.GdxGraphics;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
@ -11,9 +10,15 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.utils.Align;
import Control.Controller; import Control.Controller;
import Entity.Enemy; import Entity.Enemy;
import Entity.Player;
import Text.Line;
import Text.TextEnemy;
import Main.Settings;
public class ScreenBattle extends RenderingScreen{ public class ScreenBattle extends RenderingScreen{
@ -28,29 +33,47 @@ public class ScreenBattle extends RenderingScreen{
private BitmapFont optimus40; private BitmapFont optimus40;
private TextEnemy textEnemy;
private int lineSpeech = 0;
private String lineDialog = "";
private int answer = 0;
@Override @Override
public void onInit() { public void onInit() {
//display the question textEnemy = new TextEnemy("enemi");
generateFont("resources//font//OptimusPrinceps.ttf", optimus40, 20, Color.BLACK); textEnemy.generateText();
//display the question
generateFont("resources/font/OptimusPrinceps.ttf", 40, Color.BLACK);
//initialize the first line
readNextLine();
} }
@Override @Override
public void onGraphicRender(GdxGraphics g) { public void onGraphicRender(GdxGraphics g) {
g.clear(Color.BLACK); g.clear(Color.BLACK);
g.drawStringCentered(g.getScreenHeight()/2, "attack", optimus40);
g.drawFilledRectangle(Settings.SIDE/2, HEIGHT_DIALOG/2 + EDGE, WIDTH_DIALOG, HEIGHT_DIALOG, 0);
displayDialog(g);
} }
@Override @Override
public void dispose() { public void dispose() {
optimus40.dispose(); optimus40.dispose();
} }
public void generateFont(String file, BitmapFont bitmapFont, int height, Color c ){ public void generateFont(String file, int height, Color c ){
//Generate font with the file .ttf
FileHandle fileHandle = Gdx.files.internal(file); FileHandle fileHandle = Gdx.files.internal(file);
FreeTypeFontParameter parameter = new FreeTypeFontParameter(); FreeTypeFontParameter parameter = new FreeTypeFontParameter();
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fileHandle); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fileHandle);
@ -61,26 +84,69 @@ public class ScreenBattle extends RenderingScreen{
} }
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);
}
public void setEnemy(Enemy e) { public void setEnemy(Enemy e) {
this.e = e; this.e = e;
} }
public void displayEnemy(Enemy e){ public void displayEnemy(Enemy e){
// stock his speech // stock his speech
}
//display the person public void displayPlayer(Player p){
//TODO afficher le joueur
}
public void displayEnemy(Enemy e){
//TODO display the person
} }
public void readNextLine(){ public void readNextLine(){
//display the speech //display the speech and change line
lineDialog = textEnemy.lines.get(lineSpeech).line;
lineSpeech++;
} }
public void manage(Controller c){ public void manage(Controller c){
if (c.keyStatus.get(Input.Keys.SPACE)){ if (c.keyStatus.get(Input.Keys.SPACE)){
readNextLine(); 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;
}
}
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;
}
}
} }

View File

@ -11,16 +11,6 @@ public class FightData {
private File file; private File file;
private static final String REGEX = ","; private static final String REGEX = ",";
/*
public static void main(String[] args) {
FightData d = new FightData("enemi");
d.readFile();
for(Attack a : d.attacks){
System.out.println(a);
}
}
*/
public FightData(String name) { public FightData(String name) {
file = new File("./resources/Battle/Fight/" + name + ".csv"); file = new File("./resources/Battle/Fight/" + name + ".csv");
} }
@ -42,9 +32,12 @@ public class FightData {
bf.close(); bf.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

12
src/Text/Line.java Normal file
View File

@ -0,0 +1,12 @@
package Text;
public class Line {
public String line;
public boolean attackOn;
Line( String line, boolean attackOn){
this.line = line;
this.attackOn = attackOn;
}
}

View File

@ -12,7 +12,7 @@ public class SpeechData {
public SpeechData(String name){ public SpeechData(String name){
file = new File("./resources/Battle/Fight/" + name + ".csv"); file = new File("./resources/Battle/Speech/" + name + ".txt");
} }
public void readFile() { public void readFile() {

View File

@ -6,7 +6,16 @@ public class TextEnemy {
public FightData fightData; public FightData fightData;
public SpeechData speechData; public SpeechData speechData;
Vector<Line> line = new Vector<Line>(); public Vector<Line> lines = new Vector<Line>();
public static void main(String[] args) {
TextEnemy t = new TextEnemy("enemi");
t.generateText();
for(Line l : t.lines) {
System.out.println(l.line);
}
}
public TextEnemy(String name){ public TextEnemy(String name){
//generate the vector of fight //generate the vector of fight
@ -20,33 +29,24 @@ public class TextEnemy {
} }
public void generateText(){ public void generateText(){
int i =0; int i =1;
//introduction line //introduction line
line.add(new Line(speechData.getSpeechs(i++), false)); lines.add(new Line(speechData.getSpeechs(0), false));
for(int j=0; j<4;j++){
for(int j=0; i<4;i++){
//attack and answer (number on vector : 1-4) //attack and answer (number on vector : 1-4)
line.add(new Line( lines.add(new Line(
speechData.getSpeechs(i++) + fightData.getAttack(j).attack + "? ("+fightData.getAttack(j).xp+ ") " + "\n" + speechData.getSpeechs(i++) + fightData.getAttack(j).attack + "? ("+fightData.getAttack(j).xp+ ") " + "\n" +
fightData.getAttack(j).answer1 + "\n" + fightData.getAttack(j).answer1 + "\n" +
fightData.getAttack(j).answer2 + "\n" + fightData.getAttack(j).answer2 + "\n" +
fightData.getAttack(j).answer3 + "\n" + fightData.getAttack(j).answer3 + "\n" +
fightData.getAttack(j).answer4, true )); fightData.getAttack(j).answer4, true));
// TODO mélanger les attaques aléatoirement // TODO mélanger les attaques aléatoirement
} }
//finish (win and death) //finish (win and death)
line.add(new Line(speechData.getSpeechs(i++), false)); lines.add(new Line(speechData.getSpeechs(5), false));
line.add(new Line(speechData.getSpeechs(i++), false)); lines.add(new Line(speechData.getSpeechs(6), false));
} }
} }
class Line {
String line;
boolean attackOn;
Line( String line, boolean attackOn){
this.line = line;
this.attackOn = attackOn;
}
}

View File

@ -22,7 +22,7 @@ public class testYann extends PortableApplication{
} }
testYann(){ testYann(){
super(800, 800); super( 800, 800);
} }
@Override @Override
@ -36,6 +36,13 @@ public class testYann extends PortableApplication{
@Override @Override
public void onGraphicRender(GdxGraphics g) { public void onGraphicRender(GdxGraphics g) {
s.render(g); s.render(g);
((ScreenBattle) s.getActiveScreen()).manage(controller);
}
@Override
public void onDispose() {
// TODO Auto-generated method stub
super.onDispose();
} }
@Override @Override