diff --git a/core/src/com/mygdx/game/GameScreens/GameIntro.java b/core/src/com/mygdx/game/GameScreens/GameIntro.java index 5b06a9b3862756792ebcaaf6c687eb7d39044b9c..8784ac8cead5929d351cd438874129862cd1f2ab 100644 --- a/core/src/com/mygdx/game/GameScreens/GameIntro.java +++ b/core/src/com/mygdx/game/GameScreens/GameIntro.java @@ -37,7 +37,7 @@ public class GameIntro extends GameScreen batch.draw(intro, 0, 0, GameScreen.Width(), GameScreen.Height()); - if(System.currentTimeMillis() - creationDate > 3000) + if(totalElapsedSeconds() > 3) { // Intro screen is over GameScreenManager.getInstance().showGameScreen(GameScreenEnum.GAME_MENU); diff --git a/core/src/com/mygdx/game/GameScreens/GamePlay.java b/core/src/com/mygdx/game/GameScreens/GamePlay.java index 5c02b22aa6f8ded0923e75403c4d8a4807f957af..4b7216c60ff066952bf16b937a6b9468284dc58b 100644 --- a/core/src/com/mygdx/game/GameScreens/GamePlay.java +++ b/core/src/com/mygdx/game/GameScreens/GamePlay.java @@ -1,32 +1,20 @@ package com.mygdx.game.GameScreens; +import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.audio.Sound; -import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Matrix4; -import com.badlogic.gdx.math.Shape2D; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.physics.box2d.Body; -import com.badlogic.gdx.physics.box2d.BodyDef; -import com.badlogic.gdx.physics.box2d.Box2D; import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer; -import com.badlogic.gdx.physics.box2d.CircleShape; import com.badlogic.gdx.physics.box2d.Contact; -import com.badlogic.gdx.physics.box2d.ContactImpulse; -import com.badlogic.gdx.physics.box2d.ContactListener; -import com.badlogic.gdx.physics.box2d.Fixture; -import com.badlogic.gdx.physics.box2d.FixtureDef; -import com.badlogic.gdx.physics.box2d.Manifold; -import com.badlogic.gdx.physics.box2d.Shape; import com.badlogic.gdx.physics.box2d.World; import com.mygdx.game.bodies.Ball; import com.mygdx.game.bodies.Field; @@ -66,7 +54,7 @@ public class GamePlay extends GameScreen boolean isAI; - boolean contactOccuring = false; + long winTime; Sound shoot_sound, goal_sound; @@ -123,6 +111,7 @@ public class GamePlay extends GameScreen duration = 180; remaining = (int)duration; + winTime = 0; Gdx.input.setInputProcessor(new InputAdapter() { @@ -185,115 +174,100 @@ public class GamePlay extends GameScreen if(remaining <= 0) { - GameScreenManager.getInstance().showGameScreen(GameScreenEnum.GAME_PLAY); - } - field.draw(batch); - pleft.draw(batch); - pright.draw(batch); - ball.draw(batch); - jleft.draw(batch); - jright.draw(batch); - - remaining = (int)(duration - (System.currentTimeMillis() - creationDate) / 1000); - displayTexts(batch); - - //b2dd.render(world, debugMatrix); - - if(showGoalTexture) - { - batch.draw(goal_texture, 0, 0, width(), height()); - if(System.currentTimeMillis() - lastGoal > 1000) + if(winTime == 0) winTime = System.currentTimeMillis(); + if(System.currentTimeMillis() - winTime > 3000) { - showGoalTexture = false; - pleft.reset(lastPlayerWhoScored == pleft); - pright.reset(lastPlayerWhoScored == pright); - ball.reset(); + GameScreenManager.getInstance().showGameScreen(GameScreenEnum.GAME_PLAY); } + showResults(); } else { - if(pleft.getContactStatus().equals("1")) - { - pleft.setContactStatus(2); - String s = pleft.getContactStatus(); - } - if(pright.getContactStatus().equals("1")) - { - pright.setContactStatus(2); - String s = pright.getContactStatus(); - int a = 1; - } - for(Contact contact : world.getContactList()) - { - Object dataA = contact.getFixtureA().getUserData(); - Object dataB = contact.getFixtureB().getUserData(); - - if(dataA != null && dataB != null) - { - String strDataA[] = (String[])dataA; - String strDataB[] = (String[])dataB; - - String objA = strDataA[0]; - String objB = strDataB[0]; - - if((objA.equals("goal") || objA.equals("ball")) && (objB.equals("goal") || objB.equals("ball")) && (!objA.equals(objB))) - { - String scoreSide = objA.equals("goal") ? strDataA[1] : strDataB[1]; - if (scoreSide.equals("left")) - { - score(pleft); - } - else - { - score(pright); - } - } - if((objA.equals("player") || objA.equals("ball")) && (objB.equals("player") || objB.equals("ball")) && (!objA.equals(objB))) - { - if(objA.equals("player")) - { - if(strDataA[1].equals("0")) - { - shoot_sound.play(); - strDataA[1] = "1"; - contact.getFixtureA().setUserData(strDataA); - } - else if(strDataA[1].equals("2")) - { - strDataA[1] = "1"; - contact.getFixtureA().setUserData(strDataA); + field.draw(batch); + pleft.draw(batch); + pright.draw(batch); + ball.draw(batch); + jleft.draw(batch); + jright.draw(batch); + + remaining = (int) (duration - (System.currentTimeMillis() - creationDate) / 1000); + displayTexts(batch); + + //b2dd.render(world, debugMatrix); + + if (showGoalTexture) { + batch.draw(goal_texture, 0, 0, width(), height()); + if (System.currentTimeMillis() - lastGoal > 1000) { + showGoalTexture = false; + pleft.reset(lastPlayerWhoScored == pleft); + pright.reset(lastPlayerWhoScored == pright); + ball.reset(); + } + } else { + if (pleft.getContactStatus().equals("1")) { + pleft.setContactStatus(2); + String s = pleft.getContactStatus(); + } + if (pright.getContactStatus().equals("1")) { + pright.setContactStatus(2); + String s = pright.getContactStatus(); + int a = 1; + } + for (Contact contact : world.getContactList()) { + Object dataA = contact.getFixtureA().getUserData(); + Object dataB = contact.getFixtureB().getUserData(); + + if (dataA != null && dataB != null) { + String strDataA[] = (String[]) dataA; + String strDataB[] = (String[]) dataB; + + String objA = strDataA[0]; + String objB = strDataB[0]; + + if ((objA.equals("goal") || objA.equals("ball")) && (objB.equals("goal") || objB.equals("ball")) && (!objA.equals(objB))) { + String scoreSide = objA.equals("goal") ? strDataA[1] : strDataB[1]; + if (scoreSide.equals("left")) { + score(pleft); + } else { + score(pright); } } - else - { - if(strDataB[1].equals("0")) - { - shoot_sound.play(); - strDataB[1] = "1"; - contact.getFixtureB().setUserData(strDataB); - } - else if (strDataB[1].equals("2")) - { - strDataB[1] = "1"; - contact.getFixtureB().setUserData(strDataB); + if ((objA.equals("player") || objA.equals("ball")) && (objB.equals("player") || objB.equals("ball")) && (!objA.equals(objB))) { + if (objA.equals("player")) { + if (strDataA[1].equals("0")) { + shoot_sound.play(); + strDataA[1] = "1"; + contact.getFixtureA().setUserData(strDataA); + } else if (strDataA[1].equals("2")) { + strDataA[1] = "1"; + contact.getFixtureA().setUserData(strDataA); + } + } else { + if (strDataB[1].equals("0")) { + shoot_sound.play(); + strDataB[1] = "1"; + contact.getFixtureB().setUserData(strDataB); + } else if (strDataB[1].equals("2")) { + strDataB[1] = "1"; + contact.getFixtureB().setUserData(strDataB); + } } } } } + if (pleft.getContactStatus().equals("2")) { + pleft.setContactStatus(0); + } + if (pright.getContactStatus().equals("2")) { + pright.setContactStatus(0); + } + if (isAI) pleft.interact(ball.getPos()); + else + pleft.interact(pressed(Input.Keys.Q), pressed(Input.Keys.D), pressed(Input.Keys.Z), pressed(Input.Keys.S)); + pright.interact(pressed(Input.Keys.J), pressed(Input.Keys.L), pressed(Input.Keys.I), pressed(Input.Keys.K)); } - if(pleft.getContactStatus().equals("2")) - { - pleft.setContactStatus(0); - } - if(pright.getContactStatus().equals("2")) - { - pright.setContactStatus(0); - } - if(isAI) pleft.interact(ball.getPos()); - else pleft.interact(pressed(Input.Keys.Q), pressed(Input.Keys.D), pressed(Input.Keys.Z), pressed(Input.Keys.S)); - pright.interact(pressed(Input.Keys.J), pressed(Input.Keys.L), pressed(Input.Keys.I), pressed(Input.Keys.K)); - } - world.step(delta, 8, 3); + world.step(delta, 8, 3); + } super.render(delta); } @@ -325,8 +299,34 @@ public class GamePlay extends GameScreen lastGoal = System.currentTimeMillis(); } + private void showResults() + { + String message = "Match nul !"; + if(scoreRight < scoreLeft) + { + message = "Joueur Droite gagnant !"; + } + else if(scoreLeft < scoreRight) + { + message = "Joueur Gauche gagnant !"; + } + font.draw(batch, message, 0, GameScreen.Height()/2, GameScreen.Width(), 1, true); + } + private boolean pressed(int key) { return Gdx.input.isKeyPressed(key); } + + @Override + public void dispose() { + super.dispose(); + /*pleft.dispose(); + pright.dispose();*/ + jleft.dispose(); + jright.dispose(); + /*ball.dispose(); + field.dispose(); + world.dispose();*/ + } } diff --git a/core/src/com/mygdx/game/GameScreens/GameScreen.java b/core/src/com/mygdx/game/GameScreens/GameScreen.java index 43a24403f5ba0276efc6fd8243c74e6ba8646df0..411b1f92d0d9ed281604133b3f55eb9d8041a4df 100644 --- a/core/src/com/mygdx/game/GameScreens/GameScreen.java +++ b/core/src/com/mygdx/game/GameScreens/GameScreen.java @@ -82,4 +82,9 @@ public abstract class GameScreen extends Stage implements Screen } public static float Scale() { return 10.0f; } + + public void dispose() + { + + } } diff --git a/core/src/com/mygdx/game/bodies/Ball.java b/core/src/com/mygdx/game/bodies/Ball.java index 781f5a15d6ef83f319ce842a6664fee89bd51761..326f90ae55a9527850002d1f057850298d149de6 100644 --- a/core/src/com/mygdx/game/bodies/Ball.java +++ b/core/src/com/mygdx/game/bodies/Ball.java @@ -57,6 +57,11 @@ public class Ball tb.setPosition(new Vector2(GameScreen.Width()/2f, GameScreen.Height()/2f)); } + public void dispose() + { + tb.dispose(); + } + public Vector2 getPos() { return new Vector2(tb.getX(), tb.getY()); diff --git a/core/src/com/mygdx/game/bodies/Field.java b/core/src/com/mygdx/game/bodies/Field.java index 89486df63566b909f9c0d9f4b48f0fd98b3fe122..9b8f49f0d41caeee96fefa06243794463105c3d9 100644 --- a/core/src/com/mygdx/game/bodies/Field.java +++ b/core/src/com/mygdx/game/bodies/Field.java @@ -36,6 +36,11 @@ public class Field tb = new TextureBody(Gdx.files.internal("images/Terrain.png"), world, bdef, fdef, GameScreen.Width()*0.8f, GameScreen.Height(), true); } + public void dispose() + { + tb.dispose(); + } + public Texture texture() { return tb; diff --git a/core/src/com/mygdx/game/bodies/Joystick.java b/core/src/com/mygdx/game/bodies/Joystick.java index c80bbb29ae9ed8739d101dfd42cd823d99cee874..6955170c455d7de31c02b0b3b68c9d1207375c96 100644 --- a/core/src/com/mygdx/game/bodies/Joystick.java +++ b/core/src/com/mygdx/game/bodies/Joystick.java @@ -59,6 +59,11 @@ public class Joystick return new Rectangle( (tb.getX() - tb.getW()/2)*(Gdx.graphics.getWidth()/GameScreen.Width()), (tb.getY() - tb.getH()/2)*(Gdx.graphics.getHeight()/GameScreen.Height()), tb.getW()*(Gdx.graphics.getWidth()/GameScreen.Width()), tb.getH()*(Gdx.graphics.getHeight()/GameScreen.Height())); } + public void dispose() + { + tb.dispose(); + } + public enum SIDE { LEFT, RIGHT diff --git a/core/src/com/mygdx/game/bodies/Player.java b/core/src/com/mygdx/game/bodies/Player.java index 5ae06c15991a28c6cb37007dcbb388a99ebf46e6..00f05db1fa0ea4fba152ca06df2a0628de007310 100644 --- a/core/src/com/mygdx/game/bodies/Player.java +++ b/core/src/com/mygdx/game/bodies/Player.java @@ -95,6 +95,11 @@ public class Player return ((String[])tb.getFirstFixture().getUserData())[1]; } + public void dispose() + { + tb.dispose(); + } + public enum TYPE { LEFT, RIGHT, AI