Пример #1
0
  @Override
  public boolean onSceneTouchEvent(TouchEvent pSceneTouchEvent) {

    if (pSceneTouchEvent.isActionDown() && !personajeSaltando) {
      personajeSaltando = true;
      // Animar sprite central
      JumpModifier salto =
          new JumpModifier(
              1,
              spritePersonaje.getX(),
              spritePersonaje.getX(),
              spritePersonaje.getY(),
              spritePersonaje.getY(),
              -200);
      RotationModifier rotacion = new RotationModifier(1, 360, 0);
      ParallelEntityModifier paralelo =
          new ParallelEntityModifier(salto, rotacion) {
            @Override
            protected void onModifierFinished(IEntity pItem) {
              personajeSaltando = false;
              unregisterEntityModifier(this);
              super.onModifierFinished(pItem);
            }
          };
      spritePersonaje.registerEntityModifier(paralelo);
    }

    if (pSceneTouchEvent.isActionDown()) {
      // El usuario toca la pantalla
      float x = pSceneTouchEvent.getX();
      float y = pSceneTouchEvent.getY();
      spritePersonaje.setPosition(x, y);
    }
    if (pSceneTouchEvent.isActionMove()) {
      // El usuario mueve el dedo sobre la pantalla
      float x = pSceneTouchEvent.getX();
      float y = pSceneTouchEvent.getY();
      spritePersonaje.setPosition(x, y);
    }
    if (pSceneTouchEvent.isActionUp()) {
      // El usuario deja de tocar la pantalla
    }

    return super.onSceneTouchEvent(pSceneTouchEvent);
  }
Пример #2
0
  public void updatePlayerPosition(float newPlayerPositionX, float newPlayerPositionY) {
    //		playerSprite.setPosition(newPlayerPositionX, newPlayerPositionY);
    if (oldPlayerPositionX < newPlayerPositionX && oldPlayerPositionY < newPlayerPositionY) {
      if (playerSprite.getX() < newPlayerPositionX) {
        if (playerSprite.getY() < newPlayerPositionY) {
          playerSprite.setPosition(playerSprite.getX() + 2, playerSprite.getY() + 2);
        } else if (playerSprite.getY() > newPlayerPositionY) {
          playerSprite.setPosition(playerSprite.getX() + 2, playerSprite.getY() - 2);
        } else {
          isPlayerMoving = false;
        }

      } else if (playerSprite.getX() > newPlayerPositionX) {
        if (playerSprite.getY() < newPlayerPositionY) {
          playerSprite.setPosition(playerSprite.getX() - 2, playerSprite.getY() + 2);
        } else if (playerSprite.getY() > newPlayerPositionY) {
          playerSprite.setPosition(playerSprite.getX() - 2, playerSprite.getY() - 2);
        } else {
          isPlayerMoving = false;
        }
      }
    }
  }
Пример #3
0
  @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);
  }
Пример #4
0
  @Override
  public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
    // TODO Auto-generated method stub

    this.mEngine.registerUpdateHandler(new FPSLogger());

    // createPopUpMenuScene();
    createStaticMenuScene();
    sprBanana = new AnimatedSprite(0, 0, regBanana, this.getVertexBufferObjectManager());
    sprBanana.setPosition(140, 120);

    this.mainMenuScene = new Scene();
    this.mainMenuScene.setBackground(new Background(0, 0, 0));

    Sprite menuBack =
        new Sprite(0, 0, this.mMenuTextureRegion, this.getVertexBufferObjectManager());

    this.mainMenuScene.attachChild(menuBack);
    this.mainMenuScene.getLastChild().attachChild(sprBanana);
    sprBanana.animate(100);
    this.mainMenuScene.setChildScene(mStaticMenuScene);
    pOnCreateSceneCallback.onCreateSceneFinished(mainMenuScene);
  }
  public void createExplosion(float x, float y, float radius, float damage, boolean harmPlayer) {

    final float X = x, Y = y;

    final HashMap<Character, Float> CHARACTERS_IN_RANGE = new HashMap<Character, Float>();

    for (final Zombie z : Zombie.getAliveZombies())
      this.onExplosionCheckCharacterCollision(x, y, radius, z, CHARACTERS_IN_RANGE);

    if (harmPlayer)
      this.onExplosionCheckCharacterCollision(x, y, radius, this.pPlayer, CHARACTERS_IN_RANGE);

    final Iterator<Character> CHARACTER_ITERATOR = CHARACTERS_IN_RANGE.keySet().iterator();
    final Iterator<Float> DAMAGE_ITERATOR = CHARACTERS_IN_RANGE.values().iterator();

    while (CHARACTER_ITERATOR.hasNext()) {

      final Character CHAR = CHARACTER_ITERATOR.next();
      final Float DAMAGE = DAMAGE_ITERATOR.next();

      CHAR.setHealthAmount((int) (CHAR.getHealthAmount() - damage * DAMAGE));

      if (CHAR.getHealthAmount() <= 0) AchievementsManager.incrementZombiesKilledByExplosion();
    }

    final ITiledTextureRegion EXPLOSION_TEXTURE = HudRegions.region_explosion;
    final AnimatedSprite EXPLOSION =
        new AnimatedSprite(
            x, y, EXPLOSION_TEXTURE, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager());

    if (this.explosionCount == 0) EXPLOSION_TEXTURE.getTexture().load();

    EXPLOSION.setScaleCenter(0, 0);
    EXPLOSION.setScale(2f);
    EXPLOSION.setPosition(
        EXPLOSION.getX() - EXPLOSION.getWidthScaled() / 2f,
        EXPLOSION.getY() - EXPLOSION.getHeightScaled() / 2f);
    EXPLOSION.setZIndex(this.getLevel().getMapHeight());
    this.attachChild(EXPLOSION);
    this.explosionCount++;

    EXPLOSION.animate(
        30L,
        false,
        new IAnimationListener() {
          private boolean usedEffects;

          @Override
          public void onAnimationFinished(AnimatedSprite pAnimatedSprite) {
            EnvironmentVars.MAIN_CONTEXT.runOnUpdateThread(
                new Runnable() {
                  @Override
                  public void run() {
                    SessionScene.this.explosionCount--;
                    if (SessionScene.this.explosionCount == 0)
                      EXPLOSION_TEXTURE.getTexture().unload();
                    EXPLOSION.detachSelf();
                    EXPLOSION.dispose();
                  }
                });
          }

          @Override
          public void onAnimationFrameChanged(
              AnimatedSprite pAnimatedSprite, int pOldFrameIndex, int pNewFrameIndex) {

            if (pNewFrameIndex >= 3)
              if (!this.usedEffects) {
                SessionScene.this.createExplosionMark(X, Y);
                SessionScene.this.onExplosionCreateSmoke(X, Y);
                this.usedEffects = true;
              }
          }

          @Override
          public void onAnimationLoopFinished(
              AnimatedSprite pAnimatedSprite, int pRemainingLoopCount, int pInitialLoopCount) {}

          @Override
          public void onAnimationStarted(AnimatedSprite pAnimatedSprite, int pInitialLoopCount) {}
        });

    this.getCameraManager().shakeRandomDirection();

    SessionScene.EXPLOSION_SOUND.play();
  }