Beispiel #1
0
  public GameScene() {
    activity = BaseActivity.getSharedInstance();
    setBackground(new Background(Color.WHITE));
    mCamera = BaseActivity.getSharedInstance().mCamera;
    ball = Ball.getSharedInstance();
    enemies = new LinkedList();
    enemiesToBeAdded = new LinkedList();
    enemyCount = 0;
    activity.score = new Score();
    bonusHit = true;
    shieldHit = true;
    activity.isShield = false;

    scoreText =
        new Text(
            0,
            0,
            activity.mFont,
            "Score: 0000000",
            BaseActivity.getSharedInstance().getVertexBufferObjectManager());
    scoreText.setText(activity.score.toString());
    scoreText.setPosition(10, 3);

    attachChild(activity.backgroundSprite);
    attachChild(ball.sprite);
    attachChild(scoreText);
    activity.backgroundSprite.setZIndex(0);
    activity.ballSprite.setZIndex(2);
    activity.shieldSprite.setZIndex(3);
    scoreText.setZIndex(5);

    activity.setCurrentScene(this);
    sensorManager =
        (SensorManager)
            BaseActivity.getSharedInstance().getSystemService(BaseGameActivity.SENSOR_SERVICE);
    SensorListener.getSharedInstance();
    sensorManager.registerListener(
        SensorListener.getSharedInstance(),
        sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
        SensorManager.SENSOR_DELAY_GAME);

    resetValues();
    createSpriteSpawnTimeHandler();
    registerUpdateHandler(detect);
    createScoreTimeHandler();
    createBonusSpawnTimeHandler();
    createShieldSpawnTimeHandler();

    for (int i = 0; i < 3; i++) {
      addTarget();
      enemyCount++;
    }
    isLoseNow = false;
  }
Beispiel #2
0
  public void shieldCollide() {
    detachChild(activity.shieldSpriteP);
    attachChild(activity.shieldSprite);

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

    shieldHit = true;
    activity.isShield = true;

    spriteTimerHandlerShield.reset();

    activity.editor.putInt("shieldsCollected", activity.prefs.getInt("shieldsCollected", 0) + 1);
    activity.editor.commit();
  }
Beispiel #3
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;
      }
    }
  }