示例#1
0
  public void paint(Clock clock) {
    if (!hasLoaded) return;

    // body.setLinearVelocity(new Vec2(30 * MathUtils.cos(GameScreen.angle), 30 *
    // MathUtils.sin(GameScreen.angle)));

    sprite
        .layer()
        .setTranslation(
            (body.getPosition().x / GameScreen.M_PER_PIXEL),
            (body.getPosition().y / GameScreen.M_PER_PIXEL));
    Vec2 delta = new Vec2(80f - body.getPosition().x, 400f - body.getPosition().y);
    float angle = MathUtils.atan2(delta.x, delta.y);
    body.setLinearVelocity(new Vec2(8 * -MathUtils.cos(angle), 8 * MathUtils.sin(angle)));
  }
示例#2
0
 public void rdiver() {
   //        float a= 0.6f;
   //        float i;
   //        for(i=0f;i<a;i=i+0.001f){
   //        body.setTransform(body.getPosition(),i);}
   body.applyLinearImpulse(new Vec2(0f, 5f), body.getPosition());
 }
  @Override
  public void move(Body body) {
    Objects.requireNonNull(body);

    if (body.getLinearVelocity().x == 0) {
      Vec2 v2 = new Vec2(2.0f, 0.0f);
      body.setLinearVelocity(v2);
    }
    if (body.getPosition().x * EscapeWorld.SCALE >= 550) {
      Vec2 v2 = new Vec2(-2.0f, 0.0f);
      body.setLinearVelocity(v2);
    }
    if (body.getPosition().x * EscapeWorld.SCALE <= 90) {
      Vec2 v2 = new Vec2(2.0f, 0.0f);
      body.setLinearVelocity(v2);
    }
  }
  @Override
  public void move(Body body) {
    Objects.requireNonNull(body);

    Vec2 v2 = new Vec2(2f, 0f);
    switch (nbCall) {
      case -1:
        nbCall++;
        break;
      case 0:
        if (body.getPosition().y * EscapeWorld.SCALE > (FrontApplication.WIDTH / 3 - 120)) {
          return;
        }
        v2.set(2f, 0f);
        break;
      case 1:
        if (body.getPosition().x * EscapeWorld.SCALE < (FrontApplication.WIDTH / 3)) {
          return;
        }
        v2.set(0f, 2f);
        break;
      case 2:
        if (body.getPosition().y * EscapeWorld.SCALE < (FrontApplication.WIDTH / 3)) {
          return;
        }
        v2.set(-2f, 0f);
        break;
      case 3:
        if (body.getPosition().x * EscapeWorld.SCALE > (FrontApplication.WIDTH / 3 - 120)) {
          return;
        }
        v2.set(0f, -2f);
        break;
      default:
        throw new AssertionError();
    }

    body.setLinearVelocity(v2);
    nbCall = (nbCall + 1) % 4;
  }
示例#5
0
文件: Body.java 项目: rdo/speleo
 /**
  * Set the rotation of the body. This can only be called after the body has been added to the
  * world.
  *
  * @param rotation The new rotation of the body
  */
 public void setRotation(float rotation) {
   checkBody();
   jboxBody.setXForm(jboxBody.getPosition(), rotation);
 }
示例#6
0
文件: Body.java 项目: rdo/speleo
 /**
  * Get the Y position of the body
  *
  * @return The y position of the body
  */
 public float getY() {
   checkBody();
   return jboxBody.getPosition().y;
 }
 @Override
 public void update() {
   pos = body.getPosition();
 }
示例#8
0
 public float getY() {
   return physicalBody.getPosition().y;
 }
示例#9
0
 public float getX() {
   return physicalBody.getPosition().x;
 }
示例#10
0
 public float getX() {
   return body.getPosition().x;
 }
示例#11
0
 public float getY() {
   return body.getPosition().y;
 }
示例#12
0
  public void start() {

    Vec2 gravity = new Vec2(0, 0);
    World world = new World(gravity);
    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.position.set(0, -25);
    Body groundBody = world.createBody(groundBodyDef);
    PolygonShape groundBox = new PolygonShape();
    groundBox.setAsBox(900, 10);
    groundBody.createFixture(groundBox, 0);

    // Dynamic Body
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DYNAMIC;
    bodyDef.position.set(0, 0);
    Body body = world.createBody(bodyDef);
    PolygonShape dynamicBox = new PolygonShape();
    dynamicBox.setAsBox(12, 12);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = dynamicBox;
    fixtureDef.density = 1f;
    fixtureDef.friction = 0.3f;
    body.createFixture(fixtureDef);

    // Setup world
    float timeStep = 1.0f / 60.0f;
    int velocityIterations = 6;
    int positionIterations = 2;
    body.setLinearVelocity(new Vec2(15.0f, -15.0f));
    body.setLinearDamping(2f);
    Vec2 f = body.getWorldVector(new Vec2(0.0f, -30.0f));
    Vec2 p = body.getWorldPoint(body.getLocalCenter().add(new Vec2(-.2f, 0f)));
    // body.applyForce(new Vec2(-200,-200),new Vec2(-200,200));

    try {
      Display.setDisplayMode(new DisplayMode(screen_width, screen_height));
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    }

    lastFPS = getTime();

    // standardBall[0] = new Ball(400,200,0,12);
    // standardBall[1] = new Ball(100,210,2,12);
    // standardBall[0].addImpulse(-10,0);

    standardBall[0] = new Ball(200, 300, 0, 12);
    standardBall[1] = new Ball(415, 100, 2, 12);
    standardBall[0].addImpulse(10, -9.99f);

    standardBall[2] = new Ball(620, 270, 2, 12);
    standardBall[3] = new Ball(640, 290, 2, 12);
    standardBall[4] = new Ball(660, 310, 2, 12);
    standardBall[5] = new Ball(680, 330, 2, 12);

    standardBall[6] = new Ball(620, 230, 2, 12);
    standardBall[7] = new Ball(640, 210, 2, 12);
    standardBall[8] = new Ball(660, 190, 2, 12);
    standardBall[9] = new Ball(680, 170, 2, 12);

    standardBall[10] = new Ball(640, 250, 1, 12);
    standardBall[11] = new Ball(660, 230, 2, 12);
    standardBall[12] = new Ball(660, 270, 2, 12);
    standardBall[13] = new Ball(680, 290, 2, 12);
    standardBall[14] = new Ball(680, 210, 2, 12);
    standardBall[15] = new Ball(680, 250, 2, 12);

    standardTable = new Table(0, 0, 800, 400, 25, 15);

    // init OpenGL
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 900, 0, 500, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    while (!Display.isCloseRequested()) {
      int delta = getDelta();
      world.step(timeStep, velocityIterations, positionIterations);
      Vec2 position = body.getPosition();
      float angle = body.getAngle();
      // System.out.printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle);

      // Clear the screen and depth buffer
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

      standardTable.draw();

      for (int i = 0; i < NUMBER_OF_BALLS; i++) {
        standardBall[i].draw();
        standardBall[i].update(delta);
      }
      standardBall[0].setX((position.x * 20) + offset_x);
      standardBall[0].setY((position.y * 20) + offset_y);

      update(delta);

      Display.update();

      Display.sync(60);
    }
    Display.destroy();
  }