Skip to content
Snippets Groups Projects
Commit 794d88a4 authored by ALGLAVE Ivan's avatar ALGLAVE Ivan
Browse files

Fixed position to displaying objects as being centered with coordinates, added...

Fixed position to displaying objects as being centered with coordinates, added joysticks - non functionnal
parent fbae6088
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ import com.badlogic.gdx.physics.box2d.Shape; ...@@ -17,6 +17,7 @@ import com.badlogic.gdx.physics.box2d.Shape;
import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.physics.box2d.World;
import com.mygdx.game.bodies.Ball; import com.mygdx.game.bodies.Ball;
import com.mygdx.game.bodies.Field; import com.mygdx.game.bodies.Field;
import com.mygdx.game.bodies.Joystick;
import com.mygdx.game.bodies.Player; import com.mygdx.game.bodies.Player;
/** /**
...@@ -29,6 +30,7 @@ public class GamePlay extends GameScreen ...@@ -29,6 +30,7 @@ public class GamePlay extends GameScreen
Player pleft, pright; Player pleft, pright;
Field field; Field field;
World world; World world;
Joystick jleft, jright;
Box2DDebugRenderer b2dd; Box2DDebugRenderer b2dd;
...@@ -40,6 +42,8 @@ public class GamePlay extends GameScreen ...@@ -40,6 +42,8 @@ public class GamePlay extends GameScreen
ball = new Ball(world, new Vector2(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f)); ball = new Ball(world, new Vector2(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f));
pleft = new Player(world, Player.TYPE.LEFT); pleft = new Player(world, Player.TYPE.LEFT);
pright = new Player(world, Player.TYPE.RIGHT); pright = new Player(world, Player.TYPE.RIGHT);
jleft = new Joystick(world, Joystick.SIDE.LEFT);
jright = new Joystick(world, Joystick.SIDE.RIGHT);
} }
@Override @Override
...@@ -54,6 +58,10 @@ public class GamePlay extends GameScreen ...@@ -54,6 +58,10 @@ public class GamePlay extends GameScreen
ball.draw(batch); ball.draw(batch);
jleft.draw(batch);
jright.draw(batch);
world.step(delta, 1, 1); world.step(delta, 1, 1);
super.render(delta); super.render(delta);
......
...@@ -20,7 +20,7 @@ public class Field ...@@ -20,7 +20,7 @@ public class Field
BodyDef bdef = new BodyDef(); BodyDef bdef = new BodyDef();
bdef.type = BodyDef.BodyType.StaticBody; bdef.type = BodyDef.BodyType.StaticBody;
bdef.active = false; bdef.active = false;
bdef.position.set(Gdx.graphics.getWidth()*0.1f, 0); bdef.position.set(Gdx.graphics.getWidth()*0.5f, Gdx.graphics.getHeight()*0.5f);
FixtureDef fdef = new FixtureDef(); FixtureDef fdef = new FixtureDef();
......
package com.mygdx.game.bodies;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.World;
public class Joystick
{
private TextureBody tb;
public Joystick(World world, SIDE side)
{
BodyDef bdef = new BodyDef();
bdef.type = BodyDef.BodyType.StaticBody;
Vector2 pos = side == SIDE.RIGHT ? new Vector2(Gdx.graphics.getWidth()*0.95f, Gdx.graphics.getHeight()/2f) : new Vector2(Gdx.graphics.getWidth()*0.05f, Gdx.graphics.getHeight()/2f);
bdef.position.set(pos);
FixtureDef fdef = new FixtureDef();
CircleShape cs = new CircleShape();
cs.setRadius(Gdx.graphics.getWidth() * (1f/40f));
fdef.shape = cs;
fdef.density = 0f;
fdef.restitution = 0f;
fdef.friction = 0f;
bdef.active = false;
tb = new TextureBody(Gdx.files.internal( "images/Pad.png"), world, bdef, fdef, Gdx.graphics.getWidth()*0.1f, Gdx.graphics.getWidth()*0.1f);
}
public void draw(SpriteBatch batch)
{
tb.draw(batch);
}
public enum SIDE
{
LEFT, RIGHT
}
}
...@@ -27,6 +27,6 @@ public class TextureBody extends Texture ...@@ -27,6 +27,6 @@ public class TextureBody extends Texture
public void draw(SpriteBatch batch) public void draw(SpriteBatch batch)
{ {
batch.draw(this, body.getPosition().x, body.getPosition().y, width, height); batch.draw(this, body.getPosition().x - width/2f, body.getPosition().y - height/2f, width, height);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment