public void spawnSnowflake() {
    final Image snowflake = new Image(snow);
    snowflake.setOrigin(64, 64);
    int x = (int) (Math.random() * 800);
    snowflake.setPosition(x, 480);
    snowflake.setScale((float) (Math.random() * 0.8f + 0.2f));
    snowflake.addAction(
        parallel(
            forever(rotateBy(360, (float) (Math.random() * 6))),
            sequence(
                moveTo(x, 0, (float) (Math.random() * 15)),
                fadeOut((float) (Math.random() * 1)),
                new Action() { // we
                  // can
                  // define
                  // custom
                  // actions
                  // :)

                  @Override
                  public boolean act(float delta) {
                    snowflake.remove(); // delete this snowflake
                    spawnSnowflake(); // spawn a new snowflake
                    return false;
                  }
                })));
    stage.addActor(snowflake);
  }
  public SplashScreen(TestGame pGame) {
    game = pGame;

    tree =
        new Texture(
            Gdx.files.internal(
                "graphics/tree.png")); // http://openclipart.org/detail/1936/tree-by-harmonic
    christmasTree = new TextureRegion(tree, 0, 0, 450, 730);
    ball =
        new Texture(
            Gdx.files.internal(
                "graphics/ball.png")); // http://openclipart.org/detail/170738/decorative-ball-by-merlin2525-170738
    snow =
        new Texture(
            Gdx.files.internal(
                "graphics/snow.png")); // http://openclipart.org/detail/170738/decorative-ball-by-merlin2525-170738

    font = new BitmapFont(Gdx.files.internal("ui/test.fnt"), false);

    stage = new Stage();

    // our christmas tree
    Image ctree = new Image(christmasTree);
    ctree.setSize(296, 480); // scale the tree to the right size
    ctree.setPosition(-300, 0);
    ctree.addAction(moveTo(400 - 148, 0, 1f));
    ctree.setZIndex(0);
    stage.addActor(ctree);

    Image ballImage = new Image(ball);
    ballImage.setPosition(400 - 148 + 60, 170);

    ballImage.setOrigin(32, 32);
    ballImage.setColor(1, 1, 1, 0);
    ballImage.addAction(
        sequence(
            delay(1),
            parallel(fadeIn(1), rotateBy(360, 1)),
            delay(2f),
            new Action() {
              // custom action to switch to the menu screen
              @Override
              public boolean act(float delta) {
                game.setScreen(new MenuScreen(game));
                return false;
              }
            }));

    stage.addActor(ballImage);

    // create the snowflakes
    for (int i = 0; i < 10; i++) {
      spawnSnowflake();
    }
  }
Beispiel #3
0
 private void fillGroup(Group group, Texture texture) {
   float advance = 32 + SPACING;
   for (int y = 0; y < NUM_SPRITES * advance; y += advance)
     for (int x = 0; x < NUM_SPRITES * advance; x += advance) {
       Image img = new Image(new TextureRegion(texture));
       img.setAlign(Align.center);
       img.setScaling(Scaling.none);
       img.setBounds(x, y, 32, 32);
       img.setOrigin(16, 16);
       group.addActor(img);
       images.add(img);
     }
 }
Beispiel #4
0
  private void mainInit() {
    Image logo;

    logo = new Image(new Texture("resources/logo.png"));
    logo.setPosition(16, 300);
    logo.setOrigin(logo.getWidth() / 2, logo.getHeight() / 2);
    RepeatAction twinkleForever = new RepeatAction();
    twinkleForever.setAction(new SequenceAction(CustomActions.twinkle(), new DelayAction(1.3f)));
    twinkleForever.setCount(RepeatAction.FOREVER);

    logo.addAction(twinkleForever);
    music = Gdx.audio.newMusic(Gdx.files.internal("resources/music/main.mp3"));
    music.play();
    stage.addActor(logo);
  }
Beispiel #5
0
  private Image getButton(SpriteBatch batch, String text, int textColor) {
    //        final BitmapFont font = Utility.getFont();
    //        font.setColor(textColor);
    //        font.setScale(0.25f);
    //        final int h = (int) (font.getLineHeight() * 1.6f);
    //        final int w = (int) (width / 2.8f);
    //
    //        final Pixmap pixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
    //        pixmap.setColor(0xffffffff);
    //        Pixmap.setFilter(Pixmap.Filter.BiLinear);
    //        final int cy = h / 2;
    //
    //        pixmap.fillCircle(cy, cy, cy);
    //        pixmap.fillRectangle(cy, 0, w - cy - cy, pixmap.getHeight());
    //        pixmap.fillCircle(w - cy, cy, cy);
    //
    //        final Texture texture = new Texture(pixmap);
    //
    //        Gdx.gl.glClearColor(0.8627f, 0.8627f, 0.8627f, 1);
    //        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    //        final float textWidth = font.getBounds(text).width;
    //        final float textHeight = font.getLineHeight();
    //        int x = w / 2;
    //        int y = h / 2;
    //        batch.begin();
    //        batch.draw(texture, 0, 0);
    //        font.draw(batch, text, x - textWidth / 2, y + (textHeight / 3));
    //        batch.end();
    //        texture.dispose();
    //        pixmap.dispose();
    final Image image = new Image(ScreenUtils.getFrameBufferTexture(0, 0, 90, 90));
    image.setOrigin(image.getWidth() / 2, image.getHeight() / 2);
    image.setUserObject(text);

    return image;
  }
Beispiel #6
0
  private Table buildControlsLayer() {

    Table layer = new Table();
    imgPause = new Image(skinCanyonBunny, "pause");
    layer.addActor(imgPause);
    imgPause.setScale(Constants.SCALE + 0.5f);
    imgPause.setOrigin(imgPause.getWidth() / 2f, imgPause.getHeight() / 2f);
    imgPause.setPosition(
        (Gdx.graphics.getWidth() - imgPause.getWidth()) / 2f, Gdx.graphics.getHeight() * 0.8f);

    btnResume = new Button(skinCanyonBunny, "resume");
    layer.addActor(btnResume);
    btnResume.setSize(
        btnResume.getWidth() * Constants.SCALE, btnResume.getHeight() * Constants.SCALE);
    btnResume.setPosition(
        (Gdx.graphics.getWidth() - btnResume.getWidth()) / 2f, Gdx.graphics.getHeight() * 0.6f);

    btnResume.addListener(
        new ChangeListener() {

          @Override
          public void changed(ChangeEvent event, Actor actor) {
            if (continueGame) {
              gameService.getScene(TowerDefenseScene.class).setInputProcessor();
              gameService.changeScene(TowerDefenseScene.class);
              gameService.getScene(TowerDefenseScene.class).resume();
            }
          }
        });

    if (!continueGame) {
      btnResume.setColor(
          btnResume.getColor().r, btnResume.getColor().g, btnResume.getColor().b, 0.5f);
    }

    btnRestart = new Button(skinCanyonBunny, "restart");
    layer.addActor(btnRestart);
    btnRestart.setSize(
        btnRestart.getWidth() * Constants.SCALE, btnRestart.getHeight() * Constants.SCALE);
    btnRestart.setPosition(
        (Gdx.graphics.getWidth() - btnRestart.getWidth()) / 2f, Gdx.graphics.getHeight() * 0.45f);

    btnRestart.addListener(
        new ChangeListener() {

          @SuppressWarnings("static-access")
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            if (restartGame) {
              gameService
                  .getScene(TowerDefenseScene.class)
                  .loadMap(gameService.getService(Level.class).getLevelIndex());

              gameService.getScene(TowerDefenseScene.class).setInputProcessor();

              gameService.changeScene(TowerDefenseScene.class);
              gameService.getScene(TowerDefenseScene.class).hideEditWeapon();
              gameService.getService(Player.class).towerRange.visible = false;
            }
          }
        });

    if (!restartGame) {
      btnRestart.setColor(
          btnRestart.getColor().r, btnRestart.getColor().g, btnRestart.getColor().b, 0.5f);
    }

    btnLevel = new Button(skinCanyonBunny, "levelchoice");
    layer.addActor(btnLevel);
    btnLevel.setSize(btnLevel.getWidth() * Constants.SCALE, btnLevel.getHeight() * Constants.SCALE);
    btnLevel.setPosition(
        (Gdx.graphics.getWidth() - btnLevel.getWidth()) / 2f, Gdx.graphics.getHeight() * 0.3f);

    btnLevel.addListener(
        new ChangeListener() {

          @Override
          public void changed(ChangeEvent event, Actor actor) {
            gameService.getScene(LevelScene.class).setInputProcessor();
            gameService.changeScene(LevelScene.class);
          }
        });

    btnMenu = new Button(skinCanyonBunny, "menu");
    layer.addActor(btnMenu);
    btnMenu.setSize(btnMenu.getWidth() * Constants.SCALE, btnMenu.getHeight() * Constants.SCALE);
    btnMenu.setPosition(
        (Gdx.graphics.getWidth() - btnMenu.getWidth()) / 2f, Gdx.graphics.getHeight() * 0.15f);

    btnMenu.addListener(
        new ChangeListener() {

          @Override
          public void changed(ChangeEvent event, Actor actor) {
            gameService.getScene(MenuScene.class).setInputProcessor();
            gameService.changeScene(MenuScene.class);
          }
        });

    return layer;
  }
Beispiel #7
0
  @Override
  public void show() {
    super.show();

    backgroundStage.addActor(new Image(atlas.findRegion("background")));

    Image alien = new Image(atlas.findRegion("alien"));
    alien.setPosition(mainStage.getWidth() + mainStage.getPadLeft(), -365f);
    mainStage.addActor(alien);

    Image energy = new Image(atlas.findRegion("energy")); // 195, 313
    energy.setPosition(83f, 201f);
    energy.setScale(0f);
    energy.setOrigin(energy.getPrefWidth() / 2, energy.getPrefHeight() / 2);
    mainStage.addActor(energy);

    final Table certificateTable = new Table();
    certificateTable.padTop(314f).padBottom(101f).defaults().padBottom(100f);
    certificateTable.setBackground(new TextureRegionDrawable(atlas.findRegion("certificate")));
    certificateTable.setSize(mainStage.getWidth(), mainStage.getHeight());
    certificateTable.setOrigin(195f, 313f);
    certificateTable.setTransform(true);
    certificateTable.setTouchable(Touchable.disabled);
    certificateTable.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            Assets.fanfareFX.stop();
            game.loadNextScreen(EndingScreen.this, KonnectingGame.ScreenType.MAIN_MENU);
          }
        });
    certificateTable.setScale(0f);
    mainStage.addActor(certificateTable);

    StatsData tempData = SavedData.getStats();
    int score =
        tempData.kronosScore1
            + tempData.kronosScore2
            + tempData.kronosScore3
            + tempData.kronosScore4
            + tempData.kronosScore5
            + tempData.kronosScore6
            + tempData.kronosScore7
            + tempData.zappingScore1
            + tempData.zappingScore2
            + tempData.zappingScore3
            + tempData.zappingScore4
            + tempData.zappingScore5;

    final Label userLabel =
        new Label(
            SavedData.getUsername() + "\n\n" + score + "pt",
            new Label.LabelStyle(uiSkin.getFont("default-font"), Color.WHITE));
    userLabel.setWrap(true);
    userLabel.setAlignment(Align.center);
    userLabel.getColor().a = 0f;
    certificateTable.add(userLabel).width(407f).row();

    String correctComment = comments[0];
    for (int i = scoreLimits.length - 1; i >= 0; i--) {
      if (score > scoreLimits[i]) {
        correctComment = comments[i];
        break;
      }
    }
    final Label commentLabel =
        new Label(correctComment, new Label.LabelStyle(uiSkin.getFont("arial"), Color.WHITE));
    commentLabel.setWrap(true);
    commentLabel.setFontScale(0.9f);
    commentLabel.setAlignment(Align.center);
    commentLabel.getColor().a = 0f;
    certificateTable.add(commentLabel).width(407f);

    Timeline.createSequence()
        .push(Tween.to(alien, ActorAccessor.MOVE_X, 1f).target(20f))
        .pushPause(0.25f)
        .push(Tween.to(energy, ActorAccessor.SCALEXY, 1f).target(1f))
        .push(Tween.to(energy, ActorAccessor.SCALEXY, 0.5f).target(0.8f))
        .push(Tween.to(energy, ActorAccessor.SCALEXY, 0.5f).target(1f))
        .push(Tween.to(certificateTable, ActorAccessor.SCALEXY, 0.5f).target(1f))
        .beginParallel()
        .push(Tween.to(userLabel, ActorAccessor.ALPHA, 0.5f).target(1f))
        .push(Tween.to(commentLabel, ActorAccessor.ALPHA, 0.5f).target(1f))
        .end()
        .setCallback(
            new TweenCallback() {
              @Override
              public void onEvent(int type, BaseTween<?> source) {
                Assets.fanfareFX.setOnCompletionListener(
                    new Music.OnCompletionListener() {
                      @Override
                      public void onCompletion(Music music) {
                        Assets.fanfareFX.setOnCompletionListener(null);
                        certificateTable.setTouchable(Touchable.enabled);
                      }
                    });
                Assets.fanfareFX.play();
              }
            })
        .start(tweenManager);
  }
  private void rebuildStage() {
    buttonPause = new JellyButton(Assets.instance.gameElements.pause);
    buttonPause.setMyScaleSize(1.3f, 1.3f);
    buttonPause.setPosition(8, Const.GAME_HEIGHT - buttonPause.getHeight() - 8);
    buttonPause.addTouchListener(
        new RunnableAction() {
          public void run() {
            pauseUi.showWindow(true);
          }
        },
        null);

    buttonReplay = new JellyButton(Assets.instance.gameElements.replay);
    buttonReplay.setMyScaleSize(1.3f, 1.3f);
    buttonReplay.setPosition(8, Const.GAME_HEIGHT - 2 * buttonReplay.getHeight() - 15);
    buttonReplay.addTouchListener(
        new RunnableAction() {
          public void run() {
            winnerUi.showWindow(true);
            winnerUi.setTime(110);
          }
        },
        null);

    Label.LabelStyle labelStyle = new Label.LabelStyle(Assets.instance.fonts.freezers, Color.WHITE);
    gameTime = new Label("0:00", labelStyle);
    gameTime.setAlignment(Align.left);
    gameTime.setPosition(Const.GAME_WIDTH - 135, Const.GAME_HEIGHT - 60);
    gameTime.setWrap(true);
    gameTime.setWidth(350f);

    star = new Image(Assets.instance.gameElements.star);
    star.setScale(0.3f);
    star.setOrigin(star.getWidth() / 2, star.getHeight() / 2);
    star.addAction(Actions.alpha(0f));
    star1 = new Image(Assets.instance.gameElements.star);
    star1.setScale(0.3f);
    star1.setPosition(Const.GAME_WIDTH - 60, Const.GAME_HEIGHT - 92);
    star2 = new Image(Assets.instance.gameElements.star);
    star2.setScale(0.3f);
    star2.setPosition(star1.getX() - 40, Const.GAME_HEIGHT - 92);
    star3 = new Image(Assets.instance.gameElements.star);
    star3.setScale(0.3f);
    star3.setPosition(star2.getX() - 40, Const.GAME_HEIGHT - 92);

    Label.LabelStyle labelStyle2 =
        new Label.LabelStyle(Assets.instance.fonts.freezers, Color.WHITE);
    freezes = new Label("0", labelStyle2);
    freezes.setText(String.valueOf(LevelData.freezers));
    freezes.setAlignment(Align.right);
    freezes.setPosition(Const.GAME_WIDTH - 200, Const.GAME_HEIGHT - 170);
    freezes.setWrap(true);
    freezes.setWidth(100f);

    freezeFon = new Image(Assets.instance.gameElements.freezeBuyFon);
    freezeFon.setPosition(
        Const.GAME_WIDTH - 158, Const.GAME_HEIGHT - buttonReplay.getHeight() - 107);
    freezeFon.setScale(0.6f);

    buttonBuyFreeze = new JellyButton(Assets.instance.gameElements.freezeBuy);
    buttonBuyFreeze.setMyScaleSize(1.6f, 1.6f);
    buttonBuyFreeze.setPosition(
        Const.GAME_WIDTH - buttonBuyFreeze.getWidth() - 15,
        Const.GAME_HEIGHT - buttonReplay.getHeight() - 100);
    buttonBuyFreeze.addTouchListener(
        new RunnableAction() {
          public void run() {
            marketUi.showWindow(true);
          }
        },
        null);

    imgFreeze = new Image(Assets.instance.gameElements.freeze);
    imgFreeze.setOrigin(imgFreeze.getWidth() / 2, imgFreeze.getHeight() / 2);
    imgFreeze.setScale(0.7f);
    imgFreeze.setPosition(freezeFon.getX() - 17, freezeFon.getY() - 25);
    imgFreeze.addAction(Actions.alpha(0f));

    if (addHelp) {
      float delay = 5f;
      if (GamePreferences.instance.isSensorXYZ) {
        delay = 4f;
        helpNavigate = new Image(Assets.instance.menuElements.navigate_tel);
        helpNavigate.setOrigin(helpNavigate.getWidth() / 2, helpNavigate.getHeight() / 2);
        helpNavigate.setScale(0.7f);
        helpNavigate.setPosition(
            Const.GAME_WIDTH - helpNavigate.getWidth() - 25, Const.GAME_HEIGHT - 500);
        helpNavigate.addAction(
            sequence(
                Actions.alpha(0f),
                Actions.delay(2f),
                new RunnableAction() {
                  public void run() {
                    gameState = GameState.PAUSE;
                  }
                },
                Actions.alpha(1f, 0.5f),
                Actions.rotateBy(15f, 0.4f, Interpolation.fade),
                Actions.rotateBy(-30f, 0.8f, Interpolation.fade),
                Actions.rotateBy(25f, 0.7f, Interpolation.fade),
                Actions.alpha(0f, 0.4f)));
      } else {
        helpNavigate = new Image(Assets.instance.menuElements.navigate_finger);
        helpNavigate.setOrigin(helpNavigate.getWidth() / 2, helpNavigate.getHeight() / 2);
        helpNavigate.setScale(0.7f);
        helpNavigate.setPosition(
            Const.GAME_WIDTH - helpNavigate.getWidth() - 25, Const.GAME_HEIGHT - 500);
        helpNavigate.addAction(
            sequence(
                Actions.alpha(0f),
                Actions.delay(2f),
                new RunnableAction() {
                  public void run() {
                    gameState = GameState.PAUSE;
                  }
                },
                Actions.alpha(1f, 0.5f),
                Actions.moveBy(-150f, 0, 0.7f, Interpolation.fade),
                Actions.moveBy(80f, 0, 0.7f, Interpolation.fade),
                Actions.moveBy(0, 150f, 0.7f, Interpolation.fade),
                Actions.moveBy(0, -200f, 0.7f, Interpolation.linear),
                Actions.alpha(0f, 0.4f)));
      }
      helpFreeze = new Image(Assets.instance.menuElements.navigate_finger);
      helpFreeze.setOrigin(helpFreeze.getWidth() / 2, helpFreeze.getHeight() / 2);
      helpFreeze.setScale(-0.7f, 0.7f);
      helpFreeze.setPosition(helpFreeze.getWidth() + 35, Const.GAME_HEIGHT - 500);
      helpFreeze.addAction(
          sequence(
              Actions.alpha(0f),
              Actions.delay(delay),
              Actions.alpha(1f, 0.5f),
              Actions.moveBy(
                  LevelData.posX - helpFreeze.getX() + 20,
                  LevelData.posY - helpFreeze.getY() - helpFreeze.getHeight() - 28,
                  0.7f,
                  Interpolation.fade),
              new RunnableAction() {
                public void run() {
                  setAnimation(animFreezeOn);
                }
              },
              Actions.alpha(0f, 0.2f)));
    }

    if (addHelp) {
      stage.addActor(helpNavigate);
      stage.addActor(helpFreeze);
    }
    stage.addActor(buttonPause);
    stage.addActor(buttonReplay);
    stage.addActor(gameTime);
    stage.addActor(freezeFon);
    stage.addActor(freezes);
    stage.addActor(buttonBuyFreeze);
    stage.addActor(star1);
    stage.addActor(star2);
    stage.addActor(star3);
    stage.addActor(star);
    stage.addActor(imgFreeze);
    stage.addActor(levelBuilder);
    stage.addActor(winnerUi);
    stage.addActor(marketUi);
    stage.addActor(pauseUi);
  }