diff --git a/core/src/body/Joyau.java b/core/src/body/Joyau.java index 1843e3177442aa11c0233ff380cae73dc8e0c2e6..3882afaf62c5efad5c80c9ba2b2b448086140624 100644 --- a/core/src/body/Joyau.java +++ b/core/src/body/Joyau.java @@ -14,6 +14,8 @@ public class Joyau { CircleShape shapeStruct; private int value; private float x; + private float y; + private World world; public Joyau(float x, float y, World world, char value){ BodyDef bodyDef = new BodyDef(); @@ -46,4 +48,5 @@ public class Joyau { public int getValue() { return value; } + } \ No newline at end of file diff --git a/core/src/com/mygdx/game/PlatVenture.java b/core/src/com/mygdx/game/PlatVenture.java index 92e501696fd209698c5fa2d6bf81009c1cda1983..e8d16468a90750c5301c6d476ae55b6c22bd5390 100644 --- a/core/src/com/mygdx/game/PlatVenture.java +++ b/core/src/com/mygdx/game/PlatVenture.java @@ -104,5 +104,6 @@ public class PlatVenture extends ApplicationAdapter { res.loadTexture("Back.png", "back"); res.loadTexture("Idle__000.png", "idle_000"); res.loadTexture("Water.png", "water"); + res.loadTexture("Gem_1.png", "gem1"); } } diff --git a/core/src/entities/B2DSprite.java b/core/src/entities/B2DSprite.java index f7a28511ba0a209170d63799c93d612808142bae..65b98adbedc1bf5ed73800f58ad5a172d3680e76 100644 --- a/core/src/entities/B2DSprite.java +++ b/core/src/entities/B2DSprite.java @@ -35,9 +35,7 @@ public class B2DSprite { } public void render(SpriteBatch sb) { - sb.begin(); - sb.draw(animation.getFrame(), (body.getPosition().x * B2DVars.PPM - width / 2), (int) (body.getPosition().y * B2DVars.PPM - height / 2)); - sb.end(); + sb.draw(animation.getFrame(), 1, 1); } public Body getBody() { return body; } diff --git a/core/src/entities/Gem.java b/core/src/entities/Gem.java index 65b54fb92354f994395d25c318decb1b50f7addd..7cf3abfc7248adf12eeda58b81cf7a821e4f9c45 100644 --- a/core/src/entities/Gem.java +++ b/core/src/entities/Gem.java @@ -6,13 +6,23 @@ import com.badlogic.gdx.physics.box2d.Body; import com.mygdx.game.PlatVenture; public class Gem extends B2DSprite{ + private int value; + public Gem(Body body) { super(body); - Texture tex = PlatVenture.res.getTexture("crystal"); - TextureRegion[] sprites = TextureRegion.split(tex, 16, 16)[0]; - animation.setFrames(sprites, 1 / 30f); + Texture tex = PlatVenture.res.getTexture("gem1"); + TextureRegion[] sprites = TextureRegion.split(tex, 56, 56)[0]; + animation.setFrames(sprites, 1 / 12f); width = sprites[0].getRegionWidth(); height = sprites[0].getRegionHeight(); } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } } diff --git a/core/src/etat/Play.java b/core/src/etat/Play.java index 3175b78a991dfab9f78fc0d14ea856a8cfa1a9be..0b059006a9bbb671575b15d6f9f21bf459f9441e 100644 --- a/core/src/etat/Play.java +++ b/core/src/etat/Play.java @@ -7,7 +7,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.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.BodyDef; @@ -17,13 +17,12 @@ import com.badlogic.gdx.physics.box2d.FixtureDef; import com.badlogic.gdx.physics.box2d.PolygonShape; import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.utils.Array; -import com.badlogic.gdx.utils.GdxRuntimeException; import com.mygdx.game.PlatVenture; -import body.Joyau; import body.Panneau; import body.Platform; import body.Water; +import entities.Gem; import handlers.ContactListenerPerso; import handlers.Content; import handlers.GameStateManager; @@ -43,6 +42,9 @@ public class Play extends GameState { private int level = 1; private boolean isChangingLevel = false; 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; @@ -67,8 +69,6 @@ public class Play extends GameState { textCam = new OrthographicCamera(); b2dCam.setToOrtho(false, PlatVenture.largeur /PPM, PlatVenture.hauteur/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 { } } + for(int i = 0; i < GemCollection.size; i++) { + GemCollection.get(i).update(dt); + } + b2dCam.update(); textCam.update(); @@ -170,7 +174,11 @@ public class Play extends GameState { //Clear l'écran Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(b2dCam.combined); + batch.begin(); + for(int i = 0; i < GemCollection.size; i++) { + GemCollection.get(i).render(batch); + } drawWorld(); batch.draw(PlatVenture.res.getTexture("idle_000"), player.getPosition().x - 5f/PPM, player.getPosition().y - 2f/PPM, 1/10f, 1/10f); batch.end(); @@ -195,7 +203,6 @@ public class Play extends GameState { map = new char[hauteur][largeur]; for (int i = hauteur; i > 0; i--){ for (int j = 0; j < largeur; j++){ - System.out.print(ligne[i].charAt(j)); char current = ligne[i].charAt(j); map[i-1][j] = current; switch (current){ @@ -221,7 +228,20 @@ public class Play extends GameState { break; case '1': 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; case 'Z': new Panneau((j*10)/PPM, ((hauteur-i) * 10)/PPM, world); @@ -230,7 +250,6 @@ public class Play extends GameState { } } - System.out.println(); } } @@ -325,7 +344,6 @@ public class Play extends GameState { loadLevel(level); createPlayer(); //player.setLinearVelocity(0, 0); // annule la vitesse linéaire du personnage - System.out.println("changing level"); isChangingLevel = false; totalTimeSinceAction = 0; @@ -367,6 +385,7 @@ public class Play extends GameState { break; case 'W': batch.draw(PlatVenture.res.getTexture("water"), (j*10)/PPM, ((hauteur-i)*10)/PPM, 1/10f, 1/10f); + break; } }