Skip to content
Snippets Groups Projects
Commit cc99dbf2 authored by Louis MALTERRE's avatar Louis MALTERRE
Browse files

commit Lm

parent 8e276981
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,8 @@ public class GameEngineGraphical {
*/
private Game game;
public int i;
/**
* l'afficheur a utiliser pour le rendu
*/
......@@ -63,7 +65,11 @@ public class GameEngineGraphical {
// fait evoluer le game
this.game.evolve(a);
// affiche le game
this.gui.paint();
i +=1;
if ( i == 5){
i = 0;
this.gui.paint();
}
// met en attente
Thread.sleep(2);
}
......
......@@ -8,6 +8,7 @@ import environnement.HitBox;
import map.Obstacle;
import environnement.Physique;
import jeu.Jeu;
import jeu.Painter;
public class Character extends Entity{
......@@ -52,13 +53,26 @@ public class Character extends Entity{
newZ = ((1-alpha)*Physique.g - tableCommande.get("CommandZ"))/2*delta*delta + vitesseActuZ*delta + this.getCoord().getZ();
if (newZ+entityHEIGHT/2 >= obstacleBeneath.getHitbox().getExtremites().get("HautGauche").getZ()){
newZ = obstacleBeneath.getHitbox().getExtremites().get("HautGauche").getZ()-entityHEIGHT/2;
newZ = obstacleBeneath.getHitbox().getExtremites().get("HautGauche").getZ()-entityHEIGHT/2+1;
//alpha = 1;
}
//(tableCommande.get("CommandZ") == 0) this.getCoord().getZ()(tableCommande.get("CommandZ") == 0) &&
this.setCoord(new Coordonnees(newX, newZ)); // on set les nouvelles coordonnees
if (obstacleNextTo != null){
if (tableCommande.get("CommandX") > 0){
if (this.getCoord().getX()+entityWIDTH/2 < obstacleNextTo.getHitbox().getExtremites().get("HautGauche").getX()){
this.setCoord(new Coordonnees(obstacleNextTo.getHitbox().getExtremites().get("HautGauche").getX()-entityWIDTH/2, this.getCoord().getZ()));
}
}
else if (tableCommande.get("CommandX") < 0){
if (this.getCoord().getX()-entityWIDTH/2 > obstacleNextTo.getHitbox().getExtremites().get("HautDroite").getX()){
this.setCoord(new Coordonnees(obstacleNextTo.getHitbox().getExtremites().get("HautDroite").getX()+entityWIDTH/2, this.getCoord().getZ()));
}
}
}
//on actualise les vitesses
......@@ -110,23 +124,18 @@ public class Character extends Entity{
}
public void checkIfNextToWall(){
if ((Obstacle.collisionDroite(this, Jeu.getObstacleTable()) && tableCommande.get("CommandX") == -vitesseMax) || (Obstacle.collisionGauche(this, Jeu.getObstacleTable()) && tableCommande.get("CommandX") == vitesseMax)){
if (((HitBox.collisionDroite(this.getHitBox(), Painter.test.getHitbox()) && tableCommande.get("CommandX") == -vitesseMax)) || (HitBox.collisionGauche(this.getHitBox(), Painter.test.getHitbox()) && tableCommande.get("CommandX") == vitesseMax)){
beta = 0;
obstacleNextTo = Painter.test;
System.out.println("beta :");
System.out.println(beta);
}else {
beta = 1;
System.out.println("beta :");
System.out.println(beta);
obstacleNextTo = null;
}
if (obstacleNextTo != null){
if (tableCommande.get("CommandX") > 0){
if (this.getCoord().getX()+entityWIDTH/2 >= obstacleNextTo.getHitbox().getExtremites().get("HautGauche").getX()){
this.setCoord(new Coordonnees(obstacleNextTo.getHitbox().getExtremites().get("HautGauche").getX()-entityWIDTH/2, this.getCoord().getZ()));
}
}
else if (tableCommande.get("CommandX") < 0){
if (this.getCoord().getX()-entityWIDTH/2 <= obstacleNextTo.getHitbox().getExtremites().get("HautDroite").getX()){
this.setCoord(new Coordonnees(obstacleNextTo.getHitbox().getExtremites().get("HautDroite").getX()+entityWIDTH/2, this.getCoord().getZ()));
}
}
}
}
......@@ -138,12 +147,12 @@ public class Character extends Entity{
}
public void evolveCharacter(){
System.out.println(beta);
getGameCommand();
checkIfNextToWall();
checkIfOnGround();
//checkIfNextToWall();
deplacements();
checkIfNextToWall();
//checkIfNextToWall();
resetCommand();
this.setHitBox(new HitBox(this.getCoord(),entityHEIGHT,entityWIDTH)); // mise à jour moins crade pour l'instant
}
......
......@@ -63,7 +63,6 @@ public class HitBox {
return !(A.extremites.get("HautDroite").getX() < B.extremites.get("HautGauche").getX());// A est à gauche de B
}
public static Boolean collisionBas(HitBox A, HitBox B){
//System.out.println(A.extremites.get("HautGauche").getZ()+" "+B.extremites.get("BasGauche").getZ());
return !(A.extremites.get("HautGauche").getZ() > B.extremites.get("BasGauche").getZ());// A est en dessous de B
}
public static Boolean collisionHaut(HitBox A, HitBox B){
......
......@@ -19,7 +19,7 @@ public class Painter implements GamePainter{
protected static final int WIDTH = 1000;
protected static final int HEIGHT = 1000;
private Obstacle test = new Obstacle(new HitBox(new Coordonnees(300,550),32,128));
public static Obstacle test = new Obstacle(new HitBox(new Coordonnees(300,550),32,128));
public Painter() {
......@@ -80,7 +80,6 @@ public class Painter implements GamePainter{
ObstacleLoader loader = new ObstacleLoader(Jeu.getSol(),"Terre.png");
HitBox hitBox = loader.getObstacle().getHitbox();
int z = (int) hitBox.getCentre().getZ();
System.out.println(z);
for (int x = 0;x<3000;x+=128) {
crayon.drawImage(loader.getImageObstacle(),x,z ,null,null);
}
......@@ -104,4 +103,5 @@ public class Painter implements GamePainter{
int x = (int) hitBox.getCentre().getX();
crayon.drawImage(loader.getImageObstacle(), x - (int) hitBox.getWidth()/2,z - (int) hitBox.getHeight()/2,null,null);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment