use of org.jbox2d.dynamics.World in project HackerHop by nicovank.
the class PlayerTest method playerShapeTest.
@Test
void playerShapeTest() {
World world = new World(new Vec2(0, -50));
Vec2 position = new Vec2(0, 10);
Player p = new Player(world, position);
Shape s = p.getBody().getFixtureList().m_shape;
PolygonShape r = new PolygonShape();
r.setAsBox(3, 3);
assertEquals(s.getType(), r.getType());
}
use of org.jbox2d.dynamics.World in project Bytecoder by mirkosertic.
the class JBox2DTest method testSimpleBall.
@Test
public void testSimpleBall() {
World world = new World(new Vec2(0, -9.8f));
float ballRadius = 0.15f;
BodyDef ballDef = new BodyDef();
ballDef.type = BodyType.DYNAMIC;
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.friction = 0.3f;
fixtureDef.restitution = 0.3f;
fixtureDef.density = 0.2f;
CircleShape shape = new CircleShape();
shape.m_radius = ballRadius;
fixtureDef.shape = shape;
int i = 0;
int j = 0;
float x = (j + 0.5f) * (ballRadius * 2 + 0.01f);
float y = (i + 0.5f) * (ballRadius * 2 + 0.01f);
ballDef.position.x = 3 + x;
ballDef.position.y = 3 + y;
Body theBall = world.createBody(ballDef);
theBall.createFixture(fixtureDef);
for (int k = 0; k < 100; k++) {
world.step(0.01f, 20, 40);
}
Vec2 thePosition = theBall.getPosition();
int theX = (int) (thePosition.x * 1000);
int theY = (int) (thePosition.y * 1000);
System.out.println("Finally ended at ");
System.out.println(theX);
System.out.println(theY);
}
use of org.jbox2d.dynamics.World in project HackerHop by nicovank.
the class PlayerTest method floorExistsTest.
@Test
void floorExistsTest() {
World world = new World(new Vec2(0, -50));
Vec2 position = new Vec2(0, 10);
Player p = new Player(world, position);
world.step(100, 6, 2);
float x = p.getBody().getPosition().x;
float y = p.getBody().getPosition().y;
assertTrue(x >= 0 && x <= 54);
assertTrue(y >= 0 && y <= 72);
}
use of org.jbox2d.dynamics.World in project HackerHop by nicovank.
the class PlayerTest method startingPositionTest.
// testing player position at the start of the game.
@Test
void startingPositionTest() {
World world = new World(new Vec2(0, -50));
Vec2 position = new Vec2(0, 10);
Player p = new Player(world, position);
float x = position.x;
float y = position.y;
assertEquals(0, x);
assertEquals(10, y);
}
Aggregations