From c65b006d767fb614b1b89642cf3cc95a9378d591 Mon Sep 17 00:00:00 2001
From: timeo <timeo.jacquier@hotmail.com>
Date: Wed, 8 Dec 2021 21:02:19 +0100
Subject: [PATCH] play connait le score actuel

---
 core/src/body/Joyau.java                    | 16 ++++++++++++++--
 core/src/etat/Play.java                     | 18 ++++++++++++++----
 core/src/handlers/ContactListenerPerso.java | 16 ++++++++++++++--
 3 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/core/src/body/Joyau.java b/core/src/body/Joyau.java
index aec93b6..a1864ca 100644
--- a/core/src/body/Joyau.java
+++ b/core/src/body/Joyau.java
@@ -12,8 +12,9 @@ import com.badlogic.gdx.physics.box2d.World;
 
 public class Joyau {
     CircleShape shapeStruct;
+    private int value;
 
-    public Joyau(float x, float y, World world){
+    public Joyau(float x, float y, World world, char value){
         BodyDef bodyDef = new BodyDef();
         bodyDef.type = BodyDef.BodyType.StaticBody;
         bodyDef.position.set(x, y);
@@ -29,8 +30,19 @@ public class Joyau {
 
         fixtureDefStruct.isSensor = true; //traversable
 
+        this.value = Character.getNumericValue(value);
 
-        structBody.createFixture(fixtureDefStruct).setUserData("joyau");
+        if (this.value == 1){
+            structBody.createFixture(fixtureDefStruct).setUserData("joyau1");
+        }
+
+        if (this.value == 2){
+            structBody.createFixture(fixtureDefStruct).setUserData("joyau2");
+        }
         shapeStruct.dispose();
     }
+
+    public int getValue() {
+        return value;
+    }
 }
\ No newline at end of file
diff --git a/core/src/etat/Play.java b/core/src/etat/Play.java
index 2c6ae6e..00331f5 100644
--- a/core/src/etat/Play.java
+++ b/core/src/etat/Play.java
@@ -34,6 +34,7 @@ public class Play extends GameState {
     private int hauteur;
     private int temps;
     private ContactListenerPerso cl;
+    private int score = 0;
 
     private Body player;
 
@@ -81,16 +82,18 @@ public class Play extends GameState {
         //dt => delta time
 
         handleInput();
-        /*TODO remettre à 1 quand j'aurai bien compris, on a pas besoin d'autant de précisions
-         */
         Array<Body> joyauToRemove = cl.getBodyToRemove();
         for (Body b : joyauToRemove){
             world.destroyBody(b);
+            score = cl.getScore();
+            System.out.println("score = " + score);
         }
         joyauToRemove.clear();
-        b2dCam.position.set(player.getPosition(), 0);
+        //b2dCam.position.set(player.getPosition(), 0);
         b2dCam.update();
 
+        /*TODO remettre à 1 quand j'aurai bien compris, on a pas besoin d'autant de précisions
+         */
         world.step(dt, 6, 2);
     }
 
@@ -144,7 +147,7 @@ public class Play extends GameState {
                         break;
                     case '1':
                     case '2':
-                        new Joyau((j*10)/PPM, ((hauteur-i) * 10)/PPM, world);
+                        new Joyau((j*10)/PPM, ((hauteur-i) * 10)/PPM, world, current);
                         break;
                     case 'Z':
                         new Panneau((j*10)/PPM, ((hauteur-i) * 10)/PPM, world);
@@ -178,6 +181,13 @@ public class Play extends GameState {
 
         foot.density = 0.5f;
         foot.restitution = 0.1f;
+        foot.friction = 0.25f;
+
+        body.restitution = 0.1f;
+        body.density = 0.5f;
+        body.friction = 0.25f;
+
+
 
         player.createFixture(foot).setUserData("foot");
     }
diff --git a/core/src/handlers/ContactListenerPerso.java b/core/src/handlers/ContactListenerPerso.java
index ec52003..7c45d3c 100644
--- a/core/src/handlers/ContactListenerPerso.java
+++ b/core/src/handlers/ContactListenerPerso.java
@@ -12,6 +12,7 @@ public class ContactListenerPerso implements ContactListener {
 
     private int numPlayerOnGround = 0;
     Array<Body> bodyToRemove = new Array<Body>();
+    private int score = 0;
 
     /**
      * Appeler quand 2 fixtures rentre en collision
@@ -26,10 +27,17 @@ public class ContactListenerPerso implements ContactListener {
             numPlayerOnGround++;
         }
 
-        if (fb.getUserData() != null && fb.getUserData().equals("joyau") && fa.getUserData() != null && fa.getBody().getUserData().equals("player")){
+        if (fb.getUserData() != null && fb.getUserData().equals("joyau1") && fa.getUserData() != null && fa.getBody().getUserData().equals("player")){
             if (!bodyToRemove.contains(fb.getBody(), false)){
+                score++;
+                bodyToRemove.add(fb.getBody());
+            }
+        }
+
+        if (fb.getUserData() != null && fb.getUserData().equals("joyau2") && fa.getUserData() != null && fa.getBody().getUserData().equals("player")){
+            if (!bodyToRemove.contains(fb.getBody(), false)){
+                score += 2;
                 bodyToRemove.add(fb.getBody());
-                System.out.println("à enlever");
             }
         }
 
@@ -76,4 +84,8 @@ public class ContactListenerPerso implements ContactListener {
     public Array<Body> getBodyToRemove() {
         return bodyToRemove;
     }
+
+    public int getScore() {
+        return score;
+    }
 }
-- 
GitLab