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

boss (dont sauts) et coeurs drops par monstres implementes LM

parent d223e676
No related branches found
No related tags found
No related merge requests found
......@@ -2,11 +2,134 @@ package entity;
import environnement.Coordonnees;
//import environnement.Physique;
import environnement.Physique;
import environnement.PositionCollision;
import static environnement.PositionCollision.*;
import map.Obstacle;
import static jeu.Jeu.getObstacleTable;
import java.util.HashMap;
import java.util.List;
public class Boss extends Monster{
private int impulsionSaut = 0;
public Boss(Coordonnees c, double vitesseMax,double width,double height,int atkStt,int nbLP){
super(c, vitesseMax, width, height, atkStt, nbLP);
}
public void deplacements(){
double delta = Math.pow(10, -3);
int nbRand = (int)(200*(Math.random()));//on cree une loi de bernouilli de parametre 1/200
if (nbRand == 0 && alpha == 1){ //une chance sur 5 de sauter et ne saute que si au sol (alpha == 1)
impulsionSaut = 700000;
}
//on se souvient de ses anciennes positions
oldCoord = coord;
//pour faire un deplacement cyclique
if ((coordInit.getX()-coord.getX() >= 500 && direction == -1) || coord.getX() <= obstacleBeneath.getHitbox().getExtremites().get("HautGauche").getX())direction = 1;
else if ((coordInit.getX()-coord.getX() <= -500 && direction == 1) || coord.getX() >= obstacleBeneath.getHitbox().getExtremites().get("HautDroite").getX())direction = -1;
//******************
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();
vitesseActuZ = vitesseActuZ + 8*(1-alpha)*Physique.g*delta;
if (impulsionSaut != 0){
newZ = newZ - impulsionSaut/2*delta*delta;
System.out.println(newZ-coord.getZ());
vitesseActuZ = vitesseActuZ - 8*impulsionSaut*delta;
}
setCoord(new Coordonnees(newX, newZ));
}
public void collisionGestion(){
List<Obstacle> listeObstaclesInVoisinage = getObstacleTable();
//stocke l'obstacle avec lequel il y a eu collision
HashMap<Obstacle,PositionCollision> collisionsPresentes = new HashMap<Obstacle,PositionCollision>();
//recupere les collisions
for (int i=0;i<listeObstaclesInVoisinage.size();i++) {
PositionCollision posCol = Obstacle.collision(this, listeObstaclesInVoisinage.get(i), i);
collisionsPresentes.put(listeObstaclesInVoisinage.get(i),posCol);
}
//on gere celles du bas
//on set alpha a 0 (on suppose qu'il est en l'air)
alpha = 0;
//on parcourt pour tester si il est sur un block
for (int i=0;i<collisionsPresentes.size();i++){
//si on trouve on sort de la boucle (pas besoin d'aller plus loin), on n'étudie qui si on ne donne pas de commande
if (impulsionSaut != 0){
System.out.println("coucou");
break;
}
if (collisionsPresentes.get(listeObstaclesInVoisinage.get(i)) == BAS){
this.vitesseActuZ = 0;
this.setCoord(new Coordonnees(this.getCoord().getX(), getObstacleTable().get(i).getHitbox().getExtremites().get("HautGauche").getZ()-entityHEIGHT/2));
alpha = 1;
break;
}
}
/*for (Obstacle obs : listeObstaclesInVoisinage){ //on cherche l'obstacle en-dessous du perso
if (obs.getHitbox().getExtremites().get("HautGauche").getZ() <= obstacleBeneath.getHitbox().getExtremites().get("HautGauche").getZ() && obs.getHitbox().getExtremites().get("HautGauche").getZ() >= hitBox.getExtremites().get("BasDroite").getZ()){
obstacleBeneath = obs;
}
}
if (collisionsPresentes.get(obstacleBeneath) == BAS && tableCommande.get("CommandAttack") == 0){
this.vitesseActuZ = 0;
this.setCoord(new Coordonnees(this.getCoord().getX(), obstacleBeneath.getHitbox().getExtremites().get("HautGauche").getZ()-entityHEIGHT/2-1));
alpha = 1;
onGround = true;
}*/
//}
//on gere les collisions laterales et celle du haut
for (int i=0;i<collisionsPresentes.size();i++){
if (collisionsPresentes.get(listeObstaclesInVoisinage.get(i)) == DROITE && this.direction == -1){
this.setCoord(new Coordonnees(listeObstaclesInVoisinage.get(i).getHitbox().getExtremites().get("HautDroite").getX()+entityWIDTH/2, this.getCoord().getZ()));
break;
}
else if (collisionsPresentes.get(listeObstaclesInVoisinage.get(i)) == GAUCHE && this.direction == 1){
this.setCoord(new Coordonnees(listeObstaclesInVoisinage.get(i).getHitbox().getExtremites().get("HautGauche").getX()-entityWIDTH/2, this.getCoord().getZ()));
break;
}
}
//on gere celles du haut
for (int i=0;i<collisionsPresentes.size();i++){
if (collisionsPresentes.get(listeObstaclesInVoisinage.get(i)) == HAUT){
this.vitesseActuZ = 0;
this.setCoord(new Coordonnees(this.getCoord().getX(), listeObstaclesInVoisinage.get(i).getHitbox().getExtremites().get("BasGauche").getZ()+entityHEIGHT/2+1));
break;
}
}
}
public void evolveMonster(){
super.evolveMonster();
impulsionSaut = 0;
}
}
package entity;
import environnement.Coordonnees;
import environnement.HitBox;
import jeu.Jeu;
import static jeu.Jeu.getGameCharacter;
import static jeu.Jeu.getHearthList;
import java.util.List;
public class Hearth {
private HitBox hitBox;
private Coordonnees coord;
private int width = 20;
private int height = 20;
public Hearth(Coordonnees coordinates){
coord = coordinates;
hitBox = new HitBox(coord, height, width);
}
private void heal(){
if (HitBox.collision(hitBox, getGameCharacter().getHitBox())){
getGameCharacter().setNbLifePoints(Math.min(getGameCharacter().getNbLifePoints()+1,getGameCharacter().getMaxLifePoints()));
getHearthList().remove(this);
}
}
public HitBox getHitBox() {
return hitBox;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public static void evolveHearths(){ //on fait heal tous les coeurs
int k = 0;
List<Hearth> testList = getHearthList(); //necessaire pour l evolution de la bouble while
while (k < getHearthList().size()) {
//on sauvegarde la liste des coeurs avant de faire heal (ou non) le coeur a l indice k
testList = getHearthList();
//on le fait heal (ou non)
getHearthList().get(k).heal();
//si il a heal, il a alors disparu de la liste, donc les tailles ne sont plus les memes, on ne fait donc rien
if (testList.size() == getHearthList().size());
//sinon, les tailles sont les memes, on passe donc au coeur suivant
k++;
}
}
}
......@@ -130,9 +130,17 @@ public class Monster extends Entity{
//updateVoisinage();
this.setHitBox(new HitBox(this.getCoord(),entityHEIGHT,entityWIDTH));
updateNbFrameInvincible();
if (death()) {
int nbRand = (int)(2*Math.random()); //on cree une loi de bernouilli de parametre 1/2
if (nbRand == 0)dropHearth();
}
}
private void dropHearth(){
Jeu.getHearthList().add(new Hearth(coord));
}
public static void evolveAllMonsters(List<Monster> liste){ // evolution de tous les monstres
if (!liste.isEmpty()){
for (Monster monster : liste)monster.evolveMonster();
......
......@@ -9,7 +9,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import entity.Boss;
import entity.Character;
import entity.Hearth;
import entity.Kunai;
import entity.Monster;
import entity.ShootingCharacter;
......@@ -58,6 +60,9 @@ public class Jeu implements Game{
private boolean characterAttacking = false; //boolean necessaire pour rendre l'animation d'attaque prioritaire
//liste des coeurs drop par les monstres
private static List<Hearth> hearthList = new ArrayList<>();
//le sol
public static Obstacle sol = new Obstacle(new HitBox(new Coordonnees(200,1064),1,1000000));
......@@ -139,6 +144,7 @@ public class Jeu implements Game{
//on genere la table des monstres
monsterList= levelManager.generateMonsterTable();
monsterList.add(new Boss(new Coordonnees(5000, -1500), 500, 50, 100, 3, 50));
//on remplit la map des frames
Map<String,Integer> tempMap = gameCharacterLoader.getPathTable();
......@@ -176,6 +182,8 @@ public class Jeu implements Game{
Monster.evolveAllMonsters(monsterList);
//kunais evoluent dans le jeu
Kunai.evolveAllKunais(kunaiList);
//coeurs healent
Hearth.evolveHearths();
//animation du perso dans le jeu (definir la bonne frame a cet instant)
animation(Attack, Right, Left);
......@@ -269,6 +277,10 @@ public class Jeu implements Game{
return levelManager;
}
public static List<Hearth> getHearthList() {
return hearthList;
}
}
\ No newline at end of file
package jeu;
import engine.GamePainter;
import entity.Hearth;
import entity.Kunai;
import entity.Monster;
import environnement.Coordonnees;
......@@ -49,7 +50,7 @@ public class Painter implements GamePainter{
drawKey(crayon);
drawMonsters(crayon);
drawKunais(crayon);
drawHearths(crayon);
drawCharacter(crayon,gameCharacterLoader.getImageCharacter());
}
......@@ -90,6 +91,17 @@ public class Painter implements GamePainter{
}
}
private void drawHearths(Graphics2D crayon){
for (Hearth hearth : getHearthList()){
HashMap<String, Coordonnees> extremites = hearth.getHitBox().getExtremites();
Coordonnees hd = extremites.get("HautDroite");
Coordonnees bd = extremites.get("BasDroite");
Coordonnees hg = extremites.get("HautGauche");
Coordonnees bg = extremites.get("BasGauche");
crayon.fillRect((int)hg.getX()-xCam, (int)hg.getZ()-zCam, hearth.getWidth(), hearth.getHeight());
}
}
private void drawObstacle(Graphics2D crayon, Obstacle obstacle){
HashMap<String, Coordonnees> extremites = obstacle.getHitbox().getExtremites();
Coordonnees hd = extremites.get("HautDroite");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment