private void handleRotateCharTouchEvent(TouchEvent touchEvent) {
    if (touchEvent.isActionDown()
        && Boundary.BoundaryUtils.isIntersecting(this.baPlayerBoundary, this.baTouchBoundary)) {
      this.isRotatingSkin = true;
      this.rotateCharInitalTouchX = touchEvent.getX();
      this.sRotateChar.setAlpha(1f);
    } else if (touchEvent.isActionUp()) {
      this.isRotatingSkin = false;
      this.sRotateChar.setAlpha(1f);
    }

    if (this.isRotatingSkin)
      if (touchEvent.isActionMove()) {
        final float DELTA = this.rotateCharInitalTouchX - touchEvent.getX();
        final float DELTA_ABS = Math.abs(DELTA);

        if (DELTA_ABS > MainMenuEditPlayer.ROTATE_MOVE_SENSITIVITY) {
          final int STEPS =
              (int) Math.floor(DELTA_ABS / MainMenuEditPlayer.ROTATE_MOVE_SENSITIVITY);

          MainMenuEditPlayer.skinMoveDirectionIndex += (DELTA > 0) ? STEPS : -STEPS;

          if (MainMenuEditPlayer.skinMoveDirectionIndex < 0)
            MainMenuEditPlayer.skinMoveDirectionIndex += Direction.values().length - 1;
          else if (MainMenuEditPlayer.skinMoveDirectionIndex > Direction.values().length - 2)
            MainMenuEditPlayer.skinMoveDirectionIndex -= Direction.values().length - 2;
          this.rotateCharInitalTouchX = touchEvent.getX();
          this.directPlayerSkin();
        }
      }
  }
Beispiel #2
0
    @Override
    public boolean onAreaTouched(
        TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
      if (!this.isVisible()) {
        return true;
      }
      if (pSceneTouchEvent.isActionDown()) {
        this.clearEntityModifiers();
        A19_10_POMI.play();
      } else if (pSceneTouchEvent.isActionMove()) {
        this.setPosition(
            pSceneTouchEvent.getX() - this.getWidth() / 2,
            pSceneTouchEvent.getY() - this.getHeight() / 2);
        if (checkContains(
            mFingerAnimatedSprite[4],
            57,
            43,
            185,
            171,
            (int) pSceneTouchEvent.getX(),
            (int) pSceneTouchEvent.getY())) {

          babyDring();
          this.setPosition(this.PX, this.PY);
          this.setVisible(false);
        }
      } else if (pSceneTouchEvent.isActionUp()) {
        this.setPosition(this.PX, this.PY);
        this.rotateAction();
      }
      return true;
    }
    @Override
    public boolean onAreaTouched(
        TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {

      if (pSceneTouchEvent.isActionDown()) {
        // Log.i(TAG, "Touch CubicTouch isActionDown");
        if (checkContains(
            mSuzuAniSprite, 113, 30, 251, 202, (int) pTouchAreaLocalX, (int) pTouchAreaLocalY)) {
          Log.i(TAG, "Touch to ActionSuzuShiShi !");
          actionSuzuShiShi();
          return true;
        }
        for (int i = 0; i < mCubicEntity.length; i++) {
          if (mCubicEntity[i].isVisible()
              && mCubicEntity[i]
                  .getCubicBody()
                  .contains(pSceneTouchEvent.getX(), pSceneTouchEvent.getY())) {
            pxMOVE = pSceneTouchEvent.getX();
            if (mCubicEntity[i].actionDown() > 0) {
              Log.i(TAG, "Touch CubicTouch > 0");
            } else {
              Log.i(TAG, "Touch CubicTouch < 0 " + i);
              CUBICID = i;
            }
            return true;
          }
        }
      } else if (pSceneTouchEvent.isActionMove()) {
        // Log.i(TAG, "Touch CubicTouch isActionMove");
      } else if (pSceneTouchEvent.isActionUp()) {
        Log.i(TAG, "Touch CubicTouch isActionUp" + CUBICID);
        if (CUBICID >= 0 && mCubicEntity[CUBICID].getCubicAction() == CubicEntity.ACTION_DEFAULT) {
          float offset = pSceneTouchEvent.getX() - pxMOVE;
          if (offset < 0) {
            if (Math.abs(offset) >= 350) {
              Log.i(TAG, "Level 3");
              mCubicEntity[CUBICID].actionUp(CubicEntity.ACTION_TURN_LEVEL_3);
            } else if (Math.abs(offset) >= 200) {
              Log.i(TAG, "Level 2");
              mCubicEntity[CUBICID].actionUp(CubicEntity.ACTION_TURN_LEVEL_2);
            } else if (Math.abs(offset) >= 0) {
              Log.i(TAG, "Level 1");
              mCubicEntity[CUBICID].actionUp(CubicEntity.ACTION_TURN_LEVEL_1);
            }
          }
        }

        CUBICID = -1;
      }
      return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
    }
Beispiel #4
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);
  }
