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

sprites bat kunai et monster implementes LM

parent e07a13de
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ public class Bat extends Monster{
public Bat(Coordonnees c,int atkStt,int nbLP){
super(c, 1000, 20, 30, atkStt, nbLP);
coordInit = coord;
monsterType = "bat_fly";
}
public void deplacements(){
......
package entity;
import java.net.URL;
import java.util.List;
import environnement.Coordonnees;
......@@ -19,6 +20,7 @@ public class Kunai {
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;
private final String sprite;
public Kunai(int dir,int dmg,Coordonnees c){
coord = c;
......@@ -26,6 +28,17 @@ public class Kunai {
damage = dmg;
direction = dir;
hitBox = new HitBox(coord,height,width);
//cest la pour les sprites, remplacer Jeu.class par classedanslaquelletues.class
String fn = "Frames_perso";
URL url = Monster.class.getClassLoader().getResource(fn);
assert url != null;
String beginPath = url.toString().substring(6)+"/";
String d;
if (direction == 1)d = "_R1";
else d = "_L1";
sprite = beginPath + "character_kunai" + d + ".png";
//************************* */
}
private void deplacement(){ //deplacement du kunai
......@@ -91,6 +104,10 @@ public class Kunai {
public static int getWidth() {
return width;
}
public String getSprite() {
return sprite;
}
}
......@@ -11,6 +11,8 @@ import map.Obstacle;
import static jeu.Jeu.getGameCharacter;
import static jeu.Jeu.getObstacleTable;
import java.io.BufferedReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -24,12 +26,24 @@ public class Monster extends Entity{
Coordonnees coordInit; // coordonnees initiales
PositionCollision collisionOnSide = NONE;
int impulsionSaut = 0;
int nbBeforeFrameChange = 0;
int nbFrame = 1;
String monsterType = "zombie_run";
private String sprite;
final String beginPath;
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;
//cest la pour les sprites, remplacer Jeu.class par classedanslaquelletues.class
String fn = "Monstres";
URL url = Monster.class.getClassLoader().getResource(fn);
assert url != null;
beginPath = url.toString().substring(6)+"/";
//************************* */
}
public void deplacements(){
......@@ -115,6 +129,20 @@ public class Monster extends Entity{
}
}
private void updateSprite() {
if (nbBeforeFrameChange == 0){
String dir;
if (direction == 1)dir = "_R";
else dir = "_L";
nbFrame = nbFrame%2 + 1;
sprite = beginPath + monsterType + dir + nbFrame + ".png";
nbBeforeFrameChange = 100;
System.out.println(sprite);
}
else nbBeforeFrameChange--;
}
private void updateNbFrameInvincible(){
nbFramesInvincible = Math.max(0, nbFramesInvincible-1);
}
......@@ -130,6 +158,7 @@ public class Monster extends Entity{
//updateVoisinage();
this.setHitBox(new HitBox(this.getCoord(),entityHEIGHT,entityWIDTH));
updateNbFrameInvincible();
updateSprite();
if (death()) {
int nbRand = (int)(2*Math.random()); //on cree une loi de bernouilli de parametre 1/2
if (nbRand == 0)dropHearth();
......@@ -171,5 +200,10 @@ public class Monster extends Entity{
public Boolean death(){
return nbLifePoints == 0;
}
public String getSprite() {
return sprite;
}
}
package jeu;
import engine.GamePainter;
import entity.Bat;
import entity.Hearth;
import entity.Kunai;
import entity.Monster;
......@@ -196,7 +197,13 @@ public class Painter implements GamePainter{
//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());
//crayon.fillRect(x-(int)monster.getEntityWIDTH()/2 - xCam, z-(int)monster.getEntityHEIGHT()/2 - zCam, (int)monster.getEntityWIDTH(), (int)monster.getEntityHEIGHT());
if (monster instanceof Bat){
crayon.drawImage(new ImageIcon(monster.getSprite()).getImage(),x-(int)monster.getEntityWIDTH()/2 - xCam-7,z-(int)monster.getEntityHEIGHT()/2 - zCam-3, null);
}
else{
crayon.drawImage(new ImageIcon(monster.getSprite()).getImage(),x-(int)monster.getEntityWIDTH()/2 - xCam-25,z-(int)monster.getEntityHEIGHT()/2 - zCam-3, null);
}
}
}
......@@ -210,7 +217,8 @@ public class Painter implements GamePainter{
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());
//crayon.fillRect(x-Kunai.getWidth()/2 - xCam, z-Kunai.getHeight()/2 - zCam, Kunai.getWidth(), Kunai.getHeight());
crayon.drawImage(new ImageIcon(kunai.getSprite()).getImage(),x - xCam-20,z - zCam-10, null);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment