@Override
  public Scene onCreateScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

    final Scene scene = new Scene();
    scene.setBackground(new Background(0, 0, 0));

    for (int i = 0; i < COUNT; i++) {
      final float tension = MathUtils.random(-0.5f, 0.5f);
      this.addRectangleWithTension(scene, tension, MathUtils.random(0, DURATION * 2f));
    }

    return scene;
  }
Example #2
0
 public static final <T> T random(final List<T> pList) {
   return pList.get(MathUtils.random(0, pList.size() - 1));
 }
Example #3
0
 @Override
 protected Bird onAllocatePoolItem() {
   Log.e("GAME", "NewSmallLeft");
   return new SimpleBirdL(
       background.getWidth(), MathUtils.random(0, 200), BirdType.SIMPLE_SMALL_LEFT);
 }
Example #4
0
 @Override
 protected Bird onAllocatePoolItem() {
   Log.e("GAME", "NewSmallRight");
   return new SimpleBirdR(
       -BirdsSizes.smallBirdWidth, MathUtils.random(0, 200), BirdType.SIMPLE_SMALL_RIGHT);
 }
Example #5
0
  @Override
  protected void onManagedUpdate(float pSecondsElapsed) {
    if (score > record) record = score;
    FPScounter++;
    if (FPScounter == FPS) {
      FPScounter = 0;
      timeLeft--;
      timeText.setText(String.valueOf(timeLeft));
      FPScounter = 0;
    }
    if (timeLeft == 0) this.onBackKeyPressed();

    int bigBird = MathUtils.random(0, 800);
    int smallBird = MathUtils.random(0, 1000);
    for (int i = 0; i < plumageArray.size(); i++) {
      plumageArray.get(i).lifetime -= pSecondsElapsed;
      if (plumageArray.get(i).lifetime <= 0) {
        plumageArray.get(i).detachSelf();
        plumageArray.get(i).dispose();
        plumageArray.remove(plumageArray.get(i));
      }
    }
    if (birdArray.size() < maxBirdCount) {
      if (bigBird == 1 || bigBird == 2) {
        Log.w("GAME", "addBigRight");
        birdArray.add(
            GetNewtBird(
                bigRightBirdPool,
                -BirdsSizes.bigBirdWidth,
                MathUtils.random(0, 200),
                BirdsSizes.bigBirdDuration));
        getChildByIndex(0).attachChild(birdArray.getLast());
      } else if (bigBird == 3 || bigBird == 4) {
        Log.w("GAME", "addBigLeft");
        birdArray.add(
            GetNewtBird(
                bigLeftBirdPool,
                background.getWidth(),
                MathUtils.random(0, 200),
                BirdsSizes.bigBirdDuration));
        getChildByIndex(0).attachChild(birdArray.getLast());
      }
      if (smallBird == 1 || smallBird == 2) {
        Log.w("GAME", "addSmallRight");
        birdArray.add(
            GetNewtBird(
                smallRightBirdPool,
                -BirdsSizes.smallBirdWidth,
                MathUtils.random(0, 200),
                BirdsSizes.smallBirdDuration));
        getChildByIndex(0).attachChild(birdArray.getLast());

      } else if (smallBird == 3 || smallBird == 4) {
        Log.w("GAME", "addSmallLeft");
        birdArray.add(
            GetNewtBird(
                smallLeftBirdPool,
                background.getWidth(),
                MathUtils.random(0, 200),
                BirdsSizes.smallBirdDuration));
        getChildByIndex(0).attachChild(birdArray.getLast());
      }
    }
    for (int i = 0; i < birdArray.size(); i++) {
      if ((birdArray.get(i).getX() >= background.getWidth()
              && birdArray.get(i).currentDirection == DIRECTIONS.RIGHT)
          || (birdArray.get(i).getX() <= -BirdsSizes.bigBirdWidth
              && birdArray.get(i).currentType == BirdType.SIMPLE_BIG_LEFT)) {
        AddToPool(i);
      } else if ((birdArray.get(i).getX() <= -BirdsSizes.smallBirdWidth
          && birdArray.get(i).currentType == BirdType.SIMPLE_SMALL_LEFT)) {
        AddToPool(i);
      }
    }
    super.onManagedUpdate(pSecondsElapsed);
  }
  @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);
  }