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

mort dans l'eau

parent cb7e789d
No related branches found
No related tags found
No related merge requests found
package body; package body;
import static handlers.B2DVars.PPM;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef; import com.badlogic.gdx.physics.box2d.BodyDef;
...@@ -12,7 +14,8 @@ public class Water { ...@@ -12,7 +14,8 @@ public class Water {
PolygonShape shapeStruct; PolygonShape shapeStruct;
Vector2[] ptsStruct; Vector2[] ptsStruct;
public Water(int x, int y, World world){ /*TODO Rajouter des box en dessous pour éviter au perso de se casser la gueule*/
public Water(float x, float y, World world){
BodyDef bodyDef = new BodyDef(); BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.StaticBody; bodyDef.type = BodyDef.BodyType.StaticBody;
...@@ -23,14 +26,14 @@ public class Water { ...@@ -23,14 +26,14 @@ public class Water {
FixtureDef fixtureDefStruct = new FixtureDef(); FixtureDef fixtureDefStruct = new FixtureDef();
shapeStruct = new PolygonShape(); shapeStruct = new PolygonShape();
ptsStruct = new Vector2[]{}; ptsStruct = new Vector2[]{new Vector2(0, 0), new Vector2(10/PPM, 0), new Vector2(10/PPM, 10/PPM), new Vector2(0, 10/PPM)};
shapeStruct.set(ptsStruct); shapeStruct.set(ptsStruct);
fixtureDefStruct.shape = shapeStruct; fixtureDefStruct.shape = shapeStruct;
fixtureDefStruct.isSensor = true; //traversable fixtureDefStruct.isSensor = true; //traversable
structBody.createFixture(fixtureDefStruct); structBody.createFixture(fixtureDefStruct).setUserData("eau");
shapeStruct.dispose(); shapeStruct.dispose();
} }
} }
......
...@@ -19,6 +19,7 @@ import com.mygdx.game.PlatVenture; ...@@ -19,6 +19,7 @@ import com.mygdx.game.PlatVenture;
import body.Joyau; import body.Joyau;
import body.Panneau; import body.Panneau;
import body.Platform; import body.Platform;
import body.Water;
import handlers.ContactListenerPerso; import handlers.ContactListenerPerso;
import handlers.GameStateManager; import handlers.GameStateManager;
import handlers.InputPerso; import handlers.InputPerso;
...@@ -98,6 +99,10 @@ public class Play extends GameState { ...@@ -98,6 +99,10 @@ public class Play extends GameState {
} }
} }
if (cl.isTouchWater()){
death(dt);
}
if (isChangingLevel){ if (isChangingLevel){
changeLevel(dt); changeLevel(dt);
} }
...@@ -180,6 +185,8 @@ public class Play extends GameState { ...@@ -180,6 +185,8 @@ public class Play extends GameState {
break; break;
case 'Z': case 'Z':
new Panneau((j*10)/PPM, ((hauteur-i) * 10)/PPM, world); new Panneau((j*10)/PPM, ((hauteur-i) * 10)/PPM, world);
case 'W':
new Water((j*10)/PPM, ((hauteur-i) * 10)/PPM, world);
} }
} }
...@@ -234,9 +241,11 @@ public class Play extends GameState { ...@@ -234,9 +241,11 @@ public class Play extends GameState {
if (totalTimeSinceAction > 2){ if (totalTimeSinceAction > 2){
player.setLinearVelocity(0, 0); player.setLinearVelocity(0, 0);
player.setTransform(15/PPM, 20/PPM, 0); player.setTransform(15/PPM, 20/PPM, 0);
score = 0; // reset du score
totalTimeSinceAction = 0; totalTimeSinceAction = 0;
} else{ } else{
totalTimeSinceAction += dt; totalTimeSinceAction += dt;
player.setLinearVelocity(0, 0);
} }
} }
...@@ -247,13 +256,21 @@ public class Play extends GameState { ...@@ -247,13 +256,21 @@ public class Play extends GameState {
private void changeLevel(float dt){ private void changeLevel(float dt){
if (totalTimeSinceAction > 2) { if (totalTimeSinceAction > 2) {
// Destruction de tout les body
Array<Body> bodies = new Array<>(); Array<Body> bodies = new Array<>();
world.getBodies(bodies); world.getBodies(bodies);
for (int i = 0; i < bodies.size; i++) { for (int i = 0; i < bodies.size; i++) {
if (!world.isLocked()) if (!world.isLocked())
world.destroyBody(bodies.get(i)); world.destroyBody(bodies.get(i));
} }
level++; // Incrémente le level
loadLevel(level);
createPlayer();
player.setLinearVelocity(0, 0); // annule la vitesse linéaire du personnage
System.out.println("changing level");
isChangingLevel = false; isChangingLevel = false;
totalTimeSinceAction = 0;
} }
else{ else{
totalTimeSinceAction += dt; totalTimeSinceAction += dt;
......
...@@ -14,6 +14,7 @@ public class ContactListenerPerso implements ContactListener { ...@@ -14,6 +14,7 @@ public class ContactListenerPerso implements ContactListener {
Array<Body> bodyToRemove = new Array<Body>(); Array<Body> bodyToRemove = new Array<Body>();
private int score = 0; private int score = 0;
private boolean triggerEndLevel = false; private boolean triggerEndLevel = false;
private boolean touchWater = false;
/** /**
* Appeler quand 2 fixtures rentre en collision * Appeler quand 2 fixtures rentre en collision
...@@ -42,6 +43,12 @@ public class ContactListenerPerso implements ContactListener { ...@@ -42,6 +43,12 @@ public class ContactListenerPerso implements ContactListener {
} }
} }
if (fa.getUserData() != null && fa.getUserData().equals("eau")){
touchWater = true;
}else{
touchWater = false;
}
} }
/** /**
...@@ -100,4 +107,8 @@ public class ContactListenerPerso implements ContactListener { ...@@ -100,4 +107,8 @@ public class ContactListenerPerso implements ContactListener {
public boolean isTriggerEndLevel() { public boolean isTriggerEndLevel() {
return triggerEndLevel; return triggerEndLevel;
} }
public boolean isTouchWater() {
return touchWater;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment