Beispiel #1
0
 /** Returns the distance between this entity and the given entity in pixels. */
 public float getDistancePixels(Entity other) {
   Vector2 thisPos = getCenter();
   Vector2 otherPos = other.getCenter();
   float distance = thisPos.dst(otherPos);
   Vector2Pool.recycle(thisPos);
   Vector2Pool.recycle(otherPos);
   return distance;
 }
  private int indexOfRightmostVertexOf(final Vector2 pVector) {
    final Vector2[] vertices = this.mVertices;
    final int vertexCount = this.mVertexCount;

    int i = 0;
    for (int j = 1; j < vertexCount; j++) {

      final Vector2 vector2A = Vector2Pool.obtain().set(vertices[j]);
      final Vector2 vector2B = Vector2Pool.obtain().set(vertices[i]);
      if (Vector2Util.isLess(vector2A.sub(pVector), vector2B.sub(pVector))) {
        i = j;
      }
      Vector2Pool.recycle(vector2A);
      Vector2Pool.recycle(vector2B);
    }
    return i;
  }
  private void jumpMario(final AnimatedSprite face) {
    final Body faceBody = (Body) face.getUserData();

    // float bufX = mario.getX();
    // float bufY = mario.getY();
    // mario.setVisible(false);
    // mario = marioJump;
    // mario.setPosition(bufX, bufY);
    // mario.setVisible(true);

    final Vector2 velocity =
        Vector2Pool.obtain(this.mGravityX * -1, (float) (this.mGravityY * -0.7));
    faceBody.setLinearVelocity(velocity);
    Vector2Pool.recycle(velocity);
  }
  @Override
  public void onAccelerometerChanged(final AccelerometerData pAccelerometerData) {
    this.mGravityX = pAccelerometerData.getX();
    this.mGravityY = pAccelerometerData.getY();

    if (pAccelerometerData.getX() > 0) {
      marioMoveRight = true;
      marioMoveLeft = false;
      marioStand = false;
    } else if (pAccelerometerData.getX() == 0) {
      marioMoveLeft = false;
      marioMoveRight = false;
      marioStand = true;
    } else if (pAccelerometerData.getX() < 0) {
      marioStand = false;
      marioMoveLeft = true;
      marioMoveRight = false;
    }

    float bufX = mario.getX();
    float bufY = mario.getY();

    if (marioMoveLeft && mario != marioLeft) {
      mario.setVisible(false);
      mario = marioLeft;
    } else if (marioMoveRight && mario != marioRight) {
      mario.setVisible(false);
      mario = marioRight;
    } else if (marioStand) {
      mario.setVisible(false);
    }
    mario.setPosition(bufX, bufY);
    mario.setVisible(true);

    final Vector2 gravity = Vector2Pool.obtain(this.mGravityX * 5, this.mGravityY);
    this.mPhysicsWorld.setGravity(gravity);
    Vector2Pool.recycle(gravity);
  }
 public void newEvent(float pX, float pY, int pSlot) {
   mCubicChooseSpite[TYPE].setVisible(false);
   SLOT = pSlot;
   CUBIC_SLOT[SLOT] = true;
   checkArrow();
   this.setPosition(0, 100);
   ACTION = ACTION_DEFAULT;
   mCubicStartAniSprite.setVisible(true);
   mScrollLeftSprite.clearEntityModifiers();
   mScrollLeftSprite.registerEntityModifier(
       new LoopEntityModifier(
           new SequenceEntityModifier(
               new AlphaModifier(0.5f, 0.2f, 1.0f), new AlphaModifier(0.5f, 1.0f, 0.2f))));
   mScrollLeftSprite.setVisible(true);
   this.setVisible(true);
   final Body body = (Body) CubicEntity.this.getUserData();
   Vector2 vector2 =
       Vector2Pool.obtain(
           pX / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT,
           pY / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);
   body.setTransform(vector2, 0);
   Vector2Pool.recycle(vector2);
 }
 @Override
 public void onAccelerationChanged(AccelerationData pAccelerationData) {
   final Vector2 gravity = Vector2Pool.obtain(pAccelerationData.getX(), pAccelerationData.getY());
   this.mPhysicsWorld.setGravity(gravity);
   Vector2Pool.recycle(gravity);
 }