protected void createInvSprite(ITiledTextureRegion sheet) {

    final float w = this.getWidth();
    final float h = this.getHeight();
    final float sw = sheet.getWidth();
    final float sh = sheet.getHeight();

    this.sInvSprite =
        new TiledSprite(
            (w - sw) / 2f,
            (h - sh) / 2f,
            sheet,
            EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager());
    this.sInvSprite.setRotationCenter(sw / 2f, sh / 2f);
    this.sInvSprite.setRotation(Inventory.INVENTORY_ICON_ROTATION);
  }
Exemple #2
0
    /*
     * Attach the LevelTile's text to itself based on whether it's locked or
     * not. If not, then the level number will be displayed on the level
     * tile.
     */
    public void attachStar() {

      /* Determine the tile's string based on whether it's locked or not*/
      if (this.mIsLocked) {
        mStar.setCurrentTileIndex(0);

      } else {
        mStar.setCurrentTileIndex(mNumStars);
      }

      /* Setup the text position to be placed in the center-bottom of the tile */
      final float starPositionX = LevelSelector.this.TILE_DIMENSION / 6 + 5;
      final float starPositionY = LevelSelector.this.TILE_DIMENSION - 15;

      /* Attach the mStar to the LevelTile */
      StarSprite =
          new Sprite(0, 0, mStar, LevelSelector.this.mEngine.getVertexBufferObjectManager());
      this.attachChild(StarSprite);
      StarSprite.setPosition(starPositionX, starPositionY + 15);
    }
    public CubicEntity(
        float pX,
        float pY,
        int pCubic,
        final ITiledTextureRegion pCubicStart,
        final ITiledTextureRegion pCubicTurn,
        final ITiledTextureRegion pCubicStop,
        final ITiledTextureRegion pCubicTurnOption[],
        ITextureRegion pTextureRegion) {
      super(pX, pY, pTextureRegion, mVertexBufferObjectManager);
      setAlpha(0.0f);
      TYPE = pCubic;
      mCubicStartAniSprite = new AnimatedSprite(0, 0, pCubicStart, mVertexBufferObjectManager);
      this.attachChild(mCubicStartAniSprite);
      mCubicStartAniSprite.setVisible(false);

      float turnX = getWidth() - pCubicTurn.getWidth();
      float turnY = getHeight() - pCubicTurn.getHeight();
      mCubicTurnAniSprite =
          new AnimatedSprite(turnX - 15, turnY - 15, pCubicTurn, mVertexBufferObjectManager);
      this.attachChild(mCubicTurnAniSprite);
      mCubicTurnAniSprite.setVisible(false);

      for (int i = 0; i < mCubicTurnOptionAniSprite.length; i++) {
        float turnOpX = getWidth() - pCubicTurnOption[i].getWidth();
        float turnOpY = getHeight() - pCubicTurnOption[i].getHeight();
        mCubicTurnOptionAniSprite[i] =
            new AnimatedSprite(turnOpX, turnOpY, pCubicTurnOption[i], mVertexBufferObjectManager);
        this.attachChild(mCubicTurnOptionAniSprite[i]);
        mCubicTurnOptionAniSprite[i].setVisible(false);
      }

      float stopX = getWidth() - pCubicTurn.getWidth();
      float stopY = getHeight() - pCubicTurn.getHeight();
      mCubicStopAniSprite =
          new AnimatedSprite(stopX - 15, stopY - 15, pCubicStop, mVertexBufferObjectManager);
      this.attachChild(mCubicStopAniSprite);
      mCubicStopAniSprite.setVisible(false);

      float scrollX = turnX + pCubicTurn.getWidth() / 2 - mScrollLeftTextureRegion.getWidth();
      float scrollY = turnY + pCubicTurn.getHeight() - mScrollLeftTextureRegion.getHeight();
      mScrollLeftSprite =
          new Sprite(scrollX, scrollY, mScrollLeftTextureRegion, mVertexBufferObjectManager);
      this.attachChild(mScrollLeftSprite);
      mScrollLeftSprite.setVisible(false);

      mScrollLeftSprite.registerEntityModifier(
          new LoopEntityModifier(
              new SequenceEntityModifier(
                  new AlphaModifier(0.5f, 0.2f, 1.0f), new AlphaModifier(0.5f, 1.0f, 0.2f))));
    }
  @Override
  public void onUpdateTextureCoordinates(final TiledSprite pTiledSprite) {
    final float[] bufferData = this.mBufferData;

    final ITiledTextureRegion tiledTextureRegion = pTiledSprite.getTiledTextureRegion();

    final int tileCount = pTiledSprite.getTileCount();
    int bufferDataOffset = 0;
    for (int i = 0; i < tileCount; i++) {
      final ITextureRegion textureRegion = tiledTextureRegion.getTextureRegion(i);

      final float u;
      final float v;
      final float u2;
      final float v2;

      if (pTiledSprite.isFlippedVertical()) { // TODO Optimize with field access?
        if (pTiledSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
          u = textureRegion.getU2();
          u2 = textureRegion.getU();
          v = textureRegion.getV2();
          v2 = textureRegion.getV();
        } else {
          u = textureRegion.getU();
          u2 = textureRegion.getU2();
          v = textureRegion.getV2();
          v2 = textureRegion.getV();
        }
      } else {
        if (pTiledSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
          u = textureRegion.getU2();
          u2 = textureRegion.getU();
          v = textureRegion.getV();
          v2 = textureRegion.getV2();
        } else {
          u = textureRegion.getU();
          u2 = textureRegion.getU2();
          v = textureRegion.getV();
          v2 = textureRegion.getV2();
        }
      }

      if (textureRegion.isRotated()) {
        bufferData[
                bufferDataOffset
                    + 0 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u;
        bufferData[
                bufferDataOffset
                    + 0 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v;

        bufferData[
                bufferDataOffset
                    + 1 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u2;
        bufferData[
                bufferDataOffset
                    + 1 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v;

        bufferData[
                bufferDataOffset
                    + 2 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u;
        bufferData[
                bufferDataOffset
                    + 2 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v2;

        bufferData[
                bufferDataOffset
                    + 3 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u;
        bufferData[
                bufferDataOffset
                    + 3 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v2;

        bufferData[
                bufferDataOffset
                    + 4 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u2;
        bufferData[
                bufferDataOffset
                    + 4 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v;

        bufferData[
                bufferDataOffset
                    + 5 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u2;
        bufferData[
                bufferDataOffset
                    + 5 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v2;
      } else {
        bufferData[
                bufferDataOffset
                    + 0 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u;
        bufferData[
                bufferDataOffset
                    + 0 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v2;

        bufferData[
                bufferDataOffset
                    + 1 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u;
        bufferData[
                bufferDataOffset
                    + 1 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v;

        bufferData[
                bufferDataOffset
                    + 2 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u2;
        bufferData[
                bufferDataOffset
                    + 2 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v2;

        bufferData[
                bufferDataOffset
                    + 3 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u2;
        bufferData[
                bufferDataOffset
                    + 3 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v2;

        bufferData[
                bufferDataOffset
                    + 4 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u;
        bufferData[
                bufferDataOffset
                    + 4 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v;

        bufferData[
                bufferDataOffset
                    + 5 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_U] =
            u2;
        bufferData[
                bufferDataOffset
                    + 5 * TiledSprite.VERTEX_SIZE
                    + Sprite.TEXTURECOORDINATES_INDEX_V] =
            v;
      }

      bufferDataOffset += TiledSprite.TILEDSPRITE_SIZE;
    }

    this.setDirtyOnHardware();
  }
  protected void drawScene() {
    Log.i(TAG, "----------drawScene------------------------------");

    this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, 0), false);
    this.registerUpdateHandler(mPhysicsWorld);
    this.mPhysicsWorld.setContactListener(contactListener);

    final Sprite spriteBackGround =
        new Sprite(
            960 / 2 - mBackGroundTextureRegion.getWidth() / 2,
            0,
            mBackGroundTextureRegion,
            mVertexBufferObjectManager);
    this.attachChild(spriteBackGround);

    for (int i = 0; i < mTabSprite.length; i++) {
      mTabSprite[i] =
          new Sprite(
              960 / 2 - 1150 / 2,
              89.5f,
              tpTab[i].getTexturePackTextureRegionLibrary().get(0),
              mVertexBufferObjectManager);
      this.attachChild(mTabSprite[i]);
      mTabSprite[i].setVisible(false);
    }
    mTabSprite[0].setVisible(true);

    final Body body =
        this.physicsEditorShapeLibrary.createBody(
            "a3_5_1_iphone_dai", mTabSprite[0], this.mPhysicsWorld);
    this.mPhysicsWorld.registerPhysicsConnector(
        new PhysicsConnector(mTabSprite[0], body, true, true));
    mTabSprite[0].setUserData(body);

    // Cubic Choose
    mCubicChooseSpite[CUBIC_YELLOW] =
        new Sprite(
            279,
            70,
            tpOne
                .getTexturePackTextureRegionLibrary()
                .get(Vol3OsyougatsuResource.packer_parta_1.A3_6_4_IPHONE_KOMA_ID),
            mVertexBufferObjectManager);
    this.attachChild(mCubicChooseSpite[CUBIC_YELLOW]);

    mCubicChooseSpite[CUBIC_GREEN] =
        new Sprite(
            200,
            90f,
            tpOne
                .getTexturePackTextureRegionLibrary()
                .get(Vol3OsyougatsuResource.packer_parta_1.A3_6_3_IPHONE_KOMA_ID),
            mVertexBufferObjectManager);
    this.attachChild(mCubicChooseSpite[CUBIC_GREEN]);

    mCubicChooseSpite[CUBIC_BLUE] =
        new Sprite(
            110,
            107,
            tpOne
                .getTexturePackTextureRegionLibrary()
                .get(Vol3OsyougatsuResource.packer_parta_1.A3_6_2_IPHONE_KOMA_ID),
            mVertexBufferObjectManager);
    this.attachChild(mCubicChooseSpite[CUBIC_BLUE]);

    mCubicChooseSpite[CUBIC_ORANGE] =
        new Sprite(
            22f,
            135,
            tpOne
                .getTexturePackTextureRegionLibrary()
                .get(Vol3OsyougatsuResource.packer_parta_1.A3_6_1_IPHONE_KOMA_ID),
            mVertexBufferObjectManager);
    this.attachChild(mCubicChooseSpite[CUBIC_ORANGE]);

    cubicTouch = new CubicTouch(0, 0, 960, 640, null);
    this.attachChild(cubicTouch);
    this.registerTouchArea(cubicTouch);

    for (int i = CUBIC_ORANGE; i <= CUBIC_YELLOW; i++) {
      final TextureRegion iOTextureRegion =
          new TextureRegion(
              bitmapTexture[i % 2],
              2,
              2,
              mCubicStartTiledTexture[i].getWidth(),
              mCubicStartTiledTexture[i].getHeight());
      mCubicEntity[i] =
          new CubicEntity(
              0,
              100,
              i,
              mCubicStartTiledTexture[i],
              mCubicTurnTiledTexture[i],
              mCubicStopTiledTexture[i],
              mCubicTurnOptionTiledTexture,
              iOTextureRegion);
      this.attachChild(mCubicEntity[i]);
      mCubicEntity[i].setVisible(false);
      // Body
      final Body bodyCubic =
          this.physicsEditorShapeLibrary.createBody(
              CUBIC_BODYNAME[i], mCubicEntity[i], this.mPhysicsWorld);
      bodyCubic.setFixedRotation(true);
      bodyCubic.setActive(false);
      mCubicEntity[i].setUserData(bodyCubic);
      mPhysicsWorld.registerPhysicsConnector(
          new PhysicsConnector(mCubicEntity[i], bodyCubic, true, true));
    }

    final SceneTouch sceneTouch = new SceneTouch(0, 0, 960, 640, null);
    this.attachChild(sceneTouch);
    this.registerTouchArea(sceneTouch);

    mSuzuAniSprite =
        new AnimatedSprite(
            960 / 2 - mSuzuTiledTexTure.getWidth() / 2,
            -19,
            mSuzuTiledTexTure,
            mVertexBufferObjectManager);
    this.attachChild(mSuzuAniSprite);

    mShishiAniSprite =
        new AnimatedSprite(960, 59.5f, mShishiTiledTexTure, mVertexBufferObjectManager);
    this.attachChild(mShishiAniSprite);
    mShishiAniSprite.setVisible(false);

    mArrowSprite =
        new Sprite(
            120,
            133,
            tpThree
                .getTexturePackTextureRegionLibrary()
                .get(Vol3OsyougatsuResource.packer_parta_3.A3_8_1_IPHONE_YAJIRUSHI_ID),
            mVertexBufferObjectManager);
    this.attachChild(mArrowSprite);
    mArrowSprite.setVisible(false);
  }
  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();
  }