Skip to content
Snippets Groups Projects
Commit c65b006d authored by timeo's avatar timeo
Browse files

play connait le score actuel

parent 297e989f
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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");
}
......
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment