Search in sources :

Example 6 with World

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());
}
Also used : PolygonShape(org.jbox2d.collision.shapes.PolygonShape) PolygonShape(org.jbox2d.collision.shapes.PolygonShape) Shape(org.jbox2d.collision.shapes.Shape) Vec2(org.jbox2d.common.Vec2) World(org.jbox2d.dynamics.World) Test(org.junit.jupiter.api.Test)

Example 7 with World

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);
}
Also used : CircleShape(org.jbox2d.collision.shapes.CircleShape) Vec2(org.jbox2d.common.Vec2) World(org.jbox2d.dynamics.World) BodyDef(org.jbox2d.dynamics.BodyDef) Body(org.jbox2d.dynamics.Body) FixtureDef(org.jbox2d.dynamics.FixtureDef) ManifoldPoint(org.jbox2d.collision.ManifoldPoint) Test(org.junit.Test)

Example 8 with World

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);
}
Also used : Vec2(org.jbox2d.common.Vec2) World(org.jbox2d.dynamics.World) Test(org.junit.jupiter.api.Test)

Example 9 with World

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);
}
Also used : Vec2(org.jbox2d.common.Vec2) World(org.jbox2d.dynamics.World) Test(org.junit.jupiter.api.Test)

Aggregations

Vec2 (org.jbox2d.common.Vec2)9 World (org.jbox2d.dynamics.World)9 Test (org.junit.jupiter.api.Test)6 Test (org.junit.Test)3 CircleShape (org.jbox2d.collision.shapes.CircleShape)2 Body (org.jbox2d.dynamics.Body)2 BodyDef (org.jbox2d.dynamics.BodyDef)2 Platform (com.hackerhop.game.core.objects.platforms.Platform)1 ManifoldPoint (org.jbox2d.collision.ManifoldPoint)1 PolygonShape (org.jbox2d.collision.shapes.PolygonShape)1 Shape (org.jbox2d.collision.shapes.Shape)1 FixtureDef (org.jbox2d.dynamics.FixtureDef)1