Exemplo n.º 1
0
  @Override
  public Scene onLoadScene() {
    mEngine.registerUpdateHandler(new FPSLogger());

    final int barX = (int) ((mCamera.getWidth() - mBarTextureRegion.getWidth()) / 2);
    ballX = barX;
    final int barY = (int) ((mCamera.getHeight() - mBarTextureRegion.getHeight()) / 2);

    // player = new Sprite(PlayerX, PlayerY, mPlayerTextureRegion);
    // player.setScale(2);

    bar = new Sprite(barX, barY, mBarTextureRegion);
    bar.setScale(4, 2.5f);

    ball = new Sprite(ballX, barY + bar.getHeight(), mBallTextureRegion);
    ball.setScale(2.5f);

    mMainScene = new Scene();
    mMainScene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

    // mMainScene.attachChild(player);
    mMainScene.attachChild(bar);
    mMainScene.attachChild(ball);

    mMainScene.registerUpdateHandler(detect);

    // projectileLL = new LinkedList();
    // projectilesToBeAdded = new LinkedList();

    mMainScene.setOnSceneTouchListener(this);

    mPauseScene = new CameraScene(mCamera);
    final int x = (int) (mCamera.getWidth() / 2 - mPausedTextureRegion.getWidth() / 2);
    final int y = (int) (mCamera.getHeight() / 2 - mPausedTextureRegion.getHeight() / 2);
    final Sprite pausedSprite = new Sprite(x, y, mPausedTextureRegion);
    mPauseScene.attachChild(pausedSprite);
    mPauseScene.setBackgroundEnabled(false);

    mResultScene = new CameraScene(mCamera);
    winSprite = new Sprite(x, y, mWinTextureRegion);
    failSprite = new Sprite(x, y, mFailTextureRegion);
    mResultScene.attachChild(winSprite);
    mResultScene.attachChild(failSprite);
    mResultScene.setBackgroundEnabled(false);

    winSprite.setVisible(false);
    failSprite.setVisible(false);
    score = new ChangeableText(0, 0, mFont, "ButtsButtsButts");
    score.setPosition(5, 5); // mCamera.getWidth() - score.getWidth() - 5, 5);
    score.setWidth(2000);
    mMainScene.attachChild(score);

    sensorManager = (SensorManager) this.getSystemService(this.SENSOR_SERVICE);
    sensorManager.registerListener(
        this, sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR), 1);

    return mMainScene;
  }
Exemplo n.º 2
0
 @Override
 public void onSensorChanged(SensorEvent event) {
   if (event.sensor.getType() != Sensor.TYPE_ROTATION_VECTOR) return;
   rotation -= event.values[1]; // it's dumb, just go with it.
   score.setText("" + rotation);
   bar.setRotation(rotation);
   ballX += rotation / 100;
   ball.setPosition(ballX, ball.getY());
 }
Exemplo n.º 3
0
  public void restart() {

    runOnUpdateThread(
        new Runnable() {

          @Override
          public void run() {
            mMainScene.detachChildren();
            mMainScene.attachChild(score);
          }
        });

    hitCount = 0;
    score.setText(String.valueOf(hitCount));
  }
  public TowerUpgraderBack show(final Tower pTowerBase) {
    // Debug.i("TowerUpgrader :: show :: type=" + pTowerBase.getTowerType());

    // disable tower interaction
    TowerManager.ENABLE_TOWER_INTERACTION = false;

    // set our current tower base
    mCurrentTowerBase = pTowerBase;

    // update our sell text
    mTowerSellText.setText(Integer.toString(pTowerBase.getTowerType().getCost()));

    // set our current row/col, make sure to account for our cancel +
    // sell button
    int currentCol = 0;
    int currentRow = 0;

    // find the coords
    final int[] coords =
        Registry.sMap.getCoordsFromTiles(pTowerBase.mTowerCol, pTowerBase.mTowerRow);

    // update the position
    mPositionMarker.setPosition(coords[0], coords[1]);
    mPositionMarker.setColor(1, 1, 1, 1.0f);

    // turn on updates and visibility
    mPositionMarker.setIgnoreUpdate(false);
    mPositionMarker.setVisible(true);

    // setup the radius marker
    mRadiusMarker.setIgnoreUpdate(false);
    mRadiusMarker.setVisible(true);
    mRadiusMarker.setWidth(pTowerBase.getTowerRange() * 2);
    mRadiusMarker.setHeight(pTowerBase.getTowerRange() * 2);

    // set the position of the marker
    mRadiusMarker.setPosition(
        (-pTowerBase.getTowerRange()) + (TowerManager.TOWER_WIDTH / 2),
        (-pTowerBase.getTowerRange()) + (TowerManager.TOWER_HEIGHT / 2));

    // attach the radius marker to the position marker, then to the scene
    Registry.sSceneLayerTowers.attachChild(mPositionMarker);

    // get this towers upgrade types
    for (final TowerTypes tt : pTowerBase.getTowerUpgradeTypes()) {

      /**
       * final TiledSprite upgradableTower = new TiledSprite(this.mBoxX + TOWERS_UI_SPACER +
       * (TOWERS_UI_SPACER * currentCol) + (TOWERS_UI_ITEM_WIDTH * currentCol), mBoxY +
       * TOWERS_UI_SPACER + (TOWERS_UI_SPACER * currentRow) + (TOWERS_UI_ITEM_WIDTH * currentRow),
       * mTowerManager.getTowerMenuTiledTextureRegionClone()) {
       */

      // PUT BORDERS ABOVE THESE FROM THE UI SPRITES THEY COME IN LARGE SIZE

      final float lX =
          mBoxX
              + TOWERS_UI_SPACER
              + (TOWERS_UI_SPACER * currentCol)
              + (TOWERS_UI_ITEM_WIDTH * currentCol);
      final float lY =
          mBoxY
              + TOWERS_UI_SPACER
              + (TOWERS_UI_SPACER * currentRow)
              + (TOWERS_UI_ITEM_HEIGHT * currentRow);

      final float placeX = (TOWERS_UI_ITEM_WIDTH / 2) + (lX - tt.getTowerTileCenterX());
      final float placeY =
          (TOWERS_UI_ITEM_HEIGHT - TOWERS_UI_SPACER) + (lY - tt.getTowerTileCenterY());

      final TiledSprite upgradableTower =
          new TiledSprite(
              placeX,
              placeY,
              Registry.sTowerTextureRegions[tt.getTowerTopSprite().getId()].deepCopy());
      upgradableTower.setScale(.90f);

      if (null == tt.getPlayerRewardType()
          || Registry.sPlayerRewards.isRewardEarned(tt.getPlayerRewardType())) {
        upgradableTower.setAlpha(1f);

      } else {
        upgradableTower.setAlpha(.25f);
      }

      if (null != tt.getTowerBaseSprite()) {
        upgradableTower.setCurrentTileIndex(tt.getTowerBaseSprite().getInitialTileIndex());
        // Debug.i("getTowerBaseSprite=" + tt.getTowerBaseSprite().getInitialTileIndex());
      }

      if (null != tt.getTowerTopSprite()) {
        upgradableTower.setCurrentTileIndex(tt.getTowerTopSprite().getInitialTileIndex());
        // Debug.i("getTowerTopSprite=" + tt.getTowerTopSprite().getInitialTileIndex());
      }

      upgradableTower.setZIndex(100);
      attachChild(upgradableTower);
      registerTouchArea(upgradableTower);
      mUpgradeSprites.add(upgradableTower);

      final Rectangle rect =
          new Rectangle(lX, lY, TOWERS_UI_ITEM_WIDTH, TOWERS_UI_ITEM_HEIGHT) {
            @Override
            public boolean onAreaTouched(
                TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
              if (null == tt.getPlayerRewardType()
                  || Registry.sPlayerRewards.isRewardEarned(tt.getPlayerRewardType())) {
                this.setAlpha(1f);

                if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
                  TowerUpgraderBack.this.isValidClick = true;
                }
                if (TowerUpgraderBack.this.isValidClick
                    && pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP
                    && GameActivity.SCROLL_MODE_DISABLED
                        == Registry.sGameActivity.getScrollMode()) {
                  Registry.sGameActivity.runOnUpdateThread(
                      new Runnable() {

                        @Override
                        public void run() {
                          TowerUpgraderBack.this.upgrade(pTowerBase, tt);
                          TowerUpgraderBack.this.isValidClick = false;
                        }
                      });
                }

                return true;
              } else {
                this.setAlpha(.25f);

                Registry.sGameActivity.userNotifyShort(
                    "This tower requires the \""
                        + tt.getPlayerRewardType()
                        + "\" reward to be unlocked. Visit the Game Points section from the main menu for more information about earning and spending Game Points (The currency \"GP\" you see above).");

                return false;
              }
            }
          };
      rect.setZIndex(90);
      attachChild(rect);

      if (++currentCol >= mTotalColumns) {
        currentRow++;
        currentCol = 0;
      }
    }

    sortChildren();

    Debug.i("SpriteSheets.UI_128x128_01.ordinal()=" + SpriteSheets.UI_128x128_01.ordinal());

    final TiledSprite ts =
        new TiledSprite(
            25,
            25,
            Registry.sSpriteTextureRegions[SpriteSheets.UI_128x128_01.ordinal()].deepCopy());
    // final TiledSprite ts = new TiledSprite(25, 25,
    // Registry.sTowerTextureRegions[TowerTypes.ARCH_MAGE.getTowerTopSprite().getId()].deepCopy());
    ts.setZIndex(110);
    ts.setCurrentTileIndex(0);
    attachChild(ts);

    Registry.sGameActivity.setScrollMode(GameActivity.SCROLL_MODE_DISABLED);
    Registry.sGameActivity.getCamera().setHUD(TowerUpgraderBack.this);

    return this;
  }