diff --git a/core/src/com/mygdx/game/GameScreens/GameIntro.java b/core/src/com/mygdx/game/GameScreens/GameIntro.java index 142da8e6ae32d793b9e81d0280cf3618f098e938..2dc0c4c25afaf502350159363e4244afbd144742 100644 --- a/core/src/com/mygdx/game/GameScreens/GameIntro.java +++ b/core/src/com/mygdx/game/GameScreens/GameIntro.java @@ -18,18 +18,14 @@ import java.util.Date; public class GameIntro extends GameScreen { BitmapFont bf = new BitmapFont(); - long creationDate; Texture intro; String s; @Override - public void buildStage() { - /*Label l = new Label("Intro screen", FontManager.getInstance().getLabelStyle(Color.BLACK)); - l.setPosition(50, 50); - addActor(l);*/ - creationDate = System.currentTimeMillis(); + public void buildStage() + { bf.setColor(Color.RED); intro = new Texture(Gdx.files.internal("images/Intro.jpg")); @@ -42,7 +38,7 @@ public class GameIntro extends GameScreen batch.draw(intro, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); - if(System.currentTimeMillis() - creationDate > 2000) + if(System.currentTimeMillis() - creationDate > 3000) { // Intro screen is over GameScreenManager.getInstance().showGameScreen(GameScreenEnum.GAME_MENU); diff --git a/core/src/com/mygdx/game/GameScreens/GameMenu.java b/core/src/com/mygdx/game/GameScreens/GameMenu.java index cc91c4830abdbd0416b5db4a28eef92d70405112..d15e2aecfbec8ab44c5e42816ad846c8d9e74196 100644 --- a/core/src/com/mygdx/game/GameScreens/GameMenu.java +++ b/core/src/com/mygdx/game/GameScreens/GameMenu.java @@ -24,6 +24,11 @@ public class GameMenu extends GameScreen batch.draw(menu, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + if(totalElapsedSeconds() > 3) + { + GameScreenManager.getInstance().showGameScreen(GameScreenEnum.GAME_PLAY); + } + super.render(delta); } } diff --git a/core/src/com/mygdx/game/GameScreens/GamePlay.java b/core/src/com/mygdx/game/GameScreens/GamePlay.java index 43f1d9138552c82c0dd48c1f9c38291df1bd148a..0cab30e1b39843ea301845b3fe485a83530ba305 100644 --- a/core/src/com/mygdx/game/GameScreens/GamePlay.java +++ b/core/src/com/mygdx/game/GameScreens/GamePlay.java @@ -3,6 +3,18 @@ package com.mygdx.game.GameScreens; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +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.Fixture; +import com.badlogic.gdx.physics.box2d.FixtureDef; +import com.badlogic.gdx.physics.box2d.Shape; +import com.badlogic.gdx.physics.box2d.World; /** * Gameplay screen, allowing the user to play against an IA or another player on a shared screen @@ -10,14 +22,62 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; */ public class GamePlay extends GameScreen { + Texture game_field, pad_left, pad_right, goal_left, goal_right, player_left, player_right, ball; + World world; + Body b_ball; + + Box2DDebugRenderer b2dd; + @Override - public void buildStage() { + public void buildStage() + { + game_field = new Texture(Gdx.files.internal("images/Terrain.png")); + pad_left = new Texture(Gdx.files.internal("images/Pad.png")); + pad_right = new Texture(Gdx.files.internal("images/Pad.png")); + goal_left = new Texture(Gdx.files.internal("images/But.bmp")); + goal_right = new Texture(Gdx.files.internal("images/But.bmp")); + player_left = new Texture(Gdx.files.internal("images/JoueurGauche.png")); + player_right = new Texture(Gdx.files.internal("images/JoueurDroite.png")); + ball = new Texture(Gdx.files.internal("images/Ballon.png")); + + world = new World(new Vector2(0, 0), true); + + BodyDef bd_ball = new BodyDef(); + bd_ball.type = BodyDef.BodyType.DynamicBody; + bd_ball.position.set(width()/2, height()/2); + + b_ball = world.createBody(bd_ball); + + FixtureDef fd_ball = new FixtureDef(); + fd_ball.shape = new CircleShape(); + fd_ball.shape.setRadius((1/85f) * width()); + + Fixture f = b_ball.createFixture(fd_ball); + + b2dd = new Box2DDebugRenderer(); } @Override public void render(float delta) { beforeRender(); + batch.draw(game_field, width()*0.1f, 0, width()*0.8f, height()); + + batch.draw(ball, b_ball.getPosition().x, b_ball.getPosition().y, (1/85f)*width(), (1/85f)*width()); + //b2dd.render(world, getCamera().combined); + + world.step(delta, 1, 1); + super.render(delta); } + + private float width() + { + return Gdx.graphics.getWidth(); + } + + private float height() + { + return Gdx.graphics.getHeight(); + } } diff --git a/core/src/com/mygdx/game/GameScreens/GameScreen.java b/core/src/com/mygdx/game/GameScreens/GameScreen.java index 472ad2197d2e561d3fdf35e5833c16701abc1d35..4778e693597f68a2976f71500a8675f76ee29c4d 100644 --- a/core/src/com/mygdx/game/GameScreens/GameScreen.java +++ b/core/src/com/mygdx/game/GameScreens/GameScreen.java @@ -15,9 +15,11 @@ public abstract class GameScreen extends Stage implements Screen { SpriteBatch batch = new SpriteBatch(); + long creationDate; protected GameScreen() { - super( new StretchViewport(320.0f, 240.0f, new OrthographicCamera()) ); + super( new StretchViewport(102.4f, 76.8f, new OrthographicCamera()) ); + creationDate = System.currentTimeMillis(); } /** @@ -55,4 +57,9 @@ public abstract class GameScreen extends Stage implements Screen @Override public void hide() {} @Override public void pause() {} @Override public void resume() {} + + public long totalElapsedSeconds() + { + return (System.currentTimeMillis() - creationDate) / 1000; + } }