Ejemplo n.º 1
0
  private void createHUD() {
    gameHUD = new HUD();
    scoreText = new Text(0, 0, resourcesManager.gameFont, "Loading...", vbom);
    scoreText.setSkewCenter(0, 0);
    scoreText.setText("Score: 0");
    scoreText.setColor(Color.BLACK);
    gameHUD.attachChild(scoreText);

    timeText = new Text(380, 10, resourcesManager.gameFont, "Loading...", vbom);
    timeText.setSkewCenter(0, 0);
    timeText.setText(String.valueOf(timeLeft));
    timeText.setColor(Color.BLACK);
    gameHUD.attachChild(timeText);

    gameHUD.setChildScene(joystick);
    camera.setHUD(gameHUD);
  }
 private static void addLoadingMessage(Context context, Engine engine, Scene scene) {
   Font font = ResourceRegistry.getFont();
   Text label =
       new Text(
           0, 0, font, context.getString(R.string.loading), engine.getVertexBufferObjectManager());
   label.setHorizontalAlign(HorizontalAlign.CENTER);
   label.setX(engine.getCamera().getCenterX() - label.getWidth() / 2);
   label.setY(engine.getCamera().getCenterY() - label.getHeight() / 2);
   label.setColor(Color.WHITE);
   scene.attachChild(label);
 }
Ejemplo n.º 3
0
 public Modal(CommonResource resource, String label) {
   text =
       new Text(0, 0, resource.getRegularFont(), label, resource.getVertexBufferObjectManager());
   text.setColor(Color.WHITE);
   PositionHelper pos =
       new PositionHelper(resource.getScreenWidth(), resource.getScreenHeight())
           .setAnchorX(PositionHelper.AnchorX.LEFT)
           .setAnchorY(PositionHelper.AnchorY.BOTTOM)
           .setWidth((int) text.getWidth() + resource.getDPI() / 2)
           .setHeight((int) text.getHeight() + resource.getDPI() / 2);
   shadow = new UiShadow(resource, pos);
   attachChild(shadow);
   shadow.attachChild(text);
   text.setPosition(
       (pos.getDimension().x() - text.getWidth()) / 2,
       (pos.getDimension().y() - text.getHeight()) / 2);
 }
Ejemplo n.º 4
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);
  }