diff --git a/android/assets/Water.png b/android/assets/Water.png new file mode 100644 index 0000000000000000000000000000000000000000..80ae3bbfbf4fe7a4711ec56a128280bc0642a673 Binary files /dev/null and b/android/assets/Water.png differ diff --git a/core/src/body/Joyau.java b/core/src/body/Joyau.java index a1864ca176e285a1bf70c16a896972be227418ac..3882afaf62c5efad5c80c9ba2b2b448086140624 100644 --- a/core/src/body/Joyau.java +++ b/core/src/body/Joyau.java @@ -13,6 +13,9 @@ import com.badlogic.gdx.physics.box2d.World; 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(); @@ -45,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 b8d9b8c54eaa560da55e3b7e057f86aecdc62316..e8d16468a90750c5301c6d476ae55b6c22bd5390 100644 --- a/core/src/com/mygdx/game/PlatVenture.java +++ b/core/src/com/mygdx/game/PlatVenture.java @@ -21,6 +21,8 @@ public class PlatVenture extends ApplicationAdapter { public static final float STEP = 1 /60f; // Pas entre deux images private float accum; + private float compteurIntro = 0; + private boolean hasPassedIntro = false; private SpriteBatch batch; private OrthographicCamera cam; @@ -42,6 +44,7 @@ public class PlatVenture extends ApplicationAdapter { hudCam = new OrthographicCamera(); hudCam.setToOrtho(false, largeur, hauteur); gsm = new GameStateManager(this); + loadContent(); } @Override @@ -50,6 +53,15 @@ public class PlatVenture extends ApplicationAdapter { // update seulement si suffisamment de temps est passé depuis la dernière étape while (accum >= STEP){ + if (compteurIntro < 3){ + compteurIntro += STEP; + }else{ + //compteurIntro = 0; + if (!hasPassedIntro) { + gsm.setState(GameStateManager.PLAY); + hasPassedIntro = true; + } + } accum -= STEP; gsm.update(STEP); gsm.render(); @@ -74,4 +86,24 @@ public class PlatVenture extends ApplicationAdapter { public OrthographicCamera getHudCam() { return hudCam; } + + private void loadContent(){ + res.loadTexture("Platform_J.png", "platJ"); + res.loadTexture("Platform_K.png", "platK"); + res.loadTexture("Platform_L.png", "platL"); + res.loadTexture("Brick_A.png", "brickA"); + res.loadTexture("Brick_B.png", "brickB"); + res.loadTexture("Brick_C.png", "brickC"); + res.loadTexture("Brick_D.png", "brickD"); + res.loadTexture("Brick_E.png", "brickE"); + res.loadTexture("Brick_F.png", "brickF"); + res.loadTexture("Brick_G.png", "brickG"); + res.loadTexture("Brick_H.png", "brickH"); + res.loadTexture("Brick_I.png", "brickI"); + res.loadTexture("Exit_Z.png", "exit"); + 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 new file mode 100644 index 0000000000000000000000000000000000000000..65b98adbedc1bf5ed73800f58ad5a172d3680e76 --- /dev/null +++ b/core/src/entities/B2DSprite.java @@ -0,0 +1,46 @@ +package entities; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.physics.box2d.Body; + +import handlers.Animation; +import handlers.B2DVars; + +public class B2DSprite { + + protected Body body; + protected Animation animation; + protected float width; + protected float height; + + public B2DSprite(Body body) { + this.body = body; + animation = new Animation(); + } + + public void setAnimation(TextureRegion reg, float delay) { + setAnimation(new TextureRegion[] { reg }, delay); + } + + public void setAnimation(TextureRegion[] reg, float delay) { + animation.setFrames(reg, delay); + width = reg[0].getRegionWidth(); + height = reg[0].getRegionHeight(); + } + + public void update(float dt) { + animation.update(dt); + } + + public void render(SpriteBatch sb) { + sb.draw(animation.getFrame(), 1, 1); + } + + public Body getBody() { return body; } + public Vector2 getPosition() { return body.getPosition(); } + public float getWidth() { return width; } + public float getHeight() { return height; } + +} diff --git a/core/src/entities/Gem.java b/core/src/entities/Gem.java new file mode 100644 index 0000000000000000000000000000000000000000..7cf3abfc7248adf12eeda58b81cf7a821e4f9c45 --- /dev/null +++ b/core/src/entities/Gem.java @@ -0,0 +1,28 @@ +package entities; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +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("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 e0c75a59025991c41d6b67c7ac9ddc39b70d7da4..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(); } @@ -115,8 +115,8 @@ public class Play extends GameState { if (!isInside()){ if (cl.isTriggerEndLevel()){ - isChangingLevel = true; - cl.setTriggerEndLevel(false); + isChangingLevel = true; + cl.setTriggerEndLevel(false); }else{ if (!isChangingLevel) { death(dt); @@ -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,9 +174,13 @@ 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(res.getTexture("idle_001"), 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(); //dessine le monde box2d b2dr.render(world, b2dCam.combined); @@ -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(); } } @@ -238,7 +257,7 @@ public class Play extends GameState { BodyDef bdP = new BodyDef(); bdP.type = BodyDef.BodyType.DynamicBody; bdP.fixedRotation = true; - bdP.position.set(15/PPM, 20/PPM); + bdP.position.set(15/PPM, 20/PPM); // 15, 20 player = world.createBody(bdP); player.setUserData("player"); @@ -286,7 +305,6 @@ public class Play extends GameState { } private void death(float dt){ - /*TODO vérifier pourquoi pas de mort niveau 2*/ if (totalTimeSinceAction > 2){ player.setLinearVelocity(0, 0); player.setTransform(15/PPM, 20/PPM, 0); @@ -326,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; @@ -337,19 +354,19 @@ public class Play extends GameState { } private void drawWorld(){ - batch.draw(res.getTexture("back"), 0, 0, largeur/10f, hauteur/10f); + batch.draw(PlatVenture.res.getTexture("back"), 0, 0, largeur/10f, hauteur/10f); String key; for (int i = hauteur; i > 0; i--){ for (int j = 0; j < largeur; j++) { switch (map[i-1][j]){ case 'J': - batch.draw(res.getTexture("platJ"), (j*10)/PPM, ((hauteur-i) * 10)/PPM + 2/PPM, 1/10f, 1/12f); + batch.draw(PlatVenture.res.getTexture("platJ"), (j*10)/PPM, ((hauteur-i) * 10)/PPM + 2/PPM, 1/10f, 1/12f); break; case 'K': - batch.draw(res.getTexture("platK"), (j*10)/PPM, ((hauteur-i) * 10)/PPM + 2/PPM, 1/10f, 1/12f); + batch.draw(PlatVenture.res.getTexture("platK"), (j*10)/PPM, ((hauteur-i) * 10)/PPM + 2/PPM, 1/10f, 1/12f); break; case 'L': - batch.draw(res.getTexture("platL"), (j*10)/PPM, ((hauteur-i) * 10)/PPM + 2/PPM, 1/10f, 1/12f); + batch.draw(PlatVenture.res.getTexture("platL"), (j*10)/PPM, ((hauteur-i) * 10)/PPM + 2/PPM, 1/10f, 1/12f); break; case 'A': case 'B': @@ -361,10 +378,14 @@ public class Play extends GameState { case 'H': case 'I': key = "brick" + map[i-1][j]; - batch.draw(res.getTexture(key), (j*10)/PPM, ((hauteur-i) * 10)/PPM, 1/10f, 1/10f); + batch.draw(PlatVenture.res.getTexture(key), (j*10)/PPM, ((hauteur-i) * 10)/PPM, 1/10f, 1/10f); break; case 'Z': - batch.draw(res.getTexture("exit"), (j*10)/PPM, ((hauteur-i) * 10)/PPM, 1/10f, 1/10f); + batch.draw(PlatVenture.res.getTexture("exit"), (j*10)/PPM, ((hauteur-i) * 10)/PPM, 1/10f, 1/10f); + break; + case 'W': + batch.draw(PlatVenture.res.getTexture("water"), (j*10)/PPM, ((hauteur-i)*10)/PPM, 1/10f, 1/10f); + break; } } @@ -388,7 +409,8 @@ public class Play extends GameState { res.loadTexture("Brick_I.png", "brickI"); res.loadTexture("Exit_Z.png", "exit"); res.loadTexture("Back.png", "back"); - res.loadTexture("Idle__000.png", "idle_001"); + res.loadTexture("Idle__000.png", "idle_000"); + res.loadTexture("Water.png", "water"); //res.getTexture("platJ"); } } diff --git a/core/src/etat/WaitingScreen.java b/core/src/etat/WaitingScreen.java new file mode 100644 index 0000000000000000000000000000000000000000..31f286c424ad6a7befab3b8c3a26ec6818857270 --- /dev/null +++ b/core/src/etat/WaitingScreen.java @@ -0,0 +1,44 @@ +package etat; + +import static handlers.B2DVars.PPM; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL20; +import com.mygdx.game.PlatVenture; + +import handlers.Content; +import handlers.GameStateManager; + +public class WaitingScreen extends GameState{ + + private Content res; + + public WaitingScreen(GameStateManager gsm) { + super(gsm); + res = new Content(); + res.loadTexture("Intro.png", "intro"); + } + + @Override + public void handleInput() { + + } + + @Override + public void update(float dt) { + + } + + @Override + public void render() { + batch.setProjectionMatrix(cam.combined); + batch.begin(); + batch.draw(res.getTexture("intro"), 0, 0, PlatVenture.largeur, PlatVenture.hauteur); + batch.end(); + } + + @Override + public void dispose() { + + } +} diff --git a/core/src/handlers/Animation.java b/core/src/handlers/Animation.java index 0ee148a50c8196cde11bef13f3039ad3f19aff25..46635b4963f70d433f2d413625d07769ede9b443 100644 --- a/core/src/handlers/Animation.java +++ b/core/src/handlers/Animation.java @@ -3,52 +3,59 @@ package handlers; import com.badlogic.gdx.graphics.g2d.TextureRegion; public class Animation { + private TextureRegion[] frames; private float time; private float delay; private int currentFrame; + private int timesPlayed; - public Animation(){} + public Animation() {} - public Animation (TextureRegion[] frames){ - this(frames, 1/12f); + public Animation(TextureRegion[] frames) { + this(frames, 1 / 12f); } - public Animation(TextureRegion[] frames, float delay){ - setFrames(frames, delay); + public Animation(TextureRegion[] frames, float delay) { + this.frames = frames; + this.delay = delay; + time = 0; + currentFrame = 0; } - public void setFrames(TextureRegion[] frames, float delay){ + public void setDelay(float f) { delay = f; } + public void setCurrentFrame(int i) { if(i < frames.length) currentFrame = i; } + public void setFrames(TextureRegion[] frames) { + setFrames(frames, 1 / 12f); + } + public void setFrames(TextureRegion[] frames, float delay) { this.frames = frames; - this.delay = delay; time = 0; currentFrame = 0; timesPlayed = 0; + this.delay = delay; } - public void update(float dt){ - if (delay<=0) return; + public void update(float dt) { + if(delay <= 0) return; time += dt; - while (time >= delay){ + while(time >= delay) { step(); } } - private void step(){ + private void step() { time -= delay; currentFrame++; - if (currentFrame == frames.length){ + if(currentFrame == frames.length) { currentFrame = 0; timesPlayed++; } } - public TextureRegion[] getFrames() { - return frames; - } + public TextureRegion getFrame() { return frames[currentFrame]; } + public int getTimesPlayed() { return timesPlayed; } + public boolean hasPlayedOnce() { return timesPlayed > 0; } - public int getTimesPlayed() { - return timesPlayed; - } } diff --git a/core/src/handlers/GameStateManager.java b/core/src/handlers/GameStateManager.java index 9f7277127f83678df011ed8a6e307af3e2d9a61c..2a0c84043bf36dc6be7f84c2bac9f264314cb379 100644 --- a/core/src/handlers/GameStateManager.java +++ b/core/src/handlers/GameStateManager.java @@ -6,18 +6,20 @@ import java.util.Stack; import etat.GameState; import etat.Play; +import etat.WaitingScreen; public class GameStateManager { private PlatVenture platVenture; private Stack<GameState> gameStates; - public static final int PLAY = 4646; + public static final int PLAY = 1; + public static final int WAIT = 0; public GameStateManager(PlatVenture game){ this.platVenture = game; gameStates = new Stack<GameState>(); - pushState(PLAY); + pushState(WAIT); } public PlatVenture getPlatVenture(){ @@ -36,6 +38,9 @@ public class GameStateManager { if (state == PLAY){ return new Play(this); } + if (state == WAIT){ + return new WaitingScreen(this); + } return null; }