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

final

parent 274db359
No related branches found
No related tags found
1 merge request!1Restart
...@@ -14,6 +14,8 @@ public class Joyau { ...@@ -14,6 +14,8 @@ public class Joyau {
CircleShape shapeStruct; CircleShape shapeStruct;
private int value; private int value;
private float x; private float x;
private float y;
private World world;
public Joyau(float x, float y, World world, char value){ public Joyau(float x, float y, World world, char value){
BodyDef bodyDef = new BodyDef(); BodyDef bodyDef = new BodyDef();
...@@ -46,4 +48,5 @@ public class Joyau { ...@@ -46,4 +48,5 @@ public class Joyau {
public int getValue() { public int getValue() {
return value; return value;
} }
} }
\ No newline at end of file
...@@ -104,5 +104,6 @@ public class PlatVenture extends ApplicationAdapter { ...@@ -104,5 +104,6 @@ public class PlatVenture extends ApplicationAdapter {
res.loadTexture("Back.png", "back"); res.loadTexture("Back.png", "back");
res.loadTexture("Idle__000.png", "idle_000"); res.loadTexture("Idle__000.png", "idle_000");
res.loadTexture("Water.png", "water"); res.loadTexture("Water.png", "water");
res.loadTexture("Gem_1.png", "gem1");
} }
} }
...@@ -35,9 +35,7 @@ public class B2DSprite { ...@@ -35,9 +35,7 @@ public class B2DSprite {
} }
public void render(SpriteBatch sb) { public void render(SpriteBatch sb) {
sb.begin(); sb.draw(animation.getFrame(), 1, 1);
sb.draw(animation.getFrame(), (body.getPosition().x * B2DVars.PPM - width / 2), (int) (body.getPosition().y * B2DVars.PPM - height / 2));
sb.end();
} }
public Body getBody() { return body; } public Body getBody() { return body; }
......
...@@ -6,13 +6,23 @@ import com.badlogic.gdx.physics.box2d.Body; ...@@ -6,13 +6,23 @@ import com.badlogic.gdx.physics.box2d.Body;
import com.mygdx.game.PlatVenture; import com.mygdx.game.PlatVenture;
public class Gem extends B2DSprite{ public class Gem extends B2DSprite{
private int value;
public Gem(Body body) { public Gem(Body body) {
super(body); super(body);
Texture tex = PlatVenture.res.getTexture("crystal"); Texture tex = PlatVenture.res.getTexture("gem1");
TextureRegion[] sprites = TextureRegion.split(tex, 16, 16)[0]; TextureRegion[] sprites = TextureRegion.split(tex, 56, 56)[0];
animation.setFrames(sprites, 1 / 30f); animation.setFrames(sprites, 1 / 12f);
width = sprites[0].getRegionWidth(); width = sprites[0].getRegionWidth();
height = sprites[0].getRegionHeight(); height = sprites[0].getRegionHeight();
} }
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
} }
...@@ -7,7 +7,7 @@ import com.badlogic.gdx.Gdx; ...@@ -7,7 +7,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.BitmapFont;
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;
...@@ -17,13 +17,12 @@ import com.badlogic.gdx.physics.box2d.FixtureDef; ...@@ -17,13 +17,12 @@ import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape; import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.mygdx.game.PlatVenture; import com.mygdx.game.PlatVenture;
import body.Joyau;
import body.Panneau; import body.Panneau;
import body.Platform; import body.Platform;
import body.Water; import body.Water;
import entities.Gem;
import handlers.ContactListenerPerso; import handlers.ContactListenerPerso;
import handlers.Content; import handlers.Content;
import handlers.GameStateManager; import handlers.GameStateManager;
...@@ -43,6 +42,9 @@ public class Play extends GameState { ...@@ -43,6 +42,9 @@ public class Play extends GameState {
private int level = 1; private int level = 1;
private boolean isChangingLevel = false; private boolean isChangingLevel = false;
private float timeDoubleTap = 0f; private float timeDoubleTap = 0f;
//BitmapFont font = new BitmapFont(Gdx.files.internal("Comic_Sans_MS_Bold.ttf"), false);
private Array<Gem> GemCollection = new Array<Gem>();
private Content res; private Content res;
...@@ -67,8 +69,6 @@ public class Play extends GameState { ...@@ -67,8 +69,6 @@ public class Play extends GameState {
textCam = new OrthographicCamera(); textCam = new OrthographicCamera();
b2dCam.setToOrtho(false, PlatVenture.largeur /PPM, PlatVenture.hauteur/PPM); b2dCam.setToOrtho(false, PlatVenture.largeur /PPM, PlatVenture.hauteur/PPM);
textCam.setToOrtho(false, Gdx.graphics.getWidth() / PPM, Gdx.graphics.getHeight() / PPM); textCam.setToOrtho(false, Gdx.graphics.getWidth() / PPM, Gdx.graphics.getHeight() / PPM);
//textCam.position.set(Gdx.graphics.getWidth() / PPM / 2, 0, 0);
//loadTexture();
} }
...@@ -157,6 +157,10 @@ public class Play extends GameState { ...@@ -157,6 +157,10 @@ public class Play extends GameState {
} }
} }
for(int i = 0; i < GemCollection.size; i++) {
GemCollection.get(i).update(dt);
}
b2dCam.update(); b2dCam.update();
textCam.update(); textCam.update();
...@@ -170,7 +174,11 @@ public class Play extends GameState { ...@@ -170,7 +174,11 @@ public class Play extends GameState {
//Clear l'écran //Clear l'écran
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(b2dCam.combined); batch.setProjectionMatrix(b2dCam.combined);
batch.begin(); batch.begin();
for(int i = 0; i < GemCollection.size; i++) {
GemCollection.get(i).render(batch);
}
drawWorld(); drawWorld();
batch.draw(PlatVenture.res.getTexture("idle_000"), player.getPosition().x - 5f/PPM, player.getPosition().y - 2f/PPM, 1/10f, 1/10f); batch.draw(PlatVenture.res.getTexture("idle_000"), player.getPosition().x - 5f/PPM, player.getPosition().y - 2f/PPM, 1/10f, 1/10f);
batch.end(); batch.end();
...@@ -195,7 +203,6 @@ public class Play extends GameState { ...@@ -195,7 +203,6 @@ public class Play extends GameState {
map = new char[hauteur][largeur]; map = new char[hauteur][largeur];
for (int i = hauteur; i > 0; i--){ for (int i = hauteur; i > 0; i--){
for (int j = 0; j < largeur; j++){ for (int j = 0; j < largeur; j++){
System.out.print(ligne[i].charAt(j));
char current = ligne[i].charAt(j); char current = ligne[i].charAt(j);
map[i-1][j] = current; map[i-1][j] = current;
switch (current){ switch (current){
...@@ -221,7 +228,20 @@ public class Play extends GameState { ...@@ -221,7 +228,20 @@ public class Play extends GameState {
break; break;
case '1': case '1':
case '2': case '2':
new Joyau((j*10)/PPM, ((hauteur-i) * 10)/PPM, world, current); BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.StaticBody;
bodyDef.position.set((j*10)/PPM, ((hauteur-i)*10)/PPM);
Body structBody = world.createBody(bodyDef);
FixtureDef fixtureDefStruct = new FixtureDef();
CircleShape shapeStruct = new CircleShape();
shapeStruct.setRadius(1/PPM);
shapeStruct.setPosition(new Vector2(5/PPM, 5/PPM));
fixtureDefStruct.shape = shapeStruct;
fixtureDefStruct.isSensor = true;
structBody.createFixture(fixtureDefStruct).setUserData("joyau"+current);
Gem g = new Gem(structBody);
g.setValue(Character.getNumericValue(current));
GemCollection.add(g);
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);
...@@ -230,7 +250,6 @@ public class Play extends GameState { ...@@ -230,7 +250,6 @@ public class Play extends GameState {
} }
} }
System.out.println();
} }
} }
...@@ -325,7 +344,6 @@ public class Play extends GameState { ...@@ -325,7 +344,6 @@ public class Play extends GameState {
loadLevel(level); loadLevel(level);
createPlayer(); createPlayer();
//player.setLinearVelocity(0, 0); // annule la vitesse linéaire du personnage //player.setLinearVelocity(0, 0); // annule la vitesse linéaire du personnage
System.out.println("changing level");
isChangingLevel = false; isChangingLevel = false;
totalTimeSinceAction = 0; totalTimeSinceAction = 0;
...@@ -367,6 +385,7 @@ public class Play extends GameState { ...@@ -367,6 +385,7 @@ public class Play extends GameState {
break; break;
case 'W': case 'W':
batch.draw(PlatVenture.res.getTexture("water"), (j*10)/PPM, ((hauteur-i)*10)/PPM, 1/10f, 1/10f); batch.draw(PlatVenture.res.getTexture("water"), (j*10)/PPM, ((hauteur-i)*10)/PPM, 1/10f, 1/10f);
break;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment