private void checkForCollisionsWithTowers(Ring ring) {
   Stack stack = null;
   Sprite tower = null;
   if (ring.collidesWith(mTower1)
       && (mStack1.size() == 0 || ring.getmWeight() < ((Ring) mStack1.peek()).getmWeight())) {
     stack = mStack1;
     tower = mTower1;
   } else if (ring.collidesWith(mTower2)
       && (mStack2.size() == 0 || ring.getmWeight() < ((Ring) mStack2.peek()).getmWeight())) {
     stack = mStack2;
     tower = mTower2;
   } else if (ring.collidesWith(mTower3)
       && (mStack3.size() == 0 || ring.getmWeight() < ((Ring) mStack3.peek()).getmWeight())) {
     stack = mStack3;
     tower = mTower3;
   } else {
     stack = ring.getmStack();
     tower = ring.getmTower();
   }
   ring.getmStack().remove(ring);
   if (stack != null && tower != null && stack.size() == 0) {
     ring.setPosition(
         tower.getX() + tower.getWidth() / 2 - ring.getWidth() / 2,
         tower.getY() + tower.getHeight() - ring.getHeight());
   } else if (stack != null && tower != null && stack.size() > 0) {
     ring.setPosition(
         tower.getX() + tower.getWidth() / 2 - ring.getWidth() / 2,
         ((Ring) stack.peek()).getY() - ring.getHeight());
   }
   stack.add(ring);
   ring.setmStack(stack);
   ring.setmTower(tower);
 }
Esempio n. 2
0
  public void addTarget() {
    Random rand = new Random();

    int minX = 0;
    int maxX = (int) (mCamera.getWidth() - activity.enemySprite.getWidth());
    int rangeX = maxX - minX;
    int y = (int) -activity.enemySprite.getHeight();
    int x = rand.nextInt(rangeX) - minX;

    Sprite target = new Sprite(x, y, activity.enemyRegion, activity.getVertexBufferObjectManager());
    target.setSize(
        activity.mCamera.getWidth() / 10.8f * 1.5f, activity.mCamera.getWidth() / 10.8f * 1.5f);

    target.setZIndex(3);

    attachChild(target);

    int minDuration = 3;
    int maxDuration = 6;
    int rangeDuration = maxDuration - minDuration;
    int actualDuration = rand.nextInt(rangeDuration) + minDuration;
    int actualMoveX = rand.nextInt((int) (mCamera.getWidth() - target.getWidth()));

    MoveModifier mod =
        new MoveModifier(
            actualDuration,
            target.getX(),
            actualMoveX,
            target.getY(),
            mCamera.getHeight() + target.getHeight());

    target.registerEntityModifier(mod.deepCopy());

    enemiesToBeAdded.add(target);
  }
  private void effectRate(Rate mRate) {
    // Log.e(tag, "effectRate");

    Sprite sprite = fastSprite;

    switch (mRate) {
      case FAST:
        sprite = new Sprite(0, 0, Region.fast, vbom);
        break;
      case SUPER_FAST:
        sprite = new Sprite(0, 0, Region.superFast, vbom);
        break;
      case COMPLETE:
        sprite = new Sprite(0, 0, Region.complete, vbom);
        break;
      case WRONG:
        sprite = new Sprite(0, 0, Region.wrong, vbom);
        break;
      case SLOW:
        sprite = new Sprite(0, 0, Region.slow, vbom);
        break;
    }

    setToCenter(sprite);
    sprite.setScale(0);
    attachChild(sprite);

    sprite.registerEntityModifier(
        new SequenceEntityModifier(
            new ScaleAtModifier(0.2f, 0, 1, sprite.getWidth() / 2, sprite.getHeight() / 2),
            new AlphaModifier(0.3f, 1, 1),
            new AlphaModifier(0.1f, 1, 0)));
  }
  protected void createExplosionMark(float x, float y) {

    final Sprite MARK =
        new TextureManagedSprite(
            0,
            0,
            HudRegions.region_explosion_mark,
            EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()) {
          private float elapsedAliveTime;

          @Override
          protected void onManagedUpdate(float pSecondsElapsed) {
            this.elapsedAliveTime += pSecondsElapsed;

            if (this.elapsedAliveTime >= SessionScene.TARGET_ALIVE_EXPLOSION_MARK_TIME) {
              this.setAlpha(this.getAlpha() - 0.002f);
              if ((int) (this.getAlpha() * 1000) <= 0) EntityUtils.safetlyDetachAndDispose(this);
            }

            super.onManagedUpdate(pSecondsElapsed);
          }
        };
    MARK.setScale(2f);
    MARK.setX(x - MARK.getWidth() / 2f);
    MARK.setY(y - MARK.getHeight() / 2f);

    this.attachChild(MARK);
  }
Esempio n. 5
0
  public boolean birdUnderAim(Bird obj) {

    float x = (aim.getX() + aim.getX() + aim.getWidth()) / 2;
    float y = (aim.getY() + aim.getY() + aim.getHeight()) / 2;
    if (x > obj.getX() && x < obj.getX() + obj.getWidth())
      if (y > obj.getY() && y < obj.getY() + obj.getHeight()) {
        return true;
      }
    return false;
  }
  private void effectReadyGo() {
    // Log.e(tag, "effectReadyGo");

    this.attachChild(readySprite);
    setToCenter(readySprite);
    readySprite.setScale(0);

    this.attachChild(goSprite);
    setToCenter(goSprite);
    goSprite.setScale(0);

    readySprite.registerEntityModifier(
        new SequenceEntityModifier(
            new ScaleAtModifier(
                0.7f, 0, 1, readySprite.getWidth() / 2, readySprite.getHeight() / 2),
            new AlphaModifier(0.75f, 1, 1),
            new AlphaModifier(0.3f, 1, 0)));

    goSprite.registerEntityModifier(
        new SequenceEntityModifier(
            new ScaleAtModifier(1.7f, 0, 0, goSprite.getWidth() / 2, goSprite.getHeight() / 2),
            new ScaleAtModifier(0.7f, 0, 1, goSprite.getWidth() / 2, goSprite.getHeight() / 2),
            new AlphaModifier(0.75f, 1, 1),
            new AlphaModifier(
                0.3f,
                1,
                0,
                new IEntityModifier.IEntityModifierListener() {
                  @Override
                  public void onModifierStarted(
                      IModifier<IEntity> iEntityIModifier, IEntity iEntity) {}

                  @Override
                  public void onModifierFinished(
                      IModifier<IEntity> iEntityIModifier, IEntity iEntity) {
                    // Log.e(tag, "onModifierFinished");
                    initTime();
                    taskInit();
                  }
                })));
  }
Esempio n. 7
0
        @Override
        public void onUpdate(float pSecondsElapsed) {
          synchronized (this) {
            Iterator<Sprite> targets = enemies.iterator();
            Sprite _target;
            Sprite _bonus;
            Sprite _shield;

            while (targets.hasNext()) {
              _target = targets.next();
              _bonus = activity.bonusSprite;
              _shield = activity.shieldSpriteP;

              if (_target.getY() >= _target.getWidth() + mCamera.getHeight()) {
                removeSprite(_target, targets);
                addTarget();
                break;
              }

              if (isColliding(
                  activity.ballSprite.getX() + activity.ballSprite.getWidth() / 2,
                  activity.ballSprite.getY() + activity.ballSprite.getWidth() / 2,
                  _target.getX() + activity.enemySprite.getWidth() / 2,
                  _target.getY() + activity.enemySprite.getHeight() / 2,
                  (int) activity.enemySprite.getHeight() / 2)) {
                enemyCollide(_target, targets);
                break;
              }
              if (!bonusHit)
                if (isColliding(
                    activity.ballSprite.getX() + activity.ballSprite.getWidth() / 2,
                    activity.ballSprite.getY() + activity.ballSprite.getWidth() / 2,
                    _bonus.getX() + activity.bonusSprite.getWidth() / 2,
                    _bonus.getY() + activity.bonusSprite.getHeight() / 2,
                    (int) activity.bonusSprite.getHeight() / 2)) {
                  bonusCollide();
                }
              if (!shieldHit)
                if (isColliding(
                    activity.ballSprite.getX() + activity.ballSprite.getWidth() / 2,
                    activity.ballSprite.getY() + activity.ballSprite.getWidth() / 2,
                    _shield.getX() + activity.shieldSpriteP.getWidth() / 2,
                    _shield.getY() + activity.shieldSpriteP.getHeight() / 2,
                    (int) activity.shieldSpriteP.getHeight() / 2)) {
                  shieldCollide();
                }
            }
            enemies.addAll(enemiesToBeAdded);
            enemiesToBeAdded.clear();
            sortChildren();
          }
        }
Esempio n. 8
0
  private void createBackground() {
    background =
        new Sprite(0, 0, resourcesManager.game_background_region, vbom) {
          @Override
          protected void preDraw(GLState pGLState, Camera pCamera) {
            super.preDraw(pGLState, pCamera);
            pGLState.enableDither();
          }

          @Override
          public boolean onAreaTouched(
              TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            Log.e("GAME", "BACK_ON_TACH");
            return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
          }
        };
    this.registerTouchArea(background);
    attachChild(background);
    camera.setCenter(background.getWidth() / 2, background.getHeight() / 2);
    camera.setBounds(0, 0, background.getWidth(), background.getHeight());
    camera.setBoundsEnabled(true);
  }
  public void effectMiss(int mPosition) {

    int[] x = {50, 150, 250};

    // Sprite sprite = new Sprite(0, 0, Region.miss, vbom);
    Sprite sprite = getMissFromPool();
    // if (sprite.getParent() != this) {
    this.attachChild(sprite);
    // }
    setToCenter(sprite);
    sprite.setX(x[mPosition]);

    sprite.registerEntityModifier(
        new SequenceEntityModifier(
            new ScaleAtModifier(0.3f, 0, 1, sprite.getWidth() / 2, sprite.getHeight() / 2),
            new AlphaModifier(0.3f, 1, 1),
            new AlphaModifier(0.3f, 1, 0)));
  }
Esempio n. 10
0
  // Creer la scene affiche e l'ecran.
  private void initSplashScene() {
    mCurrentScene = new Scene();
    // Sprite qui va contenir le logo
    Sprite splash =
        new Sprite(0, 0, manager.mSplashLogo, mEngine.getVertexBufferObjectManager()) {
          @Override
          protected void preDraw(GLState pGLState, Camera pCamera) {
            super.preDraw(pGLState, pCamera);
            pGLState.enableDither();
          }
        };
    splash.setScale(0.8f);
    // Ajoute le sprite splash e la scene.
    splash.setPosition(
        (mCamera.getWidth() - splash.getWidth()) * 0.5f,
        (mCamera.getHeight() - splash.getHeight() - 150f) * 0.5f);
    mCurrentScene.attachChild(splash);

    // Attache le titre
    mCurrentScene.attachChild(mTitle1);
    mCurrentScene.attachChild(mTitle2);
  }
Esempio n. 11
0
  public GameDialogBox(HUD hud, String message, int back, boolean text, ButtonSprite... buttons) {
    super();
    dismissed = false;
    this.buttons = buttons;
    this.hud = hud;
    this.text = text;

    ResourcesManager resourcesManager = ResourcesManager.getInstance();

    // Attach Background
    switch (back) {
      case 1:
        hud.attachChild(
            backgroundSprite =
                new Sprite(240, 400, resourcesManager.dialog_background, resourcesManager.vbom));
        break;

      case 2:
        if (resourcesManager.dialog_background2 == null) {
          Log.d("Null", "null");
        }

        hud.attachChild(
            backgroundSprite =
                new Sprite(240, 400, resourcesManager.dialog_background2, resourcesManager.vbom));
        break;

      case 3:
        hud.attachChild(
            backgroundSprite =
                new Sprite(240, 400, resourcesManager.dialog_background3, resourcesManager.vbom));
        break;
      default:
        break;
    }
    if (text) {

      messageText =
          new Text(
              240,
              400,
              resourcesManager.cartoon_font_white,
              message,
              new TextOptions(
                  AutoWrap.WORDS,
                  backgroundSprite.getWidth() - 100,
                  HorizontalAlign.CENTER,
                  Text.LEADING_DEFAULT),
              resourcesManager.vbom);

      hud.attachChild(messageText);
      if (400 + (backgroundSprite.getHeight() / 2) - 50 + (messageText.getHeight() / 2)
          > 400 + backgroundSprite.getHeight() / 2) {
        messageText.setPosition(240, 400 + backgroundSprite.getHeight() / 2 - 100);
        j = 400 + (backgroundSprite.getHeight() / 2 - 100) - messageText.getHeight() - 25;
      } else {
        messageText.setPosition(240, 400 + backgroundSprite.getHeight() / 2 - 50);
        j = 400 + (backgroundSprite.getHeight() / 2 - 50) - messageText.getHeight() - 25;
      }

    } else {
      j = 400 + ((buttons.length * 100) / 2);
    }

    int i = 0;
    for (ButtonSprite button : buttons) {
      hud.attachChild(button);
      button.setPosition(240, j - (100 * i));
      hud.registerTouchArea(button);
      i++;
    }

    // hud.registerTouchArea(okayButton);
  }
Esempio n. 12
0
  public void enemyCollide(Sprite _target, Iterator<Sprite> targets) {
    if (activity.isShield) {
      activity.isShield = false;
      detachChild(activity.shieldSprite);
      createExplosion(
          _target.getX() + _target.getWidth() / 2,
          _target.getY() + _target.getHeight() / 2,
          Color.RED,
          15,
          mCamera.getWidth() / 10);

      createExplosion(
          ball.sprite.getX() + ball.sprite.getWidth() / 2,
          ball.sprite.getY() + ball.sprite.getHeight() / 2,
          Color.BLUE,
          5,
          mCamera.getWidth() / 17);

      if (activity.isSfx()) activity.dropShieldSound.play();

      removeSprite(_target, targets);
      addTarget();
    } else {
      if (!isLoseNow) {
        if (activity.isMusic()) {
          activity.battleTheme.pause();
          activity.battleTheme.seekTo(0);
        }
        if (activity.isSfx()) {
          activity.explSound.play();
        }
        activity.score.onLose();
        activity.score.score -= 20;
        activity.editor.putInt("time", activity.prefs.getInt("time", 0) - 2);
        activity.editor.commit();

        activity.vibrator.vibrate(300);

        createExplosion(
            ball.sprite.getX() + ball.sprite.getWidth() / 2,
            ball.sprite.getY() + ball.sprite.getHeight() / 2,
            Color.RED,
            10,
            mCamera.getWidth() / 20);

        detachChild(ball.sprite);
        detachChild(scoreText);

        DelayModifier dMod =
            new DelayModifier(2) {
              @Override
              protected void onModifierFinished(IEntity pItem) {
                if (activity.isMusic()) activity.awesomeness.resume();
                restart();
              }
            };
        registerEntityModifier(dMod);
        isLoseNow = true;
      }
    }
  }
 private void setToCenter(Sprite mSprite) {
   mSprite.setPosition(
       Config.Camera.WIDTH / 2 - mSprite.getWidth() / 2,
       Config.Camera.HEIGHT / 2 - mSprite.getHeight() / 2);
 }
Esempio n. 14
0
 @Override
 protected Bird onAllocatePoolItem() {
   Log.e("GAME", "NewSmallLeft");
   return new SimpleBirdL(
       background.getWidth(), MathUtils.random(0, 200), BirdType.SIMPLE_SMALL_LEFT);
 }
Esempio n. 15
0
  @Override
  protected void onManagedUpdate(float pSecondsElapsed) {
    if (score > record) record = score;
    FPScounter++;
    if (FPScounter == FPS) {
      FPScounter = 0;
      timeLeft--;
      timeText.setText(String.valueOf(timeLeft));
      FPScounter = 0;
    }
    if (timeLeft == 0) this.onBackKeyPressed();

    int bigBird = MathUtils.random(0, 800);
    int smallBird = MathUtils.random(0, 1000);
    for (int i = 0; i < plumageArray.size(); i++) {
      plumageArray.get(i).lifetime -= pSecondsElapsed;
      if (plumageArray.get(i).lifetime <= 0) {
        plumageArray.get(i).detachSelf();
        plumageArray.get(i).dispose();
        plumageArray.remove(plumageArray.get(i));
      }
    }
    if (birdArray.size() < maxBirdCount) {
      if (bigBird == 1 || bigBird == 2) {
        Log.w("GAME", "addBigRight");
        birdArray.add(
            GetNewtBird(
                bigRightBirdPool,
                -BirdsSizes.bigBirdWidth,
                MathUtils.random(0, 200),
                BirdsSizes.bigBirdDuration));
        getChildByIndex(0).attachChild(birdArray.getLast());
      } else if (bigBird == 3 || bigBird == 4) {
        Log.w("GAME", "addBigLeft");
        birdArray.add(
            GetNewtBird(
                bigLeftBirdPool,
                background.getWidth(),
                MathUtils.random(0, 200),
                BirdsSizes.bigBirdDuration));
        getChildByIndex(0).attachChild(birdArray.getLast());
      }
      if (smallBird == 1 || smallBird == 2) {
        Log.w("GAME", "addSmallRight");
        birdArray.add(
            GetNewtBird(
                smallRightBirdPool,
                -BirdsSizes.smallBirdWidth,
                MathUtils.random(0, 200),
                BirdsSizes.smallBirdDuration));
        getChildByIndex(0).attachChild(birdArray.getLast());

      } else if (smallBird == 3 || smallBird == 4) {
        Log.w("GAME", "addSmallLeft");
        birdArray.add(
            GetNewtBird(
                smallLeftBirdPool,
                background.getWidth(),
                MathUtils.random(0, 200),
                BirdsSizes.smallBirdDuration));
        getChildByIndex(0).attachChild(birdArray.getLast());
      }
    }
    for (int i = 0; i < birdArray.size(); i++) {
      if ((birdArray.get(i).getX() >= background.getWidth()
              && birdArray.get(i).currentDirection == DIRECTIONS.RIGHT)
          || (birdArray.get(i).getX() <= -BirdsSizes.bigBirdWidth
              && birdArray.get(i).currentType == BirdType.SIMPLE_BIG_LEFT)) {
        AddToPool(i);
      } else if ((birdArray.get(i).getX() <= -BirdsSizes.smallBirdWidth
          && birdArray.get(i).currentType == BirdType.SIMPLE_SMALL_LEFT)) {
        AddToPool(i);
      }
    }
    super.onManagedUpdate(pSecondsElapsed);
  }