예제 #1
0
  @Override
  public void onSolvedGame() {

    restartButton.setVisible(false);

    Level level = gameService.getLevel();
    final LevelResult levelResult = levelService.calculateLevelResult(level);
    levelService.persistLevelResult(levelResult);

    int nextLevelId = level.getId() + 1;
    levelService.unlockLevel(nextLevelId);
    this.leaveScene = true;
    engine.registerUpdateHandler(
        new TimerHandler(
            1.5f,
            new ITimerCallback() {

              @Override
              public void onTimePassed(TimerHandler pTimerHandler) {

                engine.unregisterUpdateHandler(pTimerHandler);
                storyService.loadScoreScreen(levelResult);
              }
            }));
  }
예제 #2
0
  @Override
  protected void addButtons() {

    restartButton =
        new ButtonSprite(
            camera.getWidth() - 300,
            (camera.getHeight() - 300),
            resourcesManager.restartRegion,
            vbom,
            new ButtonSprite.OnClickListener() {

              @Override
              public void onClick(
                  ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {

                storyService.loadGameSceneFromGameScene(levelBackup);
              }
            });
    restartButton.setWidth(300);
    restartButton.setHeight(300);
    registerTouchArea(restartButton);
    attachChild(restartButton);
  }
예제 #3
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);
  }
  @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);
  }
예제 #5
0
  @Override
  public void onLoadScene() {
    // Load the menu resources
    ResourceManager.loadMenuResources();

    // Create the background
    BackgroundSprite =
        new Sprite(
            ResourceManager.getInstance().cameraWidth / 2f,
            ResourceManager.getInstance().cameraHeight / 2f,
            ResourceManager.menuBackgroundTextureRegion,
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    BackgroundSprite.setScaleX(ResourceManager.getInstance().cameraWidth);
    BackgroundSprite.setScaleY(ResourceManager.getInstance().cameraHeight / 480f);
    BackgroundSprite.setZIndex(-5000);
    this.attachChild(BackgroundSprite);

    // Create clouds that move from one side of the screen to the other, and repeat.
    CloudSprites = new Sprite[20];
    for (Sprite curCloudSprite : CloudSprites) {
      curCloudSprite =
          new Sprite(
              MathUtils.random(
                  -(this.getWidth() * this.getScaleX()) / 2,
                  ResourceManager.getInstance().cameraWidth
                      + (this.getWidth() * this.getScaleX()) / 2),
              MathUtils.random(
                  -(this.getHeight() * this.getScaleY()) / 2,
                  ResourceManager.getInstance().cameraHeight
                      + (this.getHeight() * this.getScaleY()) / 2),
              ResourceManager.cloudTextureRegion,
              ResourceManager.getInstance().engine.getVertexBufferObjectManager()) {
            private float XSpeed = MathUtils.random(0.2f, 2f);
            private boolean initialized = false;

            @Override
            protected void onManagedUpdate(final float pSecondsElapsed) {
              super.onManagedUpdate(pSecondsElapsed);
              if (!initialized) {
                initialized = true;
                this.setScale(XSpeed / 2);
                this.setZIndex(-4000 + Math.round(XSpeed * 1000f));
                MainMenu.getInstance().sortChildren();
              }
              if (this.getX() < -(this.getWidth() * this.getScaleX()) / 2) {
                XSpeed = MathUtils.random(0.2f, 2f);
                this.setScale(XSpeed / 2);
                this.setPosition(
                    ResourceManager.getInstance().cameraWidth
                        + (this.getWidth() * this.getScaleX()) / 2,
                    MathUtils.random(
                        -(this.getHeight() * this.getScaleY()) / 2,
                        ResourceManager.getInstance().cameraHeight
                            + (this.getHeight() * this.getScaleY()) / 2));

                this.setZIndex(-4000 + Math.round(XSpeed * 1000f));
                MainMenu.getInstance().sortChildren();
              }
              this.setPosition(this.getX() - (XSpeed * (pSecondsElapsed / 0.016666f)), this.getY());
            }
          };
      this.attachChild(curCloudSprite);
    }

    // Create a Play button. Notice that the Game scenes, unlike menus, are not referred to in a
    // static way.
    PlayButton =
        new ButtonSprite(
            (ResourceManager.getInstance().cameraWidth
                    - ResourceManager.buttonTiledTextureRegion.getTextureRegion(0).getWidth())
                / 2f,
            (ResourceManager.getInstance().cameraHeight
                    - ResourceManager.buttonTiledTextureRegion.getTextureRegion(0).getHeight())
                * (1f / 3f),
            ResourceManager.buttonTiledTextureRegion.getTextureRegion(0),
            ResourceManager.buttonTiledTextureRegion.getTextureRegion(1),
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    PlayButtonText =
        new Text(
            0,
            0,
            ResourceManager.fontDefault32Bold,
            "PLAY",
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    PlayButtonText.setPosition((PlayButton.getWidth()) / 2, (PlayButton.getHeight()) / 2);
    PlayButton.attachChild(PlayButtonText);
    this.attachChild(PlayButton);
    PlayButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            // Create a new GameLevel and show it using the SceneManager. And play a click.
            SceneManager.getInstance().showScene(new GameLevel());
            ResourceManager.clickSound.play();
          }
        });
    this.registerTouchArea(PlayButton);

    // Create an Option button. Notice that the SceneManager is being told to not pause the scene
    // while the OptionsLayer is open.
    OptionsButton =
        new ButtonSprite(
            PlayButton.getX() + PlayButton.getWidth(),
            PlayButton.getY(),
            ResourceManager.buttonTiledTextureRegion.getTextureRegion(0),
            ResourceManager.buttonTiledTextureRegion.getTextureRegion(1),
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    OptionsButtonText =
        new Text(
            0,
            0,
            ResourceManager.fontDefault32Bold,
            "OPTIONS",
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    OptionsButtonText.setPosition((OptionsButton.getWidth()) / 2, (OptionsButton.getHeight()) / 2);
    OptionsButton.attachChild(OptionsButtonText);
    this.attachChild(OptionsButton);
    OptionsButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            // Show the OptionsLayer and play a click.
            SceneManager.getInstance().showOptionsLayer(false);
            ResourceManager.clickSound.play();
          }
        });
    this.registerTouchArea(OptionsButton);

    // Create a title
    TitleText =
        new Text(
            0,
            0,
            ResourceManager.fontDefault72Bold,
            "HAPPY BIRDS",
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    TitleText.setPosition(
        (ResourceManager.getInstance().cameraWidth) / 2,
        (ResourceManager.getInstance().cameraHeight * 2) / 3f);
    TitleText.setColor(0.153f, 0.290f, 0.455f);
    this.attachChild(TitleText);
  }
예제 #6
0
  private void createButton() {
    // Button Exit
    btn_exit =
        new ButtonSprite(
            GameActivity.getCameraWidth() - shift_col / 3,
            GameActivity.getCameraHeight() / 4,
            m_resource_manager.m_button_region[Constant.BTN_EXIT],
            m_vbom) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (pTouchEvent.isActionDown()) {
              pauseGame();
              m_activity.runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      new DialogExit(m_activity).show();
                    }
                  });
            }
            return super.onAreaTouched(pTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
          }
        };
    registerTouchArea(btn_exit);
    btn_exit.setScale(0.75f);
    attachChild(btn_exit);

    // Button sound on

    btn_sound_on =
        new ButtonSprite(
            GameActivity.getCameraWidth() - shift_col / 3,
            GameActivity.getCameraHeight() / 2,
            m_resource_manager.m_button_region[Constant.BTN_SOUND_ON],
            m_vbom) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {

            if (pTouchEvent.isActionDown()) {
              this.setVisible(false);
              sound_on = false;
              btn_sound_off.setVisible(true);
            }
            return super.onAreaTouched(pTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
          }
        };
    btn_sound_on.setScale(0.75f);
    registerTouchArea(btn_sound_on);
    attachChild(btn_sound_on);
    // Button sound off
    btn_sound_off =
        new ButtonSprite(
            GameActivity.getCameraWidth() - shift_col / 3,
            GameActivity.getCameraHeight() / 2,
            m_resource_manager.m_button_region[Constant.BTN_SOUND_OFF],
            m_vbom) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (pTouchEvent.isActionDown()) {
              this.setVisible(false);
              sound_on = true;
              btn_sound_on.setVisible(true);
            }
            return super.onAreaTouched(pTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
          }
        };
    btn_sound_off.setScale(0.75f);
    btn_sound_off.setVisible(false);
    registerTouchArea(btn_sound_off);
    attachChild(btn_sound_off);
    // Button Settings
    btn_settings =
        new ButtonSprite(
            GameActivity.getCameraWidth() - shift_col / 3,
            3 * GameActivity.getCameraHeight() / 4,
            m_resource_manager.m_button_region[Constant.BTN_SETTINGS],
            m_vbom) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            pauseGame();
            if (pTouchEvent.isActionDown()) {
              //
              m_activity.runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      new DialogLevel(m_activity).show();
                    }
                  });
            }
            return super.onAreaTouched(pTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
          }
        };
    btn_settings.setScale(0.75f);
    registerTouchArea(btn_settings);
    attachChild(btn_settings);
    // Button Play
    btn_play =
        new ButtonSprite(
            shift_col / 3,
            2 * GameActivity.getCameraHeight() / 5,
            m_resource_manager.m_button_region[Constant.BTN_PLAY],
            m_vbom) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            pauseGame();
            if (pTouchEvent.isActionDown()) {
              //					this.setVisible(false);
              //	btn_pause.setVisible(true);
              m_activity.runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      new DialogPause(m_activity).show();
                    }
                  });
            }
            return super.onAreaTouched(pTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
          }
        };
    btn_play.setScale(0.75f);
    registerTouchArea(btn_play);

    attachChild(btn_play);

    //		btn_pause = new ButtonSprite(shift_col/3 , 2*GameActivity.getCameraHeight()/5,
    // m_resource_manager.m_button_region[Constant.BTN_PAUSE], m_vbom){
    //			@Override
    //			public boolean onAreaTouched(TouchEvent pTouchEvent, float pTouchAreaLocalX, float
    // pTouchAreaLocalY) {
    //				if(pTouchEvent.isActionDown()) {
    //					this.setVisible(false);
    //					btn_play.setVisible(true);
    //					resumeGame();
    //
    //				}
    //				return super.onAreaTouched(pTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
    //			}
    //
    //		};
    //		btn_pause.setScale(0.75f);
    //		registerTouchArea(btn_pause);
    //		btn_pause.setVisible(false);
    //		attachChild(btn_pause);

    // Button restart
    btn_restart =
        new ButtonSprite(
            shift_col / 3,
            GameActivity.getCameraHeight() / 5,
            m_resource_manager.m_button_region[Constant.BTN_RESTART],
            m_vbom) {
          @Override
          public boolean onAreaTouched(
              TouchEvent pTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            if (pTouchEvent.isActionDown()) {
              restartGame();
            }
            return super.onAreaTouched(pTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
          }
        };
    btn_restart.setScale(0.75f);
    registerTouchArea(btn_restart);
    attachChild(btn_restart);
  }