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

collision update

parent f0e6aa11
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ public class Character extends Entity{ ...@@ -21,6 +21,7 @@ public class Character extends Entity{
private final double characterHEIGHT= 60; private final double characterHEIGHT= 60;
private Map<String,Double> tableCommande; //table des commandes du perso private Map<String,Double> tableCommande; //table des commandes du perso
//private BufferedImage sprite; //private BufferedImage sprite;
private Obstacle obstacleBeneath = null;
public Character(Coordonnees c, double vitesseMax, double m, double impSaut){ public Character(Coordonnees c, double vitesseMax, double m, double impSaut){
...@@ -44,7 +45,7 @@ public class Character extends Entity{ ...@@ -44,7 +45,7 @@ public class Character extends Entity{
newX = tableCommande.get("CommandX")*delta + this.getCoord().getX(); // frottements enleves (le perso finissait par freiner tout seul donc tant que y'a pas d'interet je les enleve, j'ai tjr les equations de cote) newX = tableCommande.get("CommandX")*delta + this.getCoord().getX(); // frottements enleves (le perso finissait par freiner tout seul donc tant que y'a pas d'interet je les enleve, j'ai tjr les equations de cote)
if ((tableCommande.get("CommandZ") == 0) && (this.getCoord().getZ() >= Jeu.getCoordSol().getZ()))newZ = Jeu.getCoordSol().getZ(); if ((tableCommande.get("CommandZ") == 0) && (this.getCoord().getZ() >= Jeu.getCoordSol().getZ()))newZ = obstacleBeneath.getHitbox().getExtremites().get("HautGauche").getZ();
else newZ = ((1-alpha)*Physique.g - tableCommande.get("CommandZ"))/2*delta*delta + vitesseActuZ*delta + this.getCoord().getZ(); else newZ = ((1-alpha)*Physique.g - tableCommande.get("CommandZ"))/2*delta*delta + vitesseActuZ*delta + this.getCoord().getZ();
//System.out.println("écart de hauteur: "+this.getCoord().getZ()); //System.out.println("écart de hauteur: "+this.getCoord().getZ());
...@@ -80,7 +81,7 @@ public class Character extends Entity{ ...@@ -80,7 +81,7 @@ public class Character extends Entity{
} }
public void checkIfOnGround(){ // faut modifier la condition pour la gestion de colisions avec le sol public void checkIfOnGround(){ // faut modifier la condition pour la gestion de colisions avec le sol
if (Obstacle.collisionBas(this, Jeu.getObstacleTable()))alpha = 0; if (!Obstacle.collisionBas(this, Jeu.getObstacleTable()))alpha = 0;
else alpha = 1; else alpha = 1;
} }
...@@ -131,5 +132,11 @@ public class Character extends Entity{ ...@@ -131,5 +132,11 @@ public class Character extends Entity{
public HitBox getHitBox() { public HitBox getHitBox() {
return hitBox; return hitBox;
} }
public Obstacle getObstacleBeneath() {
return obstacleBeneath;
}
public void setObstacleBeneath(Obstacle obstacleBeneath) {
this.obstacleBeneath = obstacleBeneath;
}
} }
...@@ -38,15 +38,15 @@ public class HitBox { ...@@ -38,15 +38,15 @@ public class HitBox {
} }
public static Boolean collisionDroite(HitBox A, HitBox B){ public static Boolean collisionDroite(HitBox A, HitBox B){
return !(A.extremites.get("HautGauche").getX() >= B.extremites.get("HautDroite").getX()); return !(A.extremites.get("HautGauche").getX() >= B.extremites.get("HautDroite").getX());// A est à droite de B
} }
public static Boolean collisionGauche(HitBox A, HitBox B){ public static Boolean collisionGauche(HitBox A, HitBox B){
return !(A.extremites.get("HautDroite").getX() <= B.extremites.get("HautGauche").getX()); return !(A.extremites.get("HautDroite").getX() <= B.extremites.get("HautGauche").getX());// A est à gauche de B
} }
public static Boolean collisionBas(HitBox A, HitBox B){ public static Boolean collisionBas(HitBox A, HitBox B){
return !(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){ public static Boolean collisionHaut(HitBox A, HitBox B){
return !(A.extremites.get("BasGauche").getZ() <= B.extremites.get("HautGauche").getZ()); return !(A.extremites.get("BasGauche").getZ() <= B.extremites.get("HautGauche").getZ());// A est au dessus de B
} }
} }
\ No newline at end of file
...@@ -96,7 +96,7 @@ public class Jeu implements Game{ ...@@ -96,7 +96,7 @@ public class Jeu implements Game{
gameCharacterLoader.setPathTable(tempMap); gameCharacterLoader.setPathTable(tempMap);
obstacleTable.add(sol); obstacleTable.add(sol);
obstacleTable.add(new Obstacle(new HitBox(new Coordonnees(300,550),100,120))); obstacleTable.add(new Obstacle(new HitBox(new Coordonnees(300,550),32,128)));
} }
......
...@@ -54,8 +54,8 @@ public class Painter implements GamePainter{ ...@@ -54,8 +54,8 @@ public class Painter implements GamePainter{
private void drawCharacter(Graphics2D crayon,Image imageCharac){ private void drawCharacter(Graphics2D crayon,Image imageCharac){
int x = (int) gameCharacter.getCoord().getX(); int x = (int) gameCharacter.getCoord().getX();
int y = (int) gameCharacter.getCoord().getZ(); int y = (int) gameCharacter.getCoord().getZ();
//crayon.fillRect(x-15,y-30, (int) gameCharacter.getEntityWIDTH(),(int) gameCharacter.getEntityHEIGHT()); crayon.fillRect(x-(int) gameCharacter.getEntityWIDTH()/2,y-(int) gameCharacter.getEntityHEIGHT()/2, (int) gameCharacter.getEntityWIDTH(),(int) gameCharacter.getEntityHEIGHT());
crayon.drawImage(imageCharac, x-(int) gameCharacter.getEntityWIDTH(), y- (int) gameCharacter.getEntityHEIGHT(), null, null); crayon.drawImage(imageCharac, x-(int) gameCharacter.getEntityWIDTH()/2, y- (int) gameCharacter.getEntityHEIGHT()/2, null, null);
} }
......
...@@ -4,6 +4,9 @@ import java.util.List; ...@@ -4,6 +4,9 @@ import java.util.List;
import entity.Character; import entity.Character;
import environnement.HitBox; import environnement.HitBox;
import jeu.Jeu;
public class Obstacle { public class Obstacle {
...@@ -18,8 +21,23 @@ public class Obstacle { ...@@ -18,8 +21,23 @@ public class Obstacle {
public static Boolean collisionBas(Character charac,List<Obstacle> list){ public static Boolean collisionBas(Character charac,List<Obstacle> list){
for (Obstacle obs : list){ for (Obstacle obs : list){
if (HitBox.collisionBas(obs.getHitbox(),charac.getHitBox()))return true; if (obs != Jeu.getSol()){
}
if (HitBox.collisionDroite(charac.getHitBox(),obs.getHitbox()) && HitBox.collisionGauche(charac.getHitBox(),obs.getHitbox()) && HitBox.collisionBas(obs.getHitbox(),charac.getHitBox())){
charac.setObstacleBeneath(obs);
return true;
}
}
else{
if (HitBox.collisionBas(obs.getHitbox(), charac.getHitBox())) {
charac.setObstacleBeneath(obs);
return true;
}
}
}//a revoir
return false; return false;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment