Exemplo n.º 1
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);
  }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
0
  public void addShield() {
    detachChild(activity.shieldSpriteP);

    activity.shieldSpriteP =
        new Sprite(0, 0, activity.shieldRegion, activity.getVertexBufferObjectManager());
    activity.shieldSpriteP.setSize(
        activity.mCamera.getWidth() / 15.4f, activity.mCamera.getWidth() / 15.4f);
    activity.shieldSpriteP.setZIndex(1);

    Random rand = new Random();
    int rangex = (int) (mCamera.getWidth() - 100 - activity.shieldSpriteP.getWidth());
    int rangey = (int) (mCamera.getHeight() - 100 - activity.shieldSpriteP.getHeight());
    int x = rand.nextInt(rangex);
    int y = rand.nextInt(rangey);

    activity.shieldSpriteP.setPosition(x + 50, y + 50);

    attachChild(activity.shieldSpriteP);
    shieldHit = false;
  }
Exemplo n.º 4
0
  public void addBonus() {
    if (activity.bonusSprite.hasParent()) {
      detachChild(activity.bonusSprite);
    }

    activity.bonusSprite =
        new Sprite(0, 0, activity.bonusRegion, activity.getVertexBufferObjectManager());
    activity.bonusSprite.setSize(
        activity.mCamera.getWidth() / 15.4f, activity.mCamera.getWidth() / 15.4f);
    activity.bonusSprite.setZIndex(1);

    Random rand = new Random();
    int rangex = (int) (mCamera.getWidth() - 100 - activity.bonusSprite.getWidth());
    int rangey = (int) (mCamera.getHeight() - 100 - activity.bonusSprite.getHeight());
    int x = rand.nextInt(rangex);
    int y = rand.nextInt(rangey);

    activity.bonusSprite.setPosition(x + 50, y + 50);

    attachChild(activity.bonusSprite);
    bonusHit = false;
  }
Exemplo n.º 5
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();
            }
          });
    }
  }