Skip to content
Snippets Groups Projects
Commit 193b4269 authored by Azurlors's avatar Azurlors
Browse files

ça marche !! fait tester

parent 5a5cd438
No related branches found
No related tags found
No related merge requests found
......@@ -102,8 +102,11 @@ entity.Entity <|.. entity.Monster
class environment.Obstacle{
}
class environment.Hitbox{
- HashMap<String, Coordonnees> extremites
- int static defaultUnit
+ public {static} Boolean Collision()
}
class environment.Coordonnees{
- int x
......
......@@ -15,6 +15,7 @@ public class Character extends Entity{
private double vitesseActuZ = 0;
private final double impulsionSaut;
private double masse;
private HitBox hitBox;
private int alpha = 1; // gere les collisions avec le sol
private final double characterWIDTH = 30; // pour l'instant je les ai renommes, ca peut changer
private final double characterHEIGHT= 60;
......@@ -22,12 +23,12 @@ public class Character extends Entity{
//private BufferedImage sprite;
public Character(Coordonnees c,double vitesseMax,double m,double impSaut){
public Character(Coordonnees c, double vitesseMax, double m, double impSaut){
super(c,vitesseMax,null); // comme tous les entities ont une hitbox, j'ai factorise
this.masse = m;
this.impulsionSaut = impSaut;
this.hitBox = new HitBox(c,characterHEIGHT,characterWIDTH);
this.tableCommande = new HashMap<String,Double>();
this.tableCommande = new HashMap<>();
tableCommande.put("CommandX",(double)0);
tableCommande.put("CommandZ",(double)0);
//sprite = CharacterLoader.getImageCharacter();
......@@ -94,6 +95,7 @@ public class Character extends Entity{
checkIfOnGround();
deplacements();
resetCommand();
this.hitBox = new HitBox(this.getCoord(),characterHEIGHT,characterWIDTH); // mise à jour crade pour l'instant
}
public double getVitesseMax() {
......@@ -125,5 +127,9 @@ public class Character extends Entity{
public int getAlpha() {
return alpha;
}
public HitBox getHitBox() {
return hitBox;
}
}
......@@ -3,6 +3,7 @@ package environnement;
import java.util.HashMap;
public class HitBox {
//private final Coordonnees centre;
private HashMap<String, Coordonnees> extremites = new HashMap<String,Coordonnees>();
private static double defaultUnit = 10;
......@@ -25,17 +26,14 @@ public class HitBox {
return (int)defaultUnit;
}
public static Boolean Collision(HitBox A, HitBox B){ // lignes sautées pour raison de lisibilité
return A.extremites.get("HautDroite").getX() >= B.extremites.get("BasGauche").getX()
&& A.extremites.get("HautDroite").getZ() <= B.extremites.get("BasGauche").getZ()
||
A.extremites.get("BasDroite").getX() >= B.extremites.get("HautGauche").getX()
&& A.extremites.get("BasDroite").getZ() >= B.extremites.get("HautGauche").getZ()
||
A.extremites.get("HautGauche").getX() <= B.extremites.get("BasDroite").getX()
&& A.extremites.get("HautGauche").getZ() <= B.extremites.get("BasDroite").getZ()
||
A.extremites.get("BasGauche").getX() <= B.extremites.get("HautDroite").getX()
&& A.extremites.get("BasGauche").getZ() >= B.extremites.get("HautDroite").getZ();
public static Boolean collision(HitBox A, HitBox B){ // lignes sautées pour raison de lisibilité
return (!(A.extremites.get("HautGauche").getX() >= B.extremites.get("HautDroite").getX())) // A est au dessus de B
&& (!(A.extremites.get("HautDroite").getX() <= B.extremites.get("HautGauche").getX())) // A est à droite de B
&& (!(A.extremites.get("HautGauche").getZ() >= B.extremites.get("BasGauche").getZ())) // A est à gauche de B
&& (!(A.extremites.get("BasGauche").getZ() <= B.extremites.get("HautGauche").getZ())); // A est en dessous de B
}
public HashMap<String, Coordonnees> getExtremites() {
return extremites;
}
}
}
\ No newline at end of file
......@@ -3,4 +3,12 @@ package environnement;
public class Obstacle {
private HitBox hitbox;
public Obstacle(HitBox h){
this.hitbox = h;
}
public HitBox getHitbox() {
return hitbox;
}
}
......@@ -2,13 +2,15 @@ package jeu;
import engine.GamePainter;
import entity.Character;
import environnement.Coordonnees;
import environnement.HitBox;
import environnement.Obstacle;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import static environnement.HitBox.getDefaultUnit;
import static environnement.HitBox.collision;
import static jeu.Jeu.gameCharacter;
import static jeu.Jeu.gameCharacterLoader;
import static jeu.Jeu.getCoordSol;
......@@ -18,6 +20,8 @@ public class Painter implements GamePainter{
protected static final int WIDTH = 1000;
protected static final int HEIGHT = 1000;
private Obstacle test = new Obstacle(new HitBox(new Coordonnees(300,550),100,120));
public Painter() {
}
......@@ -28,10 +32,17 @@ public class Painter implements GamePainter{
crayon.setColor(Color.blue);
drawCharacter(crayon, gameCharacter,gameCharacterLoader.getImageCharacter());
drawSol(crayon);
crayon.setColor(Color.red);
if (!collision(gameCharacter.getHitBox(), test.getHitbox())){
crayon.setColor(Color.blue);
}
else {
crayon.setColor(Color.red);
}
drawObstacle(crayon,test);
//drawQuadrillage(crayon);
}
@Override
public int getWidth() {
return WIDTH;
......@@ -46,25 +57,24 @@ public class Painter implements GamePainter{
int x = (int) gameCharacter.getCoord().getX();
int y = (int) gameCharacter.getCoord().getZ();
//crayon.fillRect(x-15,y-30, (int) gameCharacter.getEntityWIDTH(),(int) gameCharacter.getEntityHEIGHT());
crayon.drawImage(imageCharac, x-30, y-60, null, null);
crayon.drawImage(imageCharac, x-(int) gameCharacter.getEntityWIDTH(), y- (int) gameCharacter.getEntityHEIGHT(), null, null);
}
private void drawObstacle(Graphics2D crayon, Obstacle obstacle){
HashMap<String, Coordonnees> extremites = obstacle.getHitbox().getExtremites();
Coordonnees hd = extremites.get("HautDroite");
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());
}
private void drawSol(Graphics2D crayon){
crayon.drawLine(0,(int) getCoordSol().getZ(),WIDTH,(int) getCoordSol().getZ());
}
private void drawQuadrillage(Graphics2D crayon){ //pour le test de la classe obstacle
int taille = getDefaultUnit();
for (int i=1;i<(double) HEIGHT/taille;i++) {
crayon.drawLine(0, i * taille, WIDTH, i * taille);
}
for (int j =0;j<(double) WIDTH/taille;j++) {
crayon.drawLine(j * taille, 0, j * taille,HEIGHT );
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment