diff --git a/core/src/com/mygdx/game/GameScreens/GamePlay.java b/core/src/com/mygdx/game/GameScreens/GamePlay.java index 6dc8db24261dc260af0693ad0601199349df3bb5..311bf378905f810d4f690bc2ef347d21a3c10e7c 100644 --- a/core/src/com/mygdx/game/GameScreens/GamePlay.java +++ b/core/src/com/mygdx/game/GameScreens/GamePlay.java @@ -2,12 +2,15 @@ package com.mygdx.game.GameScreens; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; +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; @@ -25,6 +28,7 @@ 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; +import com.mygdx.game.bodies.FieldBounds; import com.mygdx.game.bodies.Goal; import com.mygdx.game.bodies.Joystick; import com.mygdx.game.bodies.Player; @@ -38,13 +42,16 @@ public class GamePlay extends GameScreen Ball ball; Player pleft, pright; Field field; + FieldBounds fieldBounds; World world; Joystick jleft, jright; Goal gleft, gright; BitmapFont font; + OrthographicCamera camera; Box2DDebugRenderer b2dd; + Matrix4 debugMatrix; int scoreLeft, scoreRight; long duration; @@ -53,8 +60,14 @@ public class GamePlay extends GameScreen @Override public void buildStage() { + b2dd = new Box2DDebugRenderer(); + camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + debugMatrix = new Matrix4(camera.combined); + world = new World(new Vector2(0, 0), true); field = new Field(world); + fieldBounds = new FieldBounds(world); ball = new Ball(world, new Vector2(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f)); pleft = new Player(world, Player.TYPE.LEFT); pright = new Player(world, Player.TYPE.RIGHT); @@ -88,25 +101,25 @@ public class GamePlay extends GameScreen { if(ba.getUserData() instanceof Ball && bb.getUserData() instanceof Goal) { - Goal goal = (Goal)bb.getUserData(); + /*Goal goal = (Goal)bb.getUserData(); if(goal.side == Goal.SIDE.LEFT) { score(pright); } else { score(pleft); - } + }*/ } else if(bb.getUserData() instanceof Ball && ba.getUserData() instanceof Goal) { - Goal goal = (Goal)ba.getUserData(); + /*Goal goal = (Goal)ba.getUserData(); if(goal.side == Goal.SIDE.LEFT) { score(pright); } else { score(pleft); - } + }*/ } } } @@ -139,24 +152,19 @@ public class GamePlay extends GameScreen } 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)); - 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); + world.step(delta, 1, 1); super.render(delta); diff --git a/core/src/com/mygdx/game/GameScreens/GameScreen.java b/core/src/com/mygdx/game/GameScreens/GameScreen.java index 4778e693597f68a2976f71500a8675f76ee29c4d..d85fe99cf147fc9fcf4a1900397fcad3e9e9e43b 100644 --- a/core/src/com/mygdx/game/GameScreens/GameScreen.java +++ b/core/src/com/mygdx/game/GameScreens/GameScreen.java @@ -30,8 +30,8 @@ public abstract class GameScreen extends Stage implements Screen protected void beforeRender() { // Clear screen - Gdx.gl.glClearColor(0, 0, 0, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + //Gdx.gl.glClearColor(0, 0, 0, 1); + //Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); } diff --git a/core/src/com/mygdx/game/bodies/Ball.java b/core/src/com/mygdx/game/bodies/Ball.java index ff998eb56f438828919205781506a846dbe1060f..5583eeb2e494b2459b18e8db5470ee48823d3931 100644 --- a/core/src/com/mygdx/game/bodies/Ball.java +++ b/core/src/com/mygdx/game/bodies/Ball.java @@ -23,14 +23,14 @@ public class Ball FixtureDef fdef = new FixtureDef(); CircleShape cs = new CircleShape(); - cs.setRadius(Gdx.graphics.getWidth() * (1f/85f)); + cs.setRadius(Gdx.graphics.getWidth() * (1f/85f) / 2f); fdef.shape = cs; fdef.density = 1f; fdef.restitution = 0.5f; fdef.friction = 1.5f; - tb = new TextureBody(Gdx.files.internal("images/Ballon.png"), world, bdef, fdef, cs.getRadius(), cs.getRadius()); + tb = new TextureBody(Gdx.files.internal("images/Ballon.png"), world, bdef, fdef, cs.getRadius()*2, cs.getRadius()*2); tb.body.setUserData(this); } diff --git a/core/src/com/mygdx/game/bodies/FieldBounds.java b/core/src/com/mygdx/game/bodies/FieldBounds.java new file mode 100644 index 0000000000000000000000000000000000000000..6a6c3c076a8867d3ab0ff4ec45d63a0f6db1361a --- /dev/null +++ b/core/src/com/mygdx/game/bodies/FieldBounds.java @@ -0,0 +1,50 @@ +package com.mygdx.game.bodies; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.physics.box2d.Body; +import com.badlogic.gdx.physics.box2d.BodyDef; +import com.badlogic.gdx.physics.box2d.FixtureDef; +import com.badlogic.gdx.physics.box2d.PolygonShape; +import com.badlogic.gdx.physics.box2d.World; + +public class FieldBounds +{ + Body bodies[]; + + public FieldBounds(World world) + { + float vertices[] = {7.52f, 15.63f, 8.79f, 13.93f, 91.11f, 13.93f, 92.38f, 15.63f, 92.38f, 41.14f, 96.29f, 41.15f, 96.29f, 54.04f, 92.38f, 54.04f, 92.38f, 84.24f, 91.11f, 85.94f, 8.79f, 85.94f, 7.52f, 84.24f, 7.52f, 54.04f, 3.61f, 54.04f, 3.61f, 41.15f, 7.52f, 41.15f}; + bodies = new Body[vertices.length/2]; + for(int i = 0; i < vertices.length/2; i++) + { + float w = Gdx.graphics.getWidth()*0.8f; + float h = Gdx.graphics.getHeight(); + float x_off = Gdx.graphics.getWidth()*0.1f; + + float ox = (vertices[(i*2)%vertices.length]/100f)*w+x_off ; + float oy = (vertices[((i*2)+1)%vertices.length]/100f)*h; + float dx = (vertices[((i+1)*2)%vertices.length]/100f)*w+x_off; + float dy = (vertices[(((i+1)*2)+1)%vertices.length]/100f)*h; + + float v[] = {ox, oy, ox+0.1f, oy+0.1f, dx, dy, dx+0.1f, dy+0.1f}; + + BodyDef bdef = new BodyDef(); + bdef.type = BodyDef.BodyType.StaticBody; + + bdef.position.set(0, 0); + + FixtureDef fdef = new FixtureDef(); + + PolygonShape ps = new PolygonShape(); + ps.set(v); + + fdef.shape = ps; + fdef.density = 0f; + fdef.restitution = 0f; + fdef.friction = 0f; + + bodies[i] = world.createBody(bdef); + bodies[i].createFixture(fdef); + } + } +} diff --git a/core/src/com/mygdx/game/bodies/Goal.java b/core/src/com/mygdx/game/bodies/Goal.java index 232876628947dd67389db8f87b8fad057c4cf07c..4f943fbeee2b7dd08f2117f0a2484023e3e45d60 100644 --- a/core/src/com/mygdx/game/bodies/Goal.java +++ b/core/src/com/mygdx/game/bodies/Goal.java @@ -21,7 +21,7 @@ public class Goal { BodyDef bdef = new BodyDef(); bdef.type = BodyDef.BodyType.StaticBody; - float offset = Gdx.graphics.getWidth() * (1f/80); + float offset = Gdx.graphics.getWidth() * (1f/20); Vector2 pos = side == Goal.SIDE.RIGHT ? new Vector2(Gdx.graphics.getWidth()*0.90f - offset, Gdx.graphics.getHeight()/2f) : new Vector2(Gdx.graphics.getWidth()*0.10f + offset, Gdx.graphics.getHeight()/2f); bdef.position.set(pos); @@ -30,7 +30,7 @@ public class Goal FixtureDef fdef = new FixtureDef(); PolygonShape ps = new PolygonShape(); - ps.setAsBox(Gdx.graphics.getWidth() * (1f/40), Gdx.graphics.getHeight() * 0.2f); + ps.setAsBox(Gdx.graphics.getWidth() * (1f/120), Gdx.graphics.getHeight() * 0.1f); fdef.shape = ps; fdef.density = 0f; diff --git a/core/src/com/mygdx/game/bodies/Player.java b/core/src/com/mygdx/game/bodies/Player.java index c4c15b86b211a5c675373f5d26c06165986925a7..94cd066ce8167b5bab1db00bf632bf0dd5b1e196 100644 --- a/core/src/com/mygdx/game/bodies/Player.java +++ b/core/src/com/mygdx/game/bodies/Player.java @@ -25,7 +25,7 @@ public class Player FixtureDef fdef = new FixtureDef(); CircleShape cs = new CircleShape(); - cs.setRadius(Gdx.graphics.getWidth() * (1f/40f)); + cs.setRadius(Gdx.graphics.getWidth() * (1f/40f) / 2f); fdef.shape = cs; fdef.density = 1f; @@ -34,7 +34,7 @@ public class Player type = playerType; - tb = new TextureBody(Gdx.files.internal( "images/Joueur" + (playerType == TYPE.RIGHT ? "Droite" : "Gauche") + ".png"), world, bdef, fdef, cs.getRadius(), cs.getRadius()); + tb = new TextureBody(Gdx.files.internal( "images/Joueur" + (playerType == TYPE.RIGHT ? "Droite" : "Gauche") + ".png"), world, bdef, fdef, cs.getRadius()*2, cs.getRadius()*2); } public Texture texture() diff --git a/core/src/com/mygdx/game/bodies/TextureBody.java b/core/src/com/mygdx/game/bodies/TextureBody.java index 7fd02324c942bd2cccb31e6746c0bd731f4f6650..225141e4f8097b5b91d025ec1fee600ca88b6255 100644 --- a/core/src/com/mygdx/game/bodies/TextureBody.java +++ b/core/src/com/mygdx/game/bodies/TextureBody.java @@ -21,14 +21,12 @@ public class TextureBody extends Texture width = w; height = h; - bdef.position.x -= w/2f; - bdef.position.y -= h/2f; body = world.createBody(bdef); fixture = body.createFixture(fdef); } public void draw(SpriteBatch batch) { - batch.draw(this, body.getPosition().x, body.getPosition().y, width, height); + batch.draw(this, body.getPosition().x - width/2, body.getPosition().y - height/2, width, height); } }