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

c'est pas fini :'(

parent 150a3e5f
No related branches found
No related tags found
No related merge requests found
package entity;
import java.util.HashMap;
import java.util.Map;
......@@ -7,8 +8,11 @@ import environnement.Coordonnees;
import environnement.HitBox;
import environnement.Physique;
import jeu.Jeu;
import static environnement.HitBox.collisionMap;
import static jeu.Painter.test;
import static environnement.HitBox.collisionObstacle;
import static jeu.Jeu.getObstacleTable;
import static jeu.Jeu.getObstacleTableCollisionCharac;
public class Character extends Entity{
......@@ -74,7 +78,8 @@ public class Character extends Entity{
}
public void collisionGestion(){
collisionMap (this.getHitBox(),test.getHitbox());
collisionObstacle(this.getHitBox(), getObstacleTable().get(2).getHitbox(),2);
System.out.println(collisionObstacle(this.getHitBox(), getObstacleTable().get(2).getHitbox(),2).toString());
}
@Override
public void attaque(){
......
package environnement;
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 {
......@@ -45,32 +50,6 @@ public class HitBox {
return (int)defaultUnit;
}
public static HashMap<String,Boolean> collisionMap(HitBox A, HitBox B){ // lignes sautées pour raison de lisibilité
HashMap<String,Boolean> map = new HashMap<>();
map.put("collision_gauche", false);
map.put("collision_droite", false);
map.put("collision_bas", false);
map.put("collision_haut", false);
boolean a = !(A.extremites.get("HautGauche").getX() > B.extremites.get("HautDroite").getX()); // A est à droite de B
boolean b = !(A.extremites.get("HautDroite").getX() < B.extremites.get("HautGauche").getX()); // A est à gauche de B
boolean c = !(A.extremites.get("HautGauche").getZ() > B.extremites.get("BasGauche").getZ()); // A est en dessous de B
boolean d = !(A.extremites.get("BasGauche").getZ() < B.extremites.get("HautGauche").getZ()); // A est au dessus de B
if (a && !d && !c){
map.put("collision_gauche", true);
}
else if (b && !d && !c) {
map.put("collision_droite", true);
}
else if (c && !a && !b) {
map.put("collision_bas", true );
}
else if (d && !a && !b) {
map.put("collision_haut", true);
}
System.out.println(map);
return map;
}
public static Boolean collision(HitBox A, HitBox B){
Boolean a = !(A.extremites.get("HautGauche").getX() > B.extremites.get("HautDroite").getX()); // A est à droite de B
Boolean b = !(A.extremites.get("HautDroite").getX() < B.extremites.get("HautGauche").getX()); // A est à gauche de B
......@@ -81,4 +60,53 @@ public class HitBox {
public HashMap<String, Coordonnees> getExtremites() {
return extremites;
}
public static PositionCollision collisionObstacle(HitBox A, HitBox B,int i) {
List<PositionCollision> L = getObstacleTableCollisionCharac();
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
boolean d = !(A.getExtremites().get("BasGauche").getZ() < B.getExtremites().get("HautGauche").getZ()); // A est au-dessus de B
int somme = 0;
if (a) {
somme++;
}
if (b) {
somme++;
}
if (c) {
somme++;
}
if (d) {
somme++;
}
if (somme == 3) {
if (!a) {
L.set(i, DROITE);
}
if (!b) {
L.set(i, GAUCHE);
}
if (!c) {
L.set(i, HAUT);
}
if (!d) {
L.set(i, BAS);
}
setObstacleTableCollisionCharac(L);
}
if (somme == 4) {
return L.get(i);
} else {
return NONE;
}
}
@Override
public String toString() {
return "Hitbox ";
}
}
\ No newline at end of file
package environnement;
public enum PositionCollision {
DROITE,GAUCHE,BAS,HAUT,NONE
}
......@@ -13,9 +13,12 @@ import entity.Character;
import engine.Game;
import environnement.Coordonnees;
import environnement.HitBox;
import environnement.PositionCollision;
import map.Obstacle;
import loaders.CharacterLoader;
import static environnement.PositionCollision.*;
public class Jeu implements Game{
......@@ -50,8 +53,9 @@ public class Jeu implements Game{
public static Obstacle sol = new Obstacle(new HitBox(new Coordonnees(200,700),1,1000000));
private static List<Obstacle> obstacleTable = new ArrayList<Obstacle>();
private static List<Obstacle> obstacleTable = new ArrayList<>();
private static List<PositionCollision> obstacleTableCollisionCharac= new ArrayList<>();
public Jeu(String source) {
......@@ -102,6 +106,11 @@ public class Jeu implements Game{
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)));
obstacleTableCollisionCharac.add(NONE);
obstacleTableCollisionCharac.add(NONE);
obstacleTableCollisionCharac.add(NONE);
obstacleTableCollisionCharac.add(NONE);
}
@Override
......@@ -145,6 +154,12 @@ public class Jeu implements Game{
public static List<Obstacle> getObstacleTable() {
return obstacleTable;
}
public static List<PositionCollision> getObstacleTableCollisionCharac() {
return obstacleTableCollisionCharac;
}
public static void setObstacleTableCollisionCharac(List<PositionCollision> obstacleTableCollisionCharac) {
Jeu.obstacleTableCollisionCharac = obstacleTableCollisionCharac;
}
private void animation(Boolean Attack,Boolean Right,Boolean Left){
if (Attack && !characterAttacking) {
......@@ -170,7 +185,7 @@ public class Jeu implements Game{
//System.out.println(numberOfMovement);
if (previousMovement != movement){numberOfMovement = 1;nbBeforeFramechgt = nbIterationPerFrame;}
if (numberOfMovement == gameCharacterLoader.getPathTable().get(movement)){
System.out.println(movement);
//System.out.println(movement);
//characterNotMoving = true;
if (movement == "character_attack"){
characterAttacking = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment