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

mort si on sort du monde en x sans passer par un panneau

parent 242f2f1f
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,7 @@ public class Panneau {
fixtureDefStruct.isSensor = true;
structBody.createFixture(fixtureDefStruct);
structBody.createFixture(fixtureDefStruct).setUserData("panneau");
shapeStruct.dispose();
}
}
\ No newline at end of file
......@@ -5,9 +5,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
......@@ -21,7 +19,6 @@ import com.mygdx.game.PlatVenture;
import body.Joyau;
import body.Panneau;
import body.Platform;
import body.Water;
import handlers.ContactListenerPerso;
import handlers.GameStateManager;
import handlers.InputPerso;
......@@ -35,6 +32,8 @@ public class Play extends GameState {
private int temps;
private ContactListenerPerso cl;
private int score = 0;
private boolean dead = false;
private float totalTimeSinceDeath = 0;
private Body player;
......@@ -48,7 +47,7 @@ public class Play extends GameState {
b2dr = new Box2DDebugRenderer();
createWorld("assets/level_002.txt");
createWorld("assets/level_001.txt");
createPlayer();
//Init b2dCam
......@@ -89,6 +88,7 @@ public class Play extends GameState {
}
joyauToRemove.clear();
death(dt);
// Bouger la caméra en x
if (player.getPosition().x * PPM > (float) (PlatVenture.largeur / 2) && player.getPosition().y * PPM <= (float) (PlatVenture.hauteur / 2)
&& largeur > 16) {
......@@ -208,4 +208,29 @@ public class Play extends GameState {
player.createFixture(foot).setUserData("foot");
}
private boolean isInside(){
boolean isinside = true;
if (player.getPosition().x < -5/PPM){ // Si la totalité du corps du joueur sort
isinside = false;
}
return isinside;
}
private void death(float dt){
if (!isInside() && !cl.isTriggerEndLevel()){
dead = true;
}
if (dead){
if (totalTimeSinceDeath > 2){
player.setLinearVelocity(0, 0);
player.setTransform(15/PPM, 20/PPM, 0);
dead = false;
totalTimeSinceDeath = 0;
} else{
totalTimeSinceDeath += dt;
}
}
}
}
......@@ -13,6 +13,7 @@ public class ContactListenerPerso implements ContactListener {
private int numPlayerOnGround = 0;
Array<Body> bodyToRemove = new Array<Body>();
private int score = 0;
private boolean triggerEndLevel = false;
/**
* Appeler quand 2 fixtures rentre en collision
......@@ -55,6 +56,13 @@ public class ContactListenerPerso implements ContactListener {
if (fb.getUserData() != null && fb.getUserData().equals("foot") && fa.getUserData() != null && fa.getUserData().equals("platform")){
numPlayerOnGround--;
}
if (fa.getUserData() != null && fa.getUserData().equals("panneau") && fb.getUserData() != null && fb.getUserData().equals("body")){
triggerEndLevel = true;
}
else{
triggerEndLevel = false;
}
}
/**
......@@ -88,4 +96,8 @@ public class ContactListenerPerso implements ContactListener {
public int getScore() {
return score;
}
public boolean isTriggerEndLevel() {
return triggerEndLevel;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment