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

attaque monstres implementee, gestion des vies faite, plan uml mis a jour (globalement) LM

parent 53e15f00
Branches
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ engine.DrawingPanel <|-- engine.GraphicalInterface
engine.GamePainter <|-- engine.DrawingPanel
environment.Coordonnees <|-- entity.Entity
entity.Character <|-- environment.Physique
entity.Monster <|-- environnement.Physique
loaders.CharacterLoader <|-- jeu.Jeu
jeu.Painter <|-- loaders.CharacterLoader
......@@ -67,10 +68,7 @@ class entity.Character {
- double masse
- double impulsionSaut
- HashMap tableCommand
- int alpha
- int nbLifePoints
- double entityWIDTH
- double entityHEIGHT
- double vitesseActuX
- double vitesseActuZ
+ void deplacements()
......@@ -79,33 +77,62 @@ class entity.Character {
+ void attaque()
+ void evolveCharacter()
+ void collisionsGestion()
+ int getNbLifePoints()
+ void setNbLifePoints(int)
+ int getAlpha()
+ List<Obstacles> obstacleInVoisinage()
+ void updateVoisinage()
+ Boolean death()
+ double getM()
+ double getVitesseActuX()
+ double getVitesseActuZ()
}
class entity.Monster{
- double vitesseActuZ
- Obstacle obstacleBeneath
+ List<Obstacle> obstacleInVoisinage()
+ void updateVoisinage()
+ Boolean death()
+ void deplacements()
+ void attaque()
+ void collisionsGestion()
+ static void evolveAllMonsters(List<Monster>)
+ void evolveMonster()
}
abstract class entity.Entity{
- HitBox hitBox
- HitBox voisinage
- double vitesseMax
- int nbFramesInvincible
- int nbMaxFramesInvincible
- int attackStat
- int direction
- List<PositionCollision> obstacleTableCollision
- Coordonnees coord
- Coordonnees oldCoord
- int alpha
- int nbLifePoints
- double entityWIDTH
- double entityHEIGHT
+ void deplacements()
+ Coordonnes getCoord()
+ Coordonnees getCoord()
+ Coordonnees getOldCoord()
+ void attaque()
+ int getDirection()
+ int getNbLifePoints()
+ int getNbFramesInvincible()
+ void setNbLifePoints(int)
+ int getAlpha()
}
entity.Entity <|.. entity.Character
entity.Entity <|.. entity.Monster
class entity.Attack(){
- int damage
- Coordonnees coordCentre
- HitBox hitBox
+ void dealDamage(Entity)
+ HitBox getHitBox()
}
class environment.Obstacle{
}
......
......@@ -16,7 +16,11 @@ public class Attack {
}
public void dealDamage(Entity entity){
entity.setNbLifePoints(Math.max(entity.getNbLifePoints()-damage, 0));
if (entity.nbFramesInvincible == 0){//n'attaque que si l'entity n'est pas invincible
//le Math.max est la juste pour que la vie du perso ne tombe pas en-dessous de zero
entity.setNbLifePoints(Math.max(entity.getNbLifePoints()-damage, 0));
entity.nbFramesInvincible = entity.nbMaxFramesInvicible;//l'entity devient invincible qq frames
}
}
public HitBox getHitBox() {
......
......@@ -35,7 +35,8 @@ public class Character extends Entity{
this.tableCommande = new HashMap<>();
tableCommande.put("CommandX",(double)0);
tableCommande.put("CommandZ",(double)0);
tableCommande.put("CommandAttack",(double)0); // 1 si attack, 0 sinon
tableCommande.put("CommandAttack",(double)0); // 1 si attack, 0 sinon
nbMaxFramesInvicible = 500;
}
@Override
......@@ -137,8 +138,8 @@ public class Character extends Entity{
Attack characterAttack = new Attack(attackStat, attackCenter, new HitBox(attackCenter,entityHEIGHT,entityWIDTH+20));
for (Monster monster : Jeu.getMonsterList()){
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));
//si collision, l'attaque fait ses dmg
characterAttack.dealDamage(monster);
}
}
}
......@@ -175,10 +176,15 @@ public class Character extends Entity{
updateVoisinage();
this.setHitBox(new HitBox(this.getCoord(),entityHEIGHT,entityWIDTH)); // mise à jour moins crade pour l'instant
if (tableCommande.get("CommandAttack") == 1) attaque();
updateNbFrameInvincible();
resetCommand();
}
private void updateNbFrameInvincible(){
nbFramesInvincible = Math.max(0, nbFramesInvincible-1);
}
public double getVitesseActuX() {
return vitesseActuX;
}
......
......@@ -26,6 +26,8 @@ public abstract class Entity {
HitBox voisinage;
int direction = 1; // direction selon l'axe des x, -1 pour la gauche et 1 pour la droite
List<PositionCollision> obstacleTableCollision = new ArrayList<>();
int nbFramesInvincible = 0;
int nbMaxFramesInvicible;
public Entity(Coordonnees c,double vitesseMax,double width,double height,int atkStt){
......@@ -41,6 +43,7 @@ public abstract class Entity {
for (int i = 0;i<getObstacleTable().size();i++){
obstacleTableCollision.add(NONE);
}
nbMaxFramesInvicible = 100;
}
public void deplacements(){}
......@@ -82,6 +85,8 @@ public abstract class Entity {
return nbLifePoints;
}
public void setNbLifePoints(int nbLifePoints) {
this.nbLifePoints = nbLifePoints;
}
......@@ -117,6 +122,9 @@ public abstract class Entity {
}
public HitBox getVoisinage() {
return voisinage;
}
public int getNbFramesInvincible() {
return nbFramesInvincible;
}
}
......@@ -86,18 +86,29 @@ public class Monster extends Entity{
public void attaque(){
if (HitBox.collision(this.hitBox, getGameCharacter().getHitBox())){
//le Math.max est la juste pour que la vie du perso ne tombe pas en-dessous de zero
getGameCharacter().setNbLifePoints(Math.max(getGameCharacter().getNbLifePoints()-attackStat,0));
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
//on cree l'attaque
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());
}
}
}
private void updateNbFrameInvincible(){
nbFramesInvincible = Math.max(0, nbFramesInvincible-1);
}
public void evolveMonster(){ //evolution du monstre
deplacements();
collisionGestion(); // ca merde
attaque();
updateVoisinage();
this.setHitBox(new HitBox(this.getCoord(),entityHEIGHT,entityWIDTH));
updateNbFrameInvincible();
}
......
......@@ -105,10 +105,10 @@ public class Jeu implements Game{
//coffreTable.add(new Coffre(new HitBox(new Coordonnees(900, 685),30,30))); //table des coffres
//on met des monstres, faut supp la pour table monstres
monsterList.add(new Monster(new Coordonnees(1000, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1000, 30, 60, 1,1));
monsterList.add(new Monster(new Coordonnees(500, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1000, 30, 60, 1,1));
monsterList.add(new Monster(new Coordonnees(100, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1000, 30, 60, 1,1));
monsterList.add(new Monster(new Coordonnees(300, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1000, 30, 60, 1,1));
monsterList.add(new Monster(new Coordonnees(1000, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1000, 30, 60, 1,5));
monsterList.add(new Monster(new Coordonnees(500, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1000, 30, 60, 1,5));
monsterList.add(new Monster(new Coordonnees(100, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1000, 30, 60, 1,5));
monsterList.add(new Monster(new Coordonnees(300, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1000, 30, 60, 1,5));
//on charge le perso (a la fin du constructeur, cest important par rapport a obstacleTable, sinon y'a des pbs de "causalite")
gameCharacterLoader = new CharacterLoader(characterSkinPath,new Character(new Coordonnees(300, 300), 1500, 1,600000));
......
......@@ -52,13 +52,14 @@ public class Painter implements GamePainter{
private void drawCharacter(Graphics2D crayon,Image imageCharac){
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.drawRect(WIDTH/2-500,WIDTH/2-500, 1000,1000);
if (gameCharacter.getDirection() == 1){
crayon.drawImage(imageCharac, WIDTH/2- (int) gameCharacter.getEntityWIDTH()/2-10, HEIGHT/2 - (int) gameCharacter.getEntityHEIGHT()/2-3, null, null);
}
else{
crayon.drawImage(imageCharac, WIDTH/2- (int) gameCharacter.getEntityWIDTH()/2-10-20, 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, null, null);
}
}
......@@ -163,6 +164,7 @@ public class Painter implements GamePainter{
z = (int)monster.getCoord().getZ();
crayon.drawRect(x-300 - xCam, z-300 - zCam, 600, 600);
if (HitBox.collision(gameCharacter.getHitBox(),monster.getHitBox()))crayon.setColor(Color.red);
if (monster.getNbFramesInvincible() > 0)crayon.setColor(Color.black);
crayon.fillRect(x-(int)monster.getEntityWIDTH()/2 - xCam, z-(int)monster.getEntityHEIGHT()/2 - zCam, (int)monster.getEntityWIDTH(), (int)monster.getEntityHEIGHT());
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment