public ResultScene(Camera mCamera) {
    super(mCamera);
    activity = BaseActivity.getSharedInstance();
    setBackgroundEnabled(false);
    GameScene scene = (GameScene) activity.mCurrentScene;
    float accureay = 1 - (float) scene.missCount / scene.bulletCount;
    if (Float.isNaN(accureay)) accureay = 0;
    accureay *= 100;
    Text result =
        new Text(
            0,
            0,
            activity.mFont,
            activity.getString(R.string.accuracy) + ": " + String.format("%.2f", accureay) + "%",
            BaseActivity.getSharedInstance().getVertexBufferObjectManager());

    final int x = (int) (mCamera.getWidth() / 2 - result.getWidth() / 2);
    final int y = (int) (mCamera.getHeight() / 2 - result.getHeight() / 2);

    done = false;
    result.setPosition(x, mCamera.getHeight() + result.getHeight());
    MoveYModifier mod =
        new MoveYModifier(5, result.getY(), y) {
          @Override
          protected void onModifierFinished(IEntity pItem) {
            done = true;
          }
        };
    attachChild(result);
    result.registerEntityModifier(mod);
    setOnSceneTouchListener(this);
  }
Пример #2
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;
  }
Пример #3
0
  public SplashScene() {
    setBackground(new Background(Color.RED));
    activity = BaseActivity.getSharedInstance();
    Text title1 =
        new Text(0, 0, activity.mFont, "Blankwall", activity.getVertexBufferObjectManager());
    Text title2 =
        new Text(0, 0, activity.mFont, "Productions", activity.getVertexBufferObjectManager());

    title1.setPosition(-title1.getWidth(), activity.mCamera.getHeight() / 2);
    title2.setPosition(activity.mCamera.getWidth(), activity.mCamera.getHeight() / 2);

    attachChild(title1);
    attachChild(title2);

    title1.registerEntityModifier(
        new MoveXModifier(1, title1.getX(), activity.mCamera.getWidth() / 2 - title1.getWidth()));
    title2.registerEntityModifier(
        new MoveXModifier(1, title2.getX(), activity.mCamera.getWidth() / 2));

    loadResources();
  }
Пример #4
0
  public GameoverScene() {
    super(BaseActivity.getSharedInstance().mCamera);
    activity = BaseActivity.getSharedInstance();

    setBackground(new Background(Color.WHITE));
    attachChild(activity.backgroundSprite);

    continueText =
        new Text(0, 0, activity.mFont, "Continue", activity.getVertexBufferObjectManager());
    continueText.setPosition(
        mCamera.getWidth() / 2 - continueText.getWidth() / 2,
        mCamera.getHeight() - continueText.getHeight() - 20);

    gameOverText =
        new Text(0, 0, activity.mFont, "Game Over", activity.getVertexBufferObjectManager());
    gameOverText.setPosition(
        mCamera.getWidth() / 2 - gameOverText.getWidth() / 2, mCamera.getHeight() / 6);

    scoreText =
        new Text(
            0,
            0,
            activity.mSmallFont,
            "Score: " + activity.score.getScore(),
            activity.getVertexBufferObjectManager());
    scoreText.setPosition(
        mCamera.getWidth() / 2 - scoreText.getWidth() / 2,
        mCamera.getHeight() / 2 - scoreText.getHeight() / 2 - gameOverText.getHeight());

    highscoreText =
        new Text(
            0,
            0,
            activity.mSmallFont,
            "Highscore: " + activity.highscore,
            activity.getVertexBufferObjectManager());
    highscoreText.setPosition(
        mCamera.getWidth() / 2 - highscoreText.getWidth() / 2,
        mCamera.getHeight() / 2
            - scoreText.getHeight() / 2
            - continueText.getHeight()
            + scoreText.getHeight()
            + activity.mCamera.getWidth() / 108f);

    IMenuItem startButton =
        new SpriteMenuItem(
            MENU_MAINMENU, activity.buttonRegion, activity.getVertexBufferObjectManager());
    startButton.setPosition(mCamera.getWidth() / 10, continueText.getY());
    startButton.setSize(mCamera.getWidth() - mCamera.getWidth() / 5, continueText.getHeight());

    Sprite panel =
        new Sprite(
            mCamera.getWidth() / 10 - mCamera.getWidth() / 20,
            gameOverText.getY() - 20,
            activity.panelRegion,
            activity.getVertexBufferObjectManager());
    panel.setSize(
        mCamera.getWidth() - mCamera.getWidth() / 10,
        mCamera.getHeight()
            - panel.getY()
            - (mCamera.getHeight() - highscoreText.getY())
            + highscoreText.getHeight()
            + 40);

    attachChild(panel);
    addMenuItem(startButton);
    attachChild(gameOverText);
    attachChild(highscoreText);
    attachChild(scoreText);
    attachChild(continueText);

    setOnMenuItemClickListener(this);

    if (activity.mGoogleApiClient == null || !activity.mGoogleApiClient.isConnected()) {
      activity.runOnUiThread(
          new Runnable() {
            @Override
            public void run() {
              Toast.makeText(
                      activity,
                      "Not connected to Google Play Services. Score not uploaded. Highscore gets uploaded automatically next time.",
                      Toast.LENGTH_LONG)
                  .show();
            }
          });
    }
  }