From 68019a1019407d5e41927c82bcf9f64599a1ec7b Mon Sep 17 00:00:00 2001 From: Louis MALTERRE <malterre.louis@laposte.net> Date: Tue, 6 Dec 2022 11:56:37 +0100 Subject: [PATCH] debut implementation de l attaque sur le perso LM --- MAVENProject/src/main/java/entity/Attack.java | 6 ++++++ MAVENProject/src/main/java/entity/Character.java | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/MAVENProject/src/main/java/entity/Attack.java b/MAVENProject/src/main/java/entity/Attack.java index ae31bdd..cb35f38 100644 --- a/MAVENProject/src/main/java/entity/Attack.java +++ b/MAVENProject/src/main/java/entity/Attack.java @@ -18,4 +18,10 @@ public class Attack { public void dealDamage(Entity entity){ entity.setNbLifePoints(Math.max(entity.getNbLifePoints()-damage, 0)); } + + public HitBox getHitBox() { + return hitBox; + } + + } diff --git a/MAVENProject/src/main/java/entity/Character.java b/MAVENProject/src/main/java/entity/Character.java index 38b0e86..64955ae 100644 --- a/MAVENProject/src/main/java/entity/Character.java +++ b/MAVENProject/src/main/java/entity/Character.java @@ -136,8 +136,10 @@ public class Character extends Entity{ @Override public void attaque(){ + Coordonnees attackCenter = new Coordonnees(coord.getX() + direction*entityWIDTH/2, coord.getZ()); + Attack characterAttack = new Attack(attackStat, attackCenter, new HitBox(attackCenter,entityHEIGHT,entityWIDTH)); for (Monster monster : Jeu.getMonsterList()){ - if (HitBox.collision(this.hitBox, monster.getHitBox()) && tableCommande.get("CommandAttack") == 1){ + if (HitBox.collision(characterAttack.getHitBox(), monster.getHitBox())){ //le Math.max est la juste pour que la vie du perso ne tombe pas en-dessous de zero monster.setNbLifePoints(Math.max(monster.getNbLifePoints()-attackStat,0)); } @@ -172,10 +174,10 @@ public class Character extends Entity{ public void evolveCharacter(){ getGameCommand(); deplacements(); - attaque(); collisionGestion(); updateVoisinage(); this.setHitBox(new HitBox(this.getCoord(),entityHEIGHT,entityWIDTH)); // mise à jour moins crade pour l'instant + if (tableCommande.get("CommandAttack") == 1) attaque(); resetCommand(); } -- GitLab