Beispiel #5
0
  /** TODO So ugly :( Maybe make it its own class? */
  @Override
  public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
    final Float x = pSceneTouchEvent.getX();
    final Float y = pSceneTouchEvent.getY();

    currentTile = this.tmxLayer.getTMXTileAt(x, y);

    // if the user pinches or dragtouches the screen then...
    if (this.mPinchZoomDetector != null) {

      this.mPinchZoomDetector.onTouchEvent(pSceneTouchEvent);
      if (this.mPinchZoomDetector.isZooming()) {
        this.mScrollDetector.setEnabled(false);
      } else if (!towerMove) {
        if (pSceneTouchEvent.isActionDown()) {
          this.mScrollDetector.setEnabled(true);
        }
        this.mScrollDetector.onTouchEvent(pSceneTouchEvent);
      }

    } else {
      this.mScrollDetector.onTouchEvent(pSceneTouchEvent);
    }

    if (pSceneTouchEvent.isActionDown()) {
      downCoords.set(x, y);

      SubMenuManager.setReticalPosition(-500.0f, -500.0f);

      Log.i("Detaching now", "NOW");
      SubMenuManager.remove();
      this.unregisterTouchArea(SubMenuManager.getDeleteSprite());

      panel.detachTowerUpgradeDeleteText();
      panel.detachTowerTextDescription();
      panel.attachTowerTextDescription(pointOnTile(TouchEvent.ACTION_DOWN));
    }

    Class<?> tClass;
    if (pSceneTouchEvent.isActionMove()) {

      tClass = pointOnTile(TouchEvent.ACTION_MOVE);
      if (tClass != null && !towerMove) {
        dragTower = null;
        towerMove = true;
        if (tClass.equals(TurretTower.class) && canAfford(TurretTower.COST)) {
          dragTower = new TurretTower(x, y, resourceManager.getTurretTowerRegion());
        } else if (tClass.equals(DartTower.class) && canAfford(DartTower.COST)) {
          dragTower = new DartTower(x, y, resourceManager.getDartTowerRegion());
        } else if (tClass.equals(FlameTower.class) && canAfford(FlameTower.COST)) {
          dragTower = new FlameTower(x, y, resourceManager.getFlameTowerRegion());
        } else if (tClass.equals(IceTower.class) && canAfford(IceTower.COST)) {
          dragTower = new IceTower(x, y, resourceManager.getIceTowerRegion());
        } else if (tClass.equals(SpikeTower.class) && canAfford(SpikeTower.COST)) {
          dragTower = new SpikeTower(x, y, resourceManager.getSpikeTowerRegion());
        } else towerMove = false;

        if (dragTower != null) {
          dragTower.getEntity().setZIndex(2);
          dragTower.getEntity().setScale(0.5f);

          activity.runOnUpdateThread(
              new Runnable() {
                @Override
                public void run() {
                  attachChild(dragTower.getEntity());

                  try {
                    attachChild(SubMenuManager.getReticle(dragTower));
                  } catch (Exception e) {
                  }
                  sortChildren();
                }
              });
          tClass = null;
        }

      }

      // Moving an active drag tower
      else if (towerMove) {
        if (pointOnMap(x, y)) {

          dragTower.setPosition(
              currentTile.getTileX() - GameMap.getTileSize() / 2,
              currentTile.getTileY() - GameMap.getTileSize() / 2);

          if (highlightTile == null) {
            highlightTile =
                new Rectangle(
                    currentTile.getTileX(),
                    currentTile.getTileY(),
                    GameMap.getTileSize(),
                    GameMap.getTileSize(),
                    activity.getVertexBufferObjectManager());
            highlightTile.setTag(777);
            highlightTile.setZIndex(1);
            this.attachChild(highlightTile);
            this.sortChildren();
          } else {
            highlightTile.setPosition(currentTile.getTileX(), currentTile.getTileY());
          }

          if (!inLegitimatePosition(currentTile)) {
            highlightTile.setColor(Color.RED);
          } else {
            highlightTile.setColor(Color.BLUE);
          }

          // if you drag the dragtower off the map, and then back on, we need to be able to tag it
          // so we can display the highlight tile again
          if (this.getChildByTag(777) == null) {
            this.attachChild(highlightTile);
            this.sortChildren();
          }
        }
        // if point NOT on map
        else {
          if (highlightTile != null) {
            detachHighlightTile();
          }
          dragTower.setPosition(
              pSceneTouchEvent.getX() - dragTower.getEntity().getWidth() / 2,
              pSceneTouchEvent.getY() - dragTower.getEntity().getHeight() / 2);
        }
      }
    } else if (pSceneTouchEvent.isActionUp()) {

      if (zooming) {
        fingerOnSceneCount--;

        if (fingerOnSceneCount == 0) {
          zooming = false;
          setUserDataforTowerTiles("");

          for (TowerTile tile : panel.getTiles()) {
            tile.returnOnMoved();
          }
        }
      }

      if (towerMove) {
        towerMove = false;

        if (currentTile != null
            && highlightTile != null
            && highlightTile.getColor().equals(Color.BLUE)) {

          // Add the tile to the blocked list
          blockedTileList.add(currentTile);

          towers.add(dragTower);
          SubMenuManager.getReticle(dragTower).detachSelf();

          // need to get it out of the scene so that the next dragtower doesn't have to start with
          // it from where the
          // previous tower was placed
          SubMenuManager.setReticalPosition(-500.0f, -500.0f);

          // Nothing is free in this world
          this.payAmount(dragTower.getCost());

          // If we are in the middle of a wave, the AStarPath class must update
          // the path since there is now a new tower on the field
          updateAffectedEnemies(currentTile, aStarHelper.isNavigating());
        } else {
          removeCurrentTower(false);
        }

        if (highlightTile != null) {
          detachHighlightTile();
        }
      } else if (Math.abs(downCoords.x - x) < 15.0f && Math.abs(downCoords.y - y) < 15.0f) {

        final ITower tower = pointOnExistingTower(x, y);
        if (tower != null) {
          this.attachChild(SubMenuManager.display(tower));
          Log.i("Reticle", "Visible? " + SubMenuManager.getReticle(tower).isVisible() + "");
          panel.attachTowerUpgradeDeleteText(tower);

          if (camera.getZoomFactor() - 1.0f < 0.00005f && camera.getYMin() < 0.00005f) {

            final float displacement = tower.getRadius() - tower.getEntity().getHeightScaled() / 2;
            if (tower.getY() == -20.0f) {
              camera.set(
                  camera.getXMin(),
                  camera.getYMin() - displacement,
                  camera.getXMax(),
                  camera.getYMax() - displacement);
            } else if (tower.getY() == 340.0f) {
              camera.set(
                  camera.getXMin(),
                  camera.getYMin() + displacement,
                  camera.getXMax(),
                  camera.getYMax() + displacement);
            }
          }
        }
      }
    }
    return true;
  }