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

monstres s'arrêtent désormais avant attaque, cam un peu sur-elevee

LM
parent 5fe05205
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ public class Monster extends Entity{ ...@@ -19,6 +19,7 @@ public class Monster extends Entity{
private double vitesseActuZ = 0; private double vitesseActuZ = 0;
private Obstacle obstacleBeneath = Jeu.getSol(); //obstacle en dessous private Obstacle obstacleBeneath = Jeu.getSol(); //obstacle en dessous
private int isAttacking = 0;//pour qu'il s'arrete si il attaque
public Monster(Coordonnees c, double vitesseMax,double width,double height,int atkStt,int nbLP) { public Monster(Coordonnees c, double vitesseMax,double width,double height,int atkStt,int nbLP) {
super(c, vitesseMax,width,height,atkStt); super(c, vitesseMax,width,height,atkStt);
...@@ -37,7 +38,8 @@ public class Monster extends Entity{ ...@@ -37,7 +38,8 @@ public class Monster extends Entity{
else if (coord.getX() >= 1000 || coord.getX() >= obstacleBeneath.getHitbox().getExtremites().get("HautDroite").getX())direction = -1; else if (coord.getX() >= 1000 || coord.getX() >= obstacleBeneath.getHitbox().getExtremites().get("HautDroite").getX())direction = -1;
//****************** //******************
double newX = coord.getX()+direction*vitesseMax*delta; double newX = coord.getX() + (1-Math.min(isAttacking,1))*direction*vitesseMax*delta;
double newZ = (1-alpha)*Physique.g/2*delta*delta + this.vitesseActuZ*delta + this.getCoord().getZ(); double newZ = (1-alpha)*Physique.g/2*delta*delta + this.vitesseActuZ*delta + this.getCoord().getZ();
setCoord(new Coordonnees(newX, newZ)); setCoord(new Coordonnees(newX, newZ));
vitesseActuZ = vitesseActuZ + 7*(1-alpha)*Physique.g*delta; vitesseActuZ = vitesseActuZ + 7*(1-alpha)*Physique.g*delta;
...@@ -85,15 +87,24 @@ public class Monster extends Entity{ ...@@ -85,15 +87,24 @@ public class Monster extends Entity{
} }
public void attaque(){ public void attaque(){//isAttacking > 0 pour dire que si il est entrain d'attaquer, il finit son attaque
if (direction*(this.coord.getX()-getGameCharacter().coord.getX()) <= 10 && Math.abs(this.coord.getZ()-getGameCharacter().coord.getZ()) <= entityHEIGHT){ //n'attaque que si perso pas invincible if ((Math.abs(this.coord.getX()-getGameCharacter().coord.getX()) <= 2+entityWIDTH/2+getGameCharacter().entityWIDTH/2 && Math.abs(this.coord.getZ()-getGameCharacter().coord.getZ()) <= entityHEIGHT && characInFrontOf()) || isAttacking > 0){ //n'attaque que si perso pas invincible
//on cree l'attaque //si il n'est pas immobile il s'arrete
Coordonnees coordAttack = new Coordonnees(this.coord.getX() + direction*entityWIDTH/2,this.coord.getZ()); if (isAttacking < 100){
Attack monsterAttack = new Attack(attackStat, coordAttack, new HitBox(coordAttack, entityHEIGHT, entityWIDTH+20)); isAttacking++;
//si il ya collision entre le perso et l'attaque }
if (HitBox.collision(monsterAttack.getHitBox(), getGameCharacter().hitBox)){ //sinon on cree l'attaque
//l'attaque fait ses degats else{
monsterAttack.dealDamage(getGameCharacter()); Coordonnees coordAttack = new Coordonnees(this.coord.getX() + direction*entityWIDTH/2,this.coord.getZ());
Attack monsterAttack = new Attack(attackStat, coordAttack, new HitBox(coordAttack, entityHEIGHT, entityWIDTH+20));
//si il ya collision entre le perso et l'attaque
if (HitBox.collision(monsterAttack.getHitBox(), getGameCharacter().hitBox)){
//l'attaque fait ses degats
monsterAttack.dealDamage(getGameCharacter());
}
isAttacking++;//il peut rebouger
if (isAttacking > 200)isAttacking = 0; //animation d'attaque finie
} }
} }
} }
...@@ -102,6 +113,10 @@ public class Monster extends Entity{ ...@@ -102,6 +113,10 @@ public class Monster extends Entity{
nbFramesInvincible = Math.max(0, nbFramesInvincible-1); nbFramesInvincible = Math.max(0, nbFramesInvincible-1);
} }
private Boolean characInFrontOf(){
return (direction == 1 && getGameCharacter().getCoord().getX() >= this.coord.getX()) || (direction == -1 && getGameCharacter().getCoord().getX() <= this.coord.getX());
}
public void evolveMonster(){ //evolution du monstre public void evolveMonster(){ //evolution du monstre
deplacements(); deplacements();
collisionGestion(); // ca merde collisionGestion(); // ca merde
......
...@@ -28,6 +28,7 @@ public class Painter implements GamePainter{ ...@@ -28,6 +28,7 @@ public class Painter implements GamePainter{
private static Coordonnees coordonneesCam; private static Coordonnees coordonneesCam;
private int xCam; private int xCam;
private int zCam; private int zCam;
private int decalage = 225;
public Painter() { public Painter() {
...@@ -37,7 +38,7 @@ public class Painter implements GamePainter{ ...@@ -37,7 +38,7 @@ public class Painter implements GamePainter{
public void draw(BufferedImage im) { public void draw(BufferedImage im) {
coordonneesCam = gameCharacter.getCoord(); coordonneesCam = gameCharacter.getCoord();
xCam = -WIDTH/2 + (int) coordonneesCam.getX(); xCam = -WIDTH/2 + (int) coordonneesCam.getX();
zCam = -HEIGHT/2 +(int) coordonneesCam.getZ(); zCam = -HEIGHT/2 +(int) coordonneesCam.getZ()-decalage;
Graphics2D crayon = (Graphics2D) im.getGraphics(); Graphics2D crayon = (Graphics2D) im.getGraphics();
crayon.setColor(Color.blue); crayon.setColor(Color.blue);
...@@ -53,13 +54,13 @@ public class Painter implements GamePainter{ ...@@ -53,13 +54,13 @@ public class Painter implements GamePainter{
private void drawCharacter(Graphics2D crayon,Image imageCharac){ private void drawCharacter(Graphics2D crayon,Image imageCharac){
if (gameCharacter.getNbFramesInvincible() > 0)crayon.setColor(Color.black); if (gameCharacter.getNbFramesInvincible() > 0)crayon.setColor(Color.black);
crayon.fillRect(WIDTH/2-(int) gameCharacter.getEntityWIDTH()/2,WIDTH/2-(int) gameCharacter.getEntityHEIGHT()/2, (int) gameCharacter.getEntityWIDTH(),(int) gameCharacter.getEntityHEIGHT()); crayon.fillRect(WIDTH/2-(int) gameCharacter.getEntityWIDTH()/2,HEIGHT/2-(int) gameCharacter.getEntityHEIGHT()/2+decalage, (int) gameCharacter.getEntityWIDTH(),(int) gameCharacter.getEntityHEIGHT());
crayon.drawRect(WIDTH/2-500,WIDTH/2-500, 1000,1000); crayon.drawRect(WIDTH/2-500,WIDTH/2-500, 1000,1000);
if (gameCharacter.getDirection() == 1){ if (gameCharacter.getDirection() == 1){
crayon.drawImage(imageCharac, WIDTH/2- (int) gameCharacter.getEntityWIDTH()/2-10, HEIGHT/2 - (int) gameCharacter.getEntityHEIGHT()/2-3, null, null); crayon.drawImage(imageCharac, WIDTH/2- (int) gameCharacter.getEntityWIDTH()/2-10, HEIGHT/2 - (int) gameCharacter.getEntityHEIGHT()/2-3+decalage, null, null);
} }
else{ else{
crayon.drawImage(imageCharac, WIDTH/2- (int) gameCharacter.getEntityWIDTH()/2-10-30, HEIGHT/2 - (int) gameCharacter.getEntityHEIGHT()/2-3, null, null); crayon.drawImage(imageCharac, WIDTH/2- (int) gameCharacter.getEntityWIDTH()/2-10-30, HEIGHT/2 - (int) gameCharacter.getEntityHEIGHT()/2-3+decalage, null, null);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment