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
 private void createAim() {
   aim =
       new Sprite(0, 0, resourcesManager.aimTextureRegion, vbom) {
         @Override
         protected void preDraw(GLState pGLState, Camera pCamera) {
           super.preDraw(pGLState, pCamera);
           pGLState.enableDither();
         }
       };
   aim.setPosition(camera.getXMin() + camera.getWidth() / 2, camera.getHeight() / 2);
   aim.setSize(40, 40);
   getChildByIndex(1).attachChild(aim);
 }
Exemplo n.º 3
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();
            }
          });
    }
  }
  @Override
  public void onLoadScene() {
    // mCurrentBoss = 1;
    // SFXManager.getInstance().loadSound("t_ko", ResourceManager.getActivity().getSoundManager(),
    // ResourceManager.getActivity());
    System.out.println("mCurrentBoss --> " + mCurrentBoss);
    Sprite themeBGSprite = new Sprite(0f, 0f, ResourceManager.themeBG, mVertexBufferObjectManager);
    // themeBGSprite.setScale(ResourceManager.getInstance().cameraHeight /
    // ResourceManager.themeBG.getHeight());
    themeBGSprite.setSize(mCameraWidth, mCameraHeight);
    themeBGSprite.setPosition(mCameraWidth / 2f, mCameraHeight / 2f);
    themeBGSprite.setZIndex(-90);
    attachChild(themeBGSprite);

    if (mScrollDetector == null) {
      mScrollDetector = new SurfaceScrollDetector(this);
    }
    mScrollDetector.setTriggerScrollMinimumDistance(10f);
    mBossSlider = getScensSlider();
    attachChild(mBossSlider);
    if (isKO) {
      themeRInitX = themeRInitX - mCameraWidth * (mCurrentBoss - 1);
      // mBossSlider.registerEntityModifier(new MoveXModifier(0.3F, mBossSlider.getX(),
      // themeRInitX));
      mBossSlider.setX(themeRInitX);
    }

    // 后退按钮
    ButtonSprite backBS =
        new ButtonSprite(0f, 0f, ResourceManager.backTR, mVertexBufferObjectManager);
    EntityUtil.setSize("height", 1f / 8f, backBS);
    backBS.setPosition(10f + backBS.getWidth() / 2f, mCameraHeight - 10f - backBS.getHeight() / 2f);
    attachChild(backBS);
    backBS.setOnClickListener(
        new org.andengine.entity.sprite.ButtonSprite.OnClickListener() {

          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            SceneManager.getInstance().showScene(ThemeScene.getInstance());
          }
        });
    registerTouchArea(backBS);

    // 主页按钮
    ButtonSprite homeBS =
        new ButtonSprite(0f, 0f, ResourceManager.homeTR, mVertexBufferObjectManager);
    homeBS.setSize(backBS.getWidth(), backBS.getHeight());
    homeBS.setPosition(mCameraWidth - 10f - homeBS.getWidth() / 2f, backBS.getY());
    attachChild(homeBS);
    homeBS.setOnClickListener(
        new org.andengine.entity.sprite.ButtonSprite.OnClickListener() {

          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            SceneManager.getInstance().showScene(MainMenuScene.getInstance());
          }
        });
    registerTouchArea(homeBS);

    // 向左箭头
    ButtonSprite arrowLeftSprite =
        new ButtonSprite(
            0f, 0f, ResourceManager.arrowLRTTR.getTextureRegion(0), mVertexBufferObjectManager);
    EntityUtil.setSize("height", 1f / 8f, arrowLeftSprite);
    arrowLeftSprite.setPosition(backBS.getX(), mCameraHeight / 2f);
    attachChild(arrowLeftSprite);
    arrowLeftSprite.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            mBossSlider.clearEntityModifiers();
            if (mCurrentBoss == 1) {
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(0.3F, mBossSlider.getX(), mBossSlider.getWidth() / 2f));
            } else {
              mCurrentBoss--;
              themeRInitX = themeRInitX + mCameraWidth;
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(0.3F, mBossSlider.getX(), themeRInitX));
            }
            System.out.println("mCurrentBoss --> " + mCurrentBoss);
          }
        });
    registerTouchArea(arrowLeftSprite);
    // 向右箭头
    ButtonSprite arrowRightSprite =
        new ButtonSprite(
            0f, 0f, ResourceManager.arrowLRTTR.getTextureRegion(1), mVertexBufferObjectManager);
    arrowRightSprite.setSize(arrowLeftSprite.getWidth(), arrowLeftSprite.getHeight());
    arrowRightSprite.setPosition(homeBS.getX(), mCameraHeight / 2f);
    attachChild(arrowRightSprite);
    arrowRightSprite.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            mBossSlider.clearEntityModifiers();
            if (mCurrentBoss == bossPics.length) {
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(
                      0.3F,
                      mBossSlider.getX(),
                      mBossSlider.getWidth() / 2f - mCameraWidth * (bossPics.length - 1)));
            } else {
              mCurrentBoss++;
              themeRInitX = themeRInitX - mCameraWidth;
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(0.3F, mBossSlider.getX(), themeRInitX));
            }
            System.out.println("mCurrentBoss --> " + mCurrentBoss);
          }
        });
    registerTouchArea(arrowRightSprite);
  }