Button3(int buttonPosition) {
      super(
          0,
          Config.Camera.HEIGHT - button3Regions[buttonPosition % 3].getHeight(),
          button3Regions[buttonPosition % 3],
          vbom);

      // Log.e(tag, "Button3");
      float[] paddingLeft = {
        0, button3Regions[0].getWidth(), button3Regions[0].getWidth() + button3Regions[1].getWidth()
      };
      setX(paddingLeft[buttonPosition % 3]);
      position = buttonPosition;

      // add icon
      Sprite mIcon = new Sprite(getX(), getY(), buttonIconsRegions[levelNumber][0], vbom);

      if (levelNumber == 9 || levelNumber == 10 || levelNumber == 11) {
        mIcon = new Sprite(getX(), getY(), buttonIconsRegions[levelNumber][position], vbom);
      }

      mIcon.setZIndex(101);

      getScene().attachChild(mIcon);
      getScene().sortChildren();
    }
Exemplo n.º 2
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);
  }
 @Override
 public void createScene() {
   createBackground();
   createMenuChildScene();
   menuChildScene.setZIndex(0);
   light.setZIndex(1);
   this.sortChildren();
 }
  private void initEffects() {

    readySprite = new Sprite(0, 0, Region.ready, vbom);
    goSprite = new Sprite(0, 0, Region.go, vbom);
    goodSprite = new Sprite(0, 0, Region.complete, vbom);
    fastSprite = new Sprite(0, 0, Region.fast, vbom);
    superFastSprite = new Sprite(0, 0, Region.superFast, vbom);
    missSprite = new Sprite(0, 0, Region.miss, vbom);

    explosion = new Sprite(0, 0, Region.explosion, vbom);
    explosion.setZIndex(1010);
  }
    Button2(int buttonPosition) {
      super(
          0,
          Config.Camera.HEIGHT - button2Regions[buttonPosition].getHeight(),
          button2Regions[buttonPosition],
          vbom);
      float[] paddingLeft = {0, button2Regions[0].getWidth()};
      setX(paddingLeft[buttonPosition]);
      position = buttonPosition;

      // add icon
      Sprite mIcon = new Sprite(getX(), getY(), buttonIconsRegions[levelNumber][0], vbom);

      // right foot
      if (levelNumber == 1 && buttonPosition == 0) {
        mIcon.setFlippedHorizontal(true);
      }

      // laces
      if (levelNumber == 8 && buttonPosition == 0) {
        mIcon.setFlippedHorizontal(true);
      }

      // ok button
      if (levelNumber == 3 && buttonPosition == 1) {
        mIcon = new Sprite(getX(), getY(), Region.buttonIconOk, vbom);
      }

      mIcon.setZIndex(101);

      getScene().attachChild(mIcon);
      cover = new Sprite(getX(), getY(), buttonCoverRegion, vbom);
      cover.setVisible(false);
      cover.setZIndex(102);
      getScene().attachChild(cover);

      getScene().sortChildren();
    }
Exemplo n.º 6
0
  public TiledImage(
      float pX,
      float pY,
      float pWidth,
      float pHeight,
      ITextureRegion pTextureRegion,
      VertexBufferObjectManager vertexBufferObjectManager,
      int voice,
      Context cont) {
    super(pX, pY, pWidth, pHeight, pTextureRegion, vertexBufferObjectManager);
    con = cont;
    ObjNo++;
    audioPlayCount = 0;
    audio = voice;
    audioPlay = false;
    mediaPlayer = new MediaPlayer();
    this.Letter =
        new Sprite(pX, pY, pTextureRegion, vertexBufferObjectManager) {
          @Override
          public boolean onAreaTouched(
              final TouchEvent pSceneTouchEvent,
              final float pTouchAreaLocalX,
              final float pTouchAreaLocalY) {
            switch (pSceneTouchEvent.getAction()) {
              case TouchEvent.ACTION_DOWN:
                {
                  this.setScale(1.09f);
                  break;
                }
              case TouchEvent.ACTION_MOVE:
                {
                  break;
                }
              case TouchEvent.ACTION_UP:
                {
                  this.setScale(1.0f);
                  audioPlay = true;
                  playAudio(audio);
                  break;
                }
              default:
                {
                }
            }
            return false;
          }
        };
    en = new Entity(0, 0);
    s = new Sprite(-20, -20, AnimatedBookActivity.SpriteBgTextureRegion, vertexBufferObjectManager);
    Letter.setWidth(pHeight - 40);
    Letter.setHeight(pHeight - 40);
    // s.setPosition(pX - 30, pY - 30);
    s.setWidth(pHeight + 10);
    s.setHeight(pHeight + 10);
    s.setZIndex(-1);
    s.setAlpha(0.8f);

    Letter.attachChild(s);

    s.setVisible(false);
    Letter.setVisible(false);

    AnimateImage();
  }
  @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);
  }
Exemplo n.º 8
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);
  }