Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • lacote18u-main-patch-07101
  • main
2 results

Target

Select target project
No results found
Select Git revision
  • lacote18u-main-patch-07101
  • main
2 results
Show changes
Commits on Source (49)
Showing
with 789 additions and 162 deletions
......@@ -12,11 +12,10 @@ Environnement :
Monstres :
• Monstres défendant les coffres
• Monstres se déplacent cycliquement
• Montres se déplacent vers le héros si celui-ci est dans sa ligne de mire
• Boss plus grand et plus fort que les autres montres
Attaques :
• Le Héros est tué après 3 attaques des monstres
• Les monstres sont tués après une attaque du héros sauf pour le boss
Interface :
• Possibilité de voir le nombre de vie restante après sur l’écran de jeu
• Attaques à distance et mêlée pour monstre et héros
• Attaques mêlée pour monstre et héros
-Avoir des collisions fonctionnelles
-Création des monstres
-Avoir des collisions fonctionnelles +
-Création des monstres +
-Création des coffres et des clés
-Création des vies
-Création de la caméra
-Création des vies +
-Création de la caméra +
-Création du niveau
-Implémenter une musique
-Implémenter une musique +
......
@startuml
@startuml PlanUML_CyberPac_2077
title Diagramme UML des Cyberpac 2077
......@@ -14,6 +14,10 @@ engine.DrawingPanel <|-- engine.GraphicalInterface
engine.GamePainter <|-- engine.DrawingPanel
environment.Coordonnees <|-- entity.Entity
entity.Character <|-- environment.Physique
entity.Monster <|-- environnement.Physique
entity.ShootingCharacter <|.. entity.Character
entity.Boss <|.. entity.Monster
entity.Bat <|.. entity.Monster
loaders.CharacterLoader <|-- jeu.Jeu
jeu.Painter <|-- loaders.CharacterLoader
......@@ -67,10 +71,6 @@ 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 +79,98 @@ 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()
}
class entity.ShootingCharacter(){
- int hasAttacked
+ void attaque()
+ void evolveCharacter()
}
class entity.Bat(){
- int directionZ
- double vitesseMaxZ
+ void deplacements()
+ void attaque()
}
class entity.Boss(){
}
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 entity.Kunai(){
- int direction
- int damage
- double vitesse
- HitBox hitBox
- Coordonnees coord
- boolean disappear
- static int height
- static int width
- void deplacements()
- void dealsDamage()
- void updateHitBox()
- void evolveKunai()
- static void evolveAllKunais(List<Kunai>)
+ public Coordonnees getcoord()
+ public HitBox getHitBox()
+ public int getWidth()
+ public int getHeight()
}
class environment.Obstacle{
}
......@@ -165,4 +230,9 @@ class environment.Physique{
- double g
}
class spotify.MP3{
- String file path
+ void displayMusic()
}
@enduml
\ No newline at end of file
......@@ -16,6 +16,18 @@
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<mainClass>start.Main</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<resources>
<resource>
<directory>src/main/resources</directory>
......
......@@ -9,7 +9,8 @@ import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import static jeu.Jeu.getGameCharacter;
import map.LevelManager;
public class DrawingPanel extends JPanel {
/**
......@@ -35,6 +36,7 @@ public class DrawingPanel extends JPanel {
/**
* la taille des images
*/
private LevelManager levelManager;
private int width, height;
/**
......@@ -89,8 +91,16 @@ public class DrawingPanel extends JPanel {
*/
public void paint(Graphics g) {
super.paint(g);
g.drawImage(this.currentImage, 0, 0, getWidth(), getHeight(), 0, 0,
getWidth(), getHeight(), null);
if (getGameCharacter().getCoord() != null){
//int x = (int) getGameCharacter().getCoord().getX();
//int z = (int) getGameCharacter().getCoord().getZ();
g.drawImage(this.currentImage, 0,0, getWidth(), getHeight(),0, 0, getWidth(), getHeight(), null);
}
else {
g.drawImage(this.currentImage, 0,0, getWidth(), getHeight()+100, 0, 0,
getWidth(), getHeight(), null);
System.out.println("test");
}
}
}
package entity;
import environnement.Coordonnees;
import environnement.HitBox;
public class Attack {
int damage;
Coordonnees coordCentre;
HitBox hitBox;
public Attack(int dmg,Coordonnees c,HitBox hb){
damage = dmg;
coordCentre = c;
hitBox = hb;
}
public void dealDamage(Entity entity){
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() {
return hitBox;
}
}
package entity;
import environnement.Coordonnees;
import environnement.HitBox;
import static jeu.Jeu.getGameCharacter;
public class Bat extends Monster{
private int directionZ = 1; //meme principe que direction pour x
private final double vitesseMaxZ = 1000;
public Bat(Coordonnees c,int atkStt,int nbLP){
super(c, 1000, 20, 30, atkStt, nbLP);
coordInit = coord;
}
public void deplacements(){
double delta = Math.pow(10, -3);
//oscillement selon z
if (coordInit.getZ()-coord.getZ() >= 50){
directionZ = 1;
}
else if (coordInit.getZ()-coord.getZ() <= -50){
directionZ = -1;
}
//oscillement selon x
if (coord.getX() < 0)direction = 1;
else if (coord.getX() >= 1000)direction = -1;
//actualisation des coordonnees
double newX = coord.getX() + direction*vitesseMax*delta;
double newZ = coord.getZ() + directionZ*vitesseMaxZ*delta;
coord = new Coordonnees(newX, newZ);
}
public void attaque(){
if (HitBox.collision(hitBox, getGameCharacter().getHitBox()) && getGameCharacter().nbFramesInvincible == 0){
getGameCharacter().setNbLifePoints(Math.max(getGameCharacter().getNbLifePoints()-attackStat, 0));
getGameCharacter().nbFramesInvincible = getGameCharacter().nbMaxFramesInvicible;
}
}
}
package entity;
import environnement.Coordonnees;
//import environnement.Physique;
public class Boss extends Monster{
public Boss(Coordonnees c, double vitesseMax,double width,double height,int atkStt,int nbLP){
super(c, vitesseMax, width, height, atkStt, nbLP);
}
}
......@@ -14,7 +14,7 @@ import environnement.PositionCollision;
import jeu.Jeu;
import map.Obstacle;
import static environnement.HitBox.collisionObstacle;
import static jeu.Jeu.getObstacleTable;
public class Character extends Entity{
......@@ -24,22 +24,21 @@ public class Character extends Entity{
private final double impulsionSaut;
private double masse;
private int clef;
private Map<String,Double> tableCommande; //table des commandes du perso
//private BufferedImage sprite;
private Obstacle obstacleBeneath = Jeu.sol;
//private BufferedImage sprite;
public Character(Coordonnees c, double vitesseMax, double m, double impSaut){
super(c,vitesseMax,30,60,1); // comme tous les entities ont une hitbox, j'ai factorise
this.masse = m;
this.impulsionSaut = impSaut;
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
......@@ -56,64 +55,79 @@ public class Character extends Entity{
newZ = ((1-alpha)*Physique.g - tableCommande.get("CommandZ"))/2*delta*delta + vitesseActuZ*delta + this.getCoord().getZ();
if (newZ+entityHEIGHT/2 >= Jeu.getSol().getHitbox().getExtremites().get("HautGauche").getZ()){
newZ = Jeu.getSol().getHitbox().getExtremites().get("HautGauche").getZ()-entityHEIGHT/2; //on remet sur le sol
alpha = 1;
}
this.setCoord(new Coordonnees(newX, newZ)); // on set les nouvelles coordonnees
//on actualise les vitesses
vitesseActuX = tableCommande.get("CommandX");
if (vitesseActuX != 0){
direction = (int) Math.signum(vitesseActuX);
}
vitesseActuZ = vitesseActuZ + 7*((1-alpha)*Physique.g - tableCommande.get("CommandZ"))*delta;
vitesseActuZ = vitesseActuZ + 8*((1-alpha)*Physique.g - tableCommande.get("CommandZ"))*delta;
}
public void collisionGestion(){
List<Obstacle> listeObstaclesInVoisinage = obstacleInVoisinage();
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++) {
collisionsPresentes.put(listeObstaclesInVoisinage.get(i),collisionObstacle(this.getHitBox(), listeObstaclesInVoisinage.get(i).getHitbox(), i));
PositionCollision posCol = Obstacle.collision(this, listeObstaclesInVoisinage.get(i), i);
collisionsPresentes.put(listeObstaclesInVoisinage.get(i),posCol);
}
//on set alpha a 0 (on suppose qu'il est en l'air)
alpha = 0;
if (this.hitBox.getExtremites().get("BasDroite").getZ()+entityHEIGHT/2-obstacleBeneath.getHitbox().getExtremites().get("HautDroite").getZ()>-1 && this.coord.getX()>=obstacleBeneath.getHitbox().getExtremites().get("BasGauche").getX() && this.coord.getX()<=obstacleBeneath.getHitbox().getExtremites().get("BasDroite").getX()) {
//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 (tableCommande.get("CommandZ") != 0){
break;
}
if (collisionsPresentes.get(getObstacleTable().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;
alpha = 1;
}
else {
obstacleBeneath=Jeu.sol;
//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 (tableCommande.get("CommandZ") != 0){
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-1));
obstacleBeneath=listeObstaclesInVoisinage.get(i);
alpha = 1;
break;
}
}
}
//on gere les collisions laterales et celle du haut
for (int i=0;i<collisionsPresentes.size();i++){
if (collisionsPresentes.get(getObstacleTable().get(i)) == DROITE && this.vitesseActuX < 0){
System.out.println("coucou");
this.setCoord(new Coordonnees(getObstacleTable().get(i).getHitbox().getExtremites().get("HautDroite").getX()+entityWIDTH/2, this.getCoord().getZ()));
if (collisionsPresentes.get(listeObstaclesInVoisinage.get(i)) == DROITE && this.vitesseActuX < 0){
this.setCoord(new Coordonnees(listeObstaclesInVoisinage.get(i).getHitbox().getExtremites().get("HautDroite").getX()+entityWIDTH/2+1, this.getCoord().getZ()));
break;
}
else if (collisionsPresentes.get(getObstacleTable().get(i)) == GAUCHE && this.vitesseActuX > 0){
this.setCoord(new Coordonnees(getObstacleTable().get(i).getHitbox().getExtremites().get("HautGauche").getX()-entityWIDTH/2, this.getCoord().getZ()));
else if (collisionsPresentes.get(listeObstaclesInVoisinage.get(i)) == GAUCHE && this.vitesseActuX > 0){
this.setCoord(new Coordonnees(listeObstaclesInVoisinage.get(i).getHitbox().getExtremites().get("HautGauche").getX()-entityWIDTH/2-1, this.getCoord().getZ()));
break;
}
else if (collisionsPresentes.get(getObstacleTable().get(i)) == 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(), getObstacleTable().get(i).getHitbox().getExtremites().get("BasGauche").getZ()+entityHEIGHT/2+1));
this.setCoord(new Coordonnees(this.getCoord().getX(), listeObstaclesInVoisinage.get(i).getHitbox().getExtremites().get("BasGauche").getZ()+entityHEIGHT/2+1));
break;
}
}
}
public List<Obstacle> obstacleInVoisinage(){
public List<Obstacle> obstacleInVoisinage(){ //recupere la liste des obstacles presents dans le voisinage
List<Obstacle> liste = new ArrayList<>();
for (Obstacle obs : getObstacleTable()){
if (HitBox.collision(voisinage, obs.getHitbox())){
......@@ -123,23 +137,19 @@ public class Character extends Entity{
return liste;
}
@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+20));
for (Monster monster : Jeu.getMonsterList()){
if (HitBox.collision(this.hitBox, monster.getHitBox()) && tableCommande.get("CommandAttack") == 1){
//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));
if (HitBox.collision(characterAttack.getHitBox(), monster.getHitBox())){
//si collision, l'attaque fait ses dmg
characterAttack.dealDamage(monster);
}
}
}
public void clef(){
for (Coffre coffre : Jeu.getCoffreTable()){
if (HitBox.collision(this.hitBox, coffre.getHitBox()){
monster.setNbLifePoints(Math.max(monster.getNbLifePoints()-attackStat,0));
}
}
}
public void getGameCommand(){
......@@ -153,7 +163,6 @@ public class Character extends Entity{
if ((alpha == 1) && (this.getVitesseActuZ() == 0)){
tableCommande.replace("CommandZ", impulsionSaut);
System.out.println(tableCommande.get("CommandZ"));
}
}
......@@ -169,14 +178,24 @@ public class Character extends Entity{
public void evolveCharacter(){
getGameCommand();
deplacements();
attaque();
collisionGestion();
updateVoisinage();
System.out.println(obstacleBeneath);
//updateVoisinage();
this.setHitBox(new HitBox(this.getCoord(),entityHEIGHT,entityWIDTH)); // mise à jour moins crade pour l'instant
if (tableCommande.get("CommandAttack") == 1) attaque();
updateNbFrameInvincible();
resetCommand();
}
public Obstacle getObstacleBeneath() {
return obstacleBeneath;
}
private void updateNbFrameInvincible(){
nbFramesInvincible = Math.max(0, nbFramesInvincible-1);
}
public double getVitesseActuX() {
return vitesseActuX;
}
......@@ -194,10 +213,16 @@ public class Character extends Entity{
}
public void updateVoisinage(){
voisinage = new HitBox(coord, 600, 600);
voisinage = new HitBox(coord, 1000, 1000);
}
public Boolean death(){
return false;
return nbLifePoints == 0;
}
public Map<String, Double> getTableCommande() {
return tableCommande;
}
}
package entity;
import java.util.ArrayList;
import java.util.List;
import environnement.Coordonnees;
import environnement.HitBox;
import environnement.PositionCollision;
import static jeu.Jeu.getObstacleTable;
import static environnement.PositionCollision.NONE;
import map.Obstacle;
public abstract class Entity {
protected Coordonnees coord;
protected Coordonnees oldCoord;
protected final double vitesseMax;
protected HitBox hitBox;
protected int attackStat; // nb de pv enleves par attaque
protected int maxLifePoints = 3;
protected int nbLifePoints = maxLifePoints;
protected final double entityWIDTH;
protected final double entityHEIGHT;
protected int alpha = 1; // gere les collisions avec le sol
protected HitBox voisinage;
Coordonnees coord;
Coordonnees oldCoord;
final double vitesseMax;
HitBox hitBox;
int attackStat; // nb de pv enleves par attaque
int maxLifePoints = 10;
int nbLifePoints = maxLifePoints;
final double entityWIDTH;
final double entityHEIGHT;
int alpha = 1; // gere les collisions avec le sol
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){
this.coord = c;
this.attackStat = atkStt;
this.oldCoord = this.coord;
......@@ -27,10 +40,24 @@ public abstract class Entity {
this.entityWIDTH = width;
this.hitBox = new HitBox(c, entityHEIGHT, entityWIDTH);
this.voisinage = new HitBox(c, 600, 600);
for (int i = 0;i<getObstacleTable().size();i++){
obstacleTableCollision.add(NONE);
}
nbMaxFramesInvicible = 100;
}
public void deplacements(){}
public void attaque(){}
public void updateVoisinage(){}
public void collisionGestion(){}
public List<Obstacle> obstacleInVoisinage(){return new ArrayList<Obstacle>();}
public Boolean death(){return false;}
public Coordonnees getCoord(){
return this.coord;
......@@ -60,6 +87,8 @@ public abstract class Entity {
return nbLifePoints;
}
public void setNbLifePoints(int nbLifePoints) {
this.nbLifePoints = nbLifePoints;
}
......@@ -84,9 +113,20 @@ public abstract class Entity {
return attackStat;
}
public void updateVoisinage(){
public List<PositionCollision> getObstacleTableCollision() {
return obstacleTableCollision;
}
public Boolean death(){return false;}
public int getDirection() {
return direction;
}
public HitBox getVoisinage() {
return voisinage;
}
public int getNbFramesInvincible() {
return nbFramesInvincible;
}
}
package entity;
import java.util.List;
import environnement.Coordonnees;
import environnement.HitBox;
import static jeu.Jeu.getMonsterList;
public class Kunai {
private final int direction; //1 si vers la droite, -1 si vers la gauche
private final int damage;
private final double vitesse = 5;
private HitBox hitBox;
private Coordonnees coord;
private final Coordonnees coordInit; //coordonnees initiales
private boolean disappear = false; //variable disant si le kunai doit disparaitre ou non
private static final int height = 12;
private static final int width = 24;
public Kunai(int dir,int dmg,Coordonnees c){
coord = c;
coordInit = coord;
damage = dmg;
direction = dir;
hitBox = new HitBox(coord,height,width);
}
private void deplacement(){ //deplacement du kunai
double newX = coord.getX() + direction*vitesse;
this.coord = new Coordonnees(newX, this.coord.getZ());
}
private void updateHitBox(){ //on update la hitbox du kunai
hitBox = new HitBox(coord,height,width);
}
private void dealsDamage(Entity entity){
if (HitBox.collision(hitBox, entity.getHitBox())){
if (entity.nbFramesInvincible == 0){
entity.setNbLifePoints(Math.max(entity.getNbLifePoints()-damage,0));
entity.nbFramesInvincible = entity.nbMaxFramesInvicible;//l'entity devient invincible qq frames
}
disappear = true; //disparait apres choc avec un monstre
}
}
private void evolveKunai(){
deplacement();
updateHitBox();
for (Monster monster : getMonsterList()){
dealsDamage(monster);
if (disappear)break; //si le kunai a disparu on arrete de regarder les autres monstres
}
if (Math.abs(coordInit.getX()-coord.getX()) >= 500) disappear = true; //au bout d'une certaine distance parcourue, il disparait
}
public static void evolveAllKunais(List<Kunai> liste){
for (Kunai kunai : liste){
kunai.evolveKunai();
}
int k = 0;
while (k < liste.size()){ //on supprime les kunais utilises
if (liste.get(k).disappear) liste.remove(liste.get(k));
else k++;
}
}
public Coordonnees getCoord() {
return coord;
}
public HitBox getHitBox() {
return hitBox;
}
public static int getHeight() {
return height;
}
public static int getWidth() {
return width;
}
}
......@@ -2,18 +2,33 @@ package entity;
import environnement.Coordonnees;
import environnement.HitBox;
import environnement.Physique;
import environnement.PositionCollision;
import static environnement.PositionCollision.*;
import jeu.Jeu;
import map.Obstacle;
import static jeu.Jeu.getGameCharacter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Monster extends Entity{
int direction = -1; // direction selon l'axe des x, -1 pour la gauche et 1 pour la droite
double vitesseActuZ = 0;
Obstacle obstacleBeneath = Jeu.getSol(); //obstacle en dessous
int isAttacking = 0;//pour qu'il s'arrete si il attaque
Coordonnees coordInit; // coordonnees initiales
PositionCollision collisionOnSide = NONE;
int impulsionSaut = 0;
public Monster(Coordonnees c, double vitesseMax,double width,double height,int atkStt,int nbLP) {
super(c, vitesseMax,width,height,atkStt);
maxLifePoints = nbLP;
nbLifePoints = maxLifePoints;
coordInit = coord;
}
public void deplacements(){
......@@ -22,26 +37,98 @@ public class Monster extends Entity{
//on se souvient de ses anciennes positions
oldCoord = coord;
//temporaire, pour faire un deplacement cyclique
if (coord.getX() < 0)direction = 1;
else if (coord.getX() >= 1000)direction = -1;
//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()+direction*vitesseMax*delta;
setCoord(new Coordonnees(newX, coord.getZ()));
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();
setCoord(new Coordonnees(newX, newZ));
vitesseActuZ = vitesseActuZ + 8*(1-alpha)*Physique.g*delta;
}
public void collisionGestion(){
//recupere la liste des obstacles dans le voisinage
List<Obstacle> listeObstaclesInVoisinage = obstacleInVoisinage();
//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++) {
collisionsPresentes.put(listeObstaclesInVoisinage.get(i),Obstacle.collision(this, listeObstaclesInVoisinage.get(i), i));
}
//on set alpha a 0 (on le suppose dans les airs)
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)
if (collisionsPresentes.get(listeObstaclesInVoisinage.get(i)) == BAS){
//si on a donné une impulsion, on regarde pas les collisions bas
this.vitesseActuZ = 0;
this.setCoord(new Coordonnees(this.getCoord().getX(), listeObstaclesInVoisinage.get(i).getHitbox().getExtremites().get("HautGauche").getZ()-entityHEIGHT/2));
alpha = 1;
obstacleBeneath = listeObstaclesInVoisinage.get(i);
break;
}
}
//on gere les collisions laterales
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()));
this.direction = 1;
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()));
this.direction = -1;
break;
}
}
}
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));
public void attaque(){//isAttacking > 0 pour dire que si il est entrain d'attaquer, il finit son attaque
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
//si il n'est pas immobile il s'arrete
if (isAttacking < 100){
isAttacking++;
}
//sinon on cree l'attaque
else{
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
}
}
}
private void updateNbFrameInvincible(){
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
deplacements();
collisionGestion(); // ca merde
attaque();
updateVoisinage();
this.setHitBox(new HitBox(this.getCoord(),entityHEIGHT,entityWIDTH));
updateNbFrameInvincible();
}
......@@ -49,6 +136,7 @@ public class Monster extends Entity{
if (!liste.isEmpty()){
for (Monster monster : liste)monster.evolveMonster();
}
//on supprime tous les monstres morts
int i = 0;
while (i < liste.size()){
if (liste.get(i).death())liste.remove(i);
......@@ -57,6 +145,20 @@ public class Monster extends Entity{
}
public List<Obstacle> obstacleInVoisinage(){ //recupere la liste des obstacles presents dans le voisinage
List<Obstacle> liste = new ArrayList<>();
for (Obstacle obs : Jeu.getObstacleTable()){
if (HitBox.collision(voisinage, obs.getHitbox())){
liste.add(obs);
}
}
return liste;
}
public void updateVoisinage(){
voisinage = new HitBox(coord, 1000, 1000);
}
public Boolean death(){
return nbLifePoints == 0;
}
......
package entity;
import java.util.List;
import environnement.Coordonnees;
import jeu.Jeu;
public class ShootingCharacter extends Character{
private int hasAttacked = 0; //varialbe disant si il a deja attaque, il ne peut attaque que toutes les deux frames, ainsi il ne peut attaquer que si = 0
public ShootingCharacter(Coordonnees c, double vitesseMax, double m, double impSaut){
super(c, vitesseMax, m, impSaut);
}
public void attaque(){
if (this.getTableCommande().get("CommandAttack") != 0 && hasAttacked == 0){ //on ajoute un kunai dans la liste
List<Kunai> temp = Jeu.getKunaiList();
Coordonnees coordKunai = new Coordonnees(coord.getX()+direction*Kunai.getWidth()/2+direction*this.getEntityWIDTH()/2, coord.getZ());
temp.add(new Kunai(direction, attackStat, coordKunai));
Jeu.setKunaiList(temp);
hasAttacked++;
}
}
public void evolveCharacter(){
super.evolveCharacter();
if (hasAttacked > 0){
hasAttacked++;
if (hasAttacked > 50)hasAttacked = 0;
}
}
}
......@@ -4,8 +4,7 @@ import java.util.HashMap;
import java.util.List;
import static environnement.PositionCollision.*;
import static jeu.Jeu.getObstacleTableCollisionCharac;
import static jeu.Jeu.setObstacleTableCollisionCharac;
public class HitBox {
......@@ -61,8 +60,8 @@ public class HitBox {
return extremites;
}
public static PositionCollision collisionObstacle(HitBox A, HitBox B,int i) {
List<PositionCollision> L = getObstacleTableCollisionCharac();
public static PositionCollision collisionObstacle(HitBox A, HitBox B,int i,List<PositionCollision> L) {
boolean a = !(A.getExtremites().get("HautGauche").getX() > B.getExtremites().get("HautDroite").getX()); // A est à droite de B
boolean b = !(A.getExtremites().get("HautDroite").getX() < B.getExtremites().get("HautGauche").getX()); // A est à gauche de B
boolean c = !(A.getExtremites().get("HautGauche").getZ() > B.getExtremites().get("BasGauche").getZ()); // A est en dessous de B
......@@ -95,7 +94,7 @@ public class HitBox {
if (!d) {
L.set(i, BAS);
}
setObstacleTableCollisionCharac(L);
}
if (somme == 4) {
......
......@@ -9,17 +9,19 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import entity.Bat;
import entity.Boss;
import entity.Character;
import entity.Kunai;
import entity.Monster;
import entity.ShootingCharacter;
import engine.Game;
import environnement.Coordonnees;
import environnement.HitBox;
import environnement.PositionCollision;
import loaders.ObstacleLoader;
import map.Obstacle;
import map.Coffre;
import loaders.CharacterLoader;
import static environnement.PositionCollision.*;
import map.LevelManager;
public class Jeu implements Game{
......@@ -27,6 +29,11 @@ public class Jeu implements Game{
//coordonnees du sol
//private static Coordonnees coordSol = new Coordonnees(200,700); //coordonnees du sol (en realite juste Z nous interesse)
//Coordonees de debut du personnage
static final double zdebut = 0;
static final double xdebut = 200;
//perso
static Character gameCharacter;
......@@ -53,14 +60,19 @@ public class Jeu implements Game{
private boolean characterAttacking = false; //boolean necessaire pour rendre l'animation d'attaque prioritaire
public static Obstacle sol = new Obstacle(new HitBox(new Coordonnees(200,700),1,1000000));
public static Obstacle sol = new Obstacle(new HitBox(new Coordonnees(200,700),56,1000000));
private static List<Obstacle> obstacleTable = new ArrayList<>();
private static List<PositionCollision> obstacleTableCollisionCharac= new ArrayList<>();
public static List<Obstacle> obstacleTable = new ArrayList<>();
private static List<Monster> monsterList = new ArrayList<>();
private static List<Coffre> coffreTable = new ArrayList<>();
private static List<Kunai> kunaiList = new ArrayList<>();
//private static List<Coffre> coffreTable = new ArrayList<>();
public final static int TILES_DEFAULT_SIZE=32;
public final static float SCALE=1.75f;
public final static int TILES_IN_WIDTH = 60;
public final static int TILES_IN_HEIGHT = 20;
public final static int TILES_SIZE = (int) (TILES_DEFAULT_SIZE*SCALE);
LevelManager levelManager;
public Jeu(String source) {
......@@ -75,8 +87,11 @@ public class Jeu implements Game{
characterSkinPath = beginPath + movement + numberOfMovement + ".png"; // path premiere frame
/*A = new ArrayList<Double>();
n = 0;*/
gameCharacterLoader = new CharacterLoader(characterSkinPath,new Character(new Coordonnees(300, 300), 2000, 1,600000));
gameCharacter = gameCharacterLoader.getGameCharacter();
LevelManager levelManager = new LevelManager();
try {
helpReader = new BufferedReader(new FileReader(source));
String line;
......@@ -95,6 +110,33 @@ public class Jeu implements Game{
directionJeu.put("Jump", false);
directionJeu.put("Attack",false);
//faut supp la pour table obstacles
obstacleTable= levelManager.generateObstacleTable();
obstacleTable.add(sol);
/*obstacleTable.add(new Obstacle(new HitBox(new Coordonnees(300,550),32,128)));
obstacleTable.add(new Obstacle(new HitBox(new Coordonnees(800, 625),150,50)));
obstacleTable.add(new Obstacle(new HitBox(new Coordonnees(600, 662.5),75,50)));
obstacleTable.add(new Obstacle(new HitBox(new Coordonnees(450, 400),32,128)));*/
//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,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(320, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1000, 30, 60, 1,5));
monsterList.add(new Bat(new Coordonnees(1500, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1, 3));
monsterList.add(new Boss(new Coordonnees(3000, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 500, 90, 180, 3, 50));
//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 ShootingCharacter(new Coordonnees(xdebut, zdebut), 1500, 1,600000));
gameCharacter = new ShootingCharacter(new Coordonnees(xdebut, zdebut), 1500, 1,600000);
//on remplit la map des frames
Map<String,Integer> tempMap = gameCharacterLoader.getPathTable();
......@@ -103,22 +145,12 @@ public class Jeu implements Game{
tempMap.put("character_attack",3);
tempMap.put("character_run", 4);
tempMap.put("character_jump",1);
tempMap.put("character_jump_L",1);
tempMap.put("character_run_L",4);
tempMap.put("character_attack_L",3);
tempMap.put("character_idle_L",4);
gameCharacterLoader.setPathTable(tempMap);
obstacleTable.add(sol);
obstacleTable.add(new Obstacle(new HitBox(new Coordonnees(300,550),32,128)));
obstacleTable.add(new Obstacle(new HitBox(new Coordonnees(800, 625),150,50)));
obstacleTable.add(new Obstacle(new HitBox(new Coordonnees(600, 662.5),75,50)));
coffreTable.add(new Coffre(new HitBox(new Coordonnees(900, 685),30,30)));
obstacleTableCollisionCharac.add(NONE);
obstacleTableCollisionCharac.add(NONE);
obstacleTableCollisionCharac.add(NONE);
obstacleTableCollisionCharac.add(NONE);
monsterList.add(new Monster(new Coordonnees(1000, sol.getHitbox().getExtremites().get("HautGauche").getZ()-30), 1000, 30, 60, 1,1));
}
@Override
......@@ -140,6 +172,8 @@ public class Jeu implements Game{
gameCharacter.evolveCharacter();
//monstres evoluent dans le jeu
Monster.evolveAllMonsters(monsterList);
//kunais evoluent dans le jeu
Kunai.evolveAllKunais(kunaiList);
//animation du perso dans le jeu (definir la bonne frame a cet instant)
animation(Attack, Right, Left);
......@@ -155,11 +189,13 @@ public class Jeu implements Game{
private void animation(Boolean Attack,Boolean Right,Boolean Left){
if (Attack && !characterAttacking) {
movement = "character_attack";
if (gameCharacter.getDirection() == -1)movement += "_L";
characterAttacking = true;
}
if (!characterAttacking){ //animation d'attaque prioritaire
if (gameCharacter.getAlpha() == 0) movement = "character_jump"; // pour savoir si il jump ou non
if ( gameCharacter.getAlpha()==0 || gameCharacter.getHitBox().getExtremites().get("BasDroite").getZ()+gameCharacter.getEntityHEIGHT()/2-gameCharacter.getObstacleBeneath().getHitbox().getExtremites().get("HautDroite").getZ()<-1) {
movement = "character_jump";} // pour savoir si il jump ou non
else{
if (Right && Left)movement = "character_idle";
else if (Right || Left){
......@@ -170,15 +206,18 @@ public class Jeu implements Game{
movement = "character_idle"; //ca changera quand j'aurai les nouvelles frames
}
}
if (gameCharacter.getDirection() == -1)movement += "_L";
}
//si on a change de mouvement, le jeu doit redemarrer a la premiere frame correspondante
//System.out.println(numberOfMovement);
if (previousMovement != movement){numberOfMovement = 1;nbBeforeFramechgt = nbIterationPerFrame;}
if ( !previousMovement.equals(movement)){numberOfMovement = 1;nbBeforeFramechgt = nbIterationPerFrame;}
if (numberOfMovement == gameCharacterLoader.getPathTable().get(movement)){
//System.out.println(movement);
//characterNotMoving = true;
if (movement == "character_attack"){
if (movement.equals("character_attack") || movement.equals("character_attack_L")){
characterAttacking = false;
}
}
......@@ -206,15 +245,10 @@ public class Jeu implements Game{
public static List<Obstacle> getObstacleTable() {
return obstacleTable;
}
public static List<Coffre> getCoffreTable() {
/*public static List<Coffre> getCoffreTable() {
return coffreTable;
}
public static List<PositionCollision> getObstacleTableCollisionCharac() {
return obstacleTableCollisionCharac;
}
public static void setObstacleTableCollisionCharac(List<PositionCollision> obstacleTableCollisionCharac) {
Jeu.obstacleTableCollisionCharac = obstacleTableCollisionCharac;
}
}*/
public static Character getGameCharacter() {
return gameCharacter;
}
......@@ -223,6 +257,14 @@ public class Jeu implements Game{
return monsterList;
}
public static List<Kunai> getKunaiList() {
return kunaiList;
}
public static void setKunaiList(List<Kunai> kunaiList) {
Jeu.kunaiList = kunaiList;
}
}
\ No newline at end of file
package jeu;
import engine.GamePainter;
import entity.Kunai;
import entity.Monster;
import environnement.Coordonnees;
import environnement.HitBox;
import loaders.ObstacleLoader;
import map.Obstacle;
import loaders.CoffreLoader;
import map.Coffre;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.HashMap;
......@@ -19,40 +17,58 @@ import java.net.URL;
import static environnement.HitBox.collision;
import static jeu.Jeu.*;
import map.LevelManager;
public class Painter implements GamePainter{
protected static final int WIDTH = 1000;
protected static final int HEIGHT = 1000;
//protected static final int WIDTH = TILES_SIZE*TILES_IN_WIDTH;
//protected static final int HEIGHT = TILES_SIZE*TILES_IN_HEIGHT;
protected static final int WIDTH =1500;
protected static final int HEIGHT=1000;
private LevelManager levelManager;
public static Obstacle test = new Obstacle(new HitBox(new Coordonnees(300,550),32,128));
private static Coordonnees coordonneesCam;
public int xCam;
public int zCam;
private int decalage = 225;
private Painter painter;
public Painter() {
}
@Override
public void draw(BufferedImage im) {
coordonneesCam = gameCharacter.getCoord();
xCam = -WIDTH/2 + (int) coordonneesCam.getX();
zCam = -HEIGHT/2 +(int) coordonneesCam.getZ()-decalage;
Graphics2D crayon = (Graphics2D) im.getGraphics();
crayon.setColor(Color.blue);
drawCharacter(crayon,gameCharacterLoader.getImageCharacter());
//drawQuadrillage(crayon);*/
drawMap(crayon);
drawSol(crayon);
drawObstacleBis(crayon,test,"plateforme.png");
//drawObstacleBis(crayon,test,"plateforme.png"); // A changer
drawLifePoints(crayon);
drawMonsters(crayon);
drawKunais(crayon);
drawCharacter(crayon,gameCharacterLoader.getImageCharacter());
}
private void drawCharacter(Graphics2D crayon,Image imageCharac){
int x = (int) gameCharacter.getCoord().getX();
int y = (int) gameCharacter.getCoord().getZ();
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()/2-10, y- (int) gameCharacter.getEntityHEIGHT()/2-3, null, null);
if (gameCharacter.getNbFramesInvincible() > 0)crayon.setColor(Color.black);
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);
if (gameCharacter.getDirection() == 1){
crayon.drawImage(imageCharac, WIDTH/2- (int) gameCharacter.getEntityWIDTH()/2-10, HEIGHT/2 - (int) gameCharacter.getEntityHEIGHT()/2-3+decalage, null, null);
}
else{
crayon.drawImage(imageCharac, WIDTH/2- (int) gameCharacter.getEntityWIDTH()/2-10-30, HEIGHT/2 - (int) gameCharacter.getEntityHEIGHT()/2-3+decalage, null, null);
}
}
private void drawLifePoints(Graphics2D crayon){
......@@ -79,13 +95,14 @@ public class Painter implements GamePainter{
Coordonnees bd = extremites.get("BasDroite");
Coordonnees hg = extremites.get("HautGauche");
Coordonnees bg = extremites.get("BasGauche");
crayon.drawLine((int)hd.getX(),(int)hd.getZ(),(int)bd.getX(),(int)bd.getZ());
crayon.drawLine((int)bd.getX(),(int)bd.getZ(),(int)bg.getX(),(int)bg.getZ());
crayon.drawLine((int)bg.getX(),(int)bg.getZ(),(int)hg.getX(),(int)hg.getZ());
crayon.drawLine((int)hg.getX(),(int)hg.getZ(),(int)hd.getX(),(int)hd.getZ());
if (HitBox.collision(gameCharacter.getVoisinage(), obstacle.getHitbox()))crayon.setColor(Color.green);
crayon.drawLine((int)hd.getX() - xCam,(int)hd.getZ() - zCam,(int)bd.getX() - xCam,(int)bd.getZ() - zCam);
crayon.drawLine((int)bd.getX() - xCam,(int)bd.getZ() - zCam,(int)bg.getX() - xCam,(int)bg.getZ() - zCam);
crayon.drawLine((int)bg.getX() - xCam,(int)bg.getZ() - zCam,(int)hg.getX() - xCam,(int)hg.getZ() - zCam);
crayon.drawLine((int)hg.getX() - xCam,(int)hg.getZ() - zCam,(int)hd.getX() - xCam,(int)hd.getZ() - zCam);
}
private void drawCoffre(Graphics2D crayon, Coffre coffre){
/*private void drawCoffre(Graphics2D crayon, Coffre coffre){
HashMap<String, Coordonnees> extremites = coffre.getHitbox().getExtremites();
Coordonnees hd = extremites.get("HautDroite");
Coordonnees bd = extremites.get("BasDroite");
......@@ -96,18 +113,19 @@ public class Painter implements GamePainter{
crayon.drawLine((int)bg.getX(),(int)bg.getZ(),(int)hg.getX(),(int)hg.getZ());
crayon.drawLine((int)hg.getX(),(int)hg.getZ(),(int)hd.getX(),(int)hd.getZ());
}
}*/
private void drawSol(Graphics2D crayon){
ObstacleLoader loader = new ObstacleLoader(Jeu.getSol(),"Terre.png");
HitBox hitBox = loader.getObstacle().getHitbox();
int z = (int) hitBox.getCentre().getZ();
for (int x = 0;x<3000;x+=128) {
crayon.drawImage(loader.getImageObstacle(),x,z ,null,null);
crayon.drawImage(loader.getImageObstacle(),x -xCam ,z - zCam,null,null);
}
}
private void drawMap(Graphics2D crayon){
System.out.println("Nombre obstacle :"+Jeu.getObstacleTable().size());
for (Obstacle obs : Jeu.getObstacleTable()){
if (!collision(gameCharacter.getHitBox(), obs.getHitbox())){
crayon.setColor(Color.blue);
......@@ -117,7 +135,7 @@ public class Painter implements GamePainter{
}
drawObstacle(crayon,obs);
}
for (Coffre obs : Jeu.getCoffreTable()){
/*for (Coffre obs : Jeu.getCoffreTable()){
if (!collision(gameCharacter.getHitBox(), obs.getHitbox())){
crayon.setColor(Color.blue);
}
......@@ -125,7 +143,7 @@ public class Painter implements GamePainter{
crayon.setColor(Color.red);
}
drawCoffre(crayon,obs);
}
}*/
}
private void drawObstacleBis(Graphics2D crayon, Obstacle obstacle, String nom){
......@@ -133,16 +151,16 @@ public class Painter implements GamePainter{
HitBox hitBox = loader.getObstacle().getHitbox();
int z = (int) hitBox.getCentre().getZ();
int x = (int) hitBox.getCentre().getX();
crayon.drawImage(loader.getImageObstacle(), x - (int) hitBox.getWidth()/2,z - (int) hitBox.getHeight()/2,null,null);
crayon.drawImage(loader.getImageObstacle(), x - (int) hitBox.getWidth()/2 -xCam,z - (int) hitBox.getHeight()/2 -zCam,null,null);
}
private void drawCoffreBis(Graphics2D crayon, Coffre coffre, String nom){
/*private void drawCoffreBis(Graphics2D crayon, Coffre coffre, String nom){
CoffreLoader loader = new CoffreLoader(coffre,nom);
HitBox hitBox = loader.getCoffre().getHitbox();
int z = (int) hitBox.getCentre().getZ();
int x = (int) hitBox.getCentre().getX();
crayon.drawImage(loader.getImageCoffre(), x - (int) hitBox.getWidth()/2,z - (int) hitBox.getHeight()/2,null,null);
}
}*/
private void drawMonsters(Graphics2D crayon){
int x;
......@@ -150,10 +168,27 @@ public class Painter implements GamePainter{
crayon.setColor(Color.blue);
for (Monster monster : getMonsterList()){
crayon.setColor(Color.blue);
x = (int)monster.getCoord().getX();
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);
crayon.fillRect(x-(int)monster.getEntityWIDTH()/2, z-(int)monster.getEntityHEIGHT()/2, (int)monster.getEntityWIDTH(), (int)monster.getEntityHEIGHT());
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());
}
}
private void drawKunais(Graphics2D crayon){
int x;
int z;
crayon.setColor(Color.blue);
for (Kunai kunai : getKunaiList()){
crayon.setColor(Color.blue);
x = (int)kunai.getCoord().getX();
z = (int)kunai.getCoord().getZ();
if (HitBox.collision(gameCharacter.getHitBox(),kunai.getHitBox()))crayon.setColor(Color.red);
crayon.fillRect(x-Kunai.getWidth()/2 - xCam, z-Kunai.getHeight()/2 - zCam, Kunai.getWidth(), Kunai.getHeight());
}
}
......
package loaders;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import jeu.Jeu;
public class LoadSave {
public static final String LEVEL_SPRITES = "Obstacles/Map_level_one.png";
public static final String LEVEL_ONE = "Obstacles/level_one2.png";
public static BufferedImage GetSpriteAtlas(String fileName) {
BufferedImage img = null;
InputStream is = LoadSave.class.getResourceAsStream("/" + fileName);
try {
img = ImageIO.read(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return img;
}
public static int[][] GetLevelData() {
int[][] lvlData = new int[Jeu.TILES_IN_HEIGHT][Jeu.TILES_IN_WIDTH];
BufferedImage img = GetSpriteAtlas(LEVEL_ONE);
for (int j = 0; j < img.getHeight(); j++)
for (int i = 0; i < img.getWidth(); i++) {
Color color = new Color(img.getRGB(i, j));
int value = color.getRed();
if (value >= 18)
value = 0;
lvlData[j][i] = value;
}
return lvlData;
}
}
package map;
import environnement.HitBox;
public class Coffre {
private HitBox hitbox;
public Coffre(HitBox h){
this.hitbox = h;
}
public HitBox getHitbox() {
return hitbox;
}
}
package map;
public class Level {
private int[][] lvlData;
public Level(int[][] lvlData) {
this.lvlData = lvlData;
}
public int getSpriteIndex(int x, int y) {
return lvlData[y][x];
}
public int[][] getLevelData() {
return lvlData;
}
}