public AfterGameScreen(Game game, AudioManager audioManager) {
    this.game = game;
    font = new BitmapFont();
    skin = new Skin();
    this.audioManager = audioManager;

    batch = new SpriteBatch();
    background = new Texture(Gdx.files.internal("homescreen/deadscene.png"));
    background.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    sprite = new Sprite(background);
    backgroundRegion = new TextureRegion(background);

    buttonTexture = new Texture(Gdx.files.internal("buttons/backmenu.png"));
    buttonTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

    buttonTextureRegion = new TextureRegion(buttonTexture);

    buttonTexturePlay = new Texture(Gdx.files.internal("buttons/playagain.png"));
    buttonTexturePlay.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

    buttonTextureRegionPlay = new TextureRegion(buttonTexturePlay);

    style = new TextButton.TextButtonStyle();
    style.up = new TextureRegionDrawable(buttonTextureRegion);
    style.down = new TextureRegionDrawable(buttonTextureRegion);
    style.font = font;

    stylePlay = new TextButton.TextButtonStyle();
    stylePlay.up = new TextureRegionDrawable(buttonTextureRegionPlay);
    stylePlay.down = new TextureRegionDrawable(buttonTextureRegionPlay);
    stylePlay.font = font;

    exitButton = new TextButton("", style);
    exitButton.setBounds(Gdx.graphics.getWidth() / 2 - 154, 30, 144, 96);
    playButton = new TextButton("", stylePlay);
    playButton.setBounds(Gdx.graphics.getWidth() / 2 + 10, 30, 144, 96);

    stage = new Stage();
    Gdx.input.setInputProcessor(stage);

    stage.addActor(exitButton);
    stage.addActor(playButton);
  }
Exemple #2
0
  public static void make(int size, TextureRegion region1, TextureRegion region2) {

    FontGenerator.generate(size);
    font = FontGenerator.returnFont();

    style = new TextButton.TextButtonStyle();
    style.up = new TextureRegionDrawable(region1);
    style.down = new TextureRegionDrawable(region2);
    style.font = font;
  }
Exemple #3
0
  public StartScreen(SpaceSim game) {
    this.game = game;
    background = new Texture(Gdx.files.internal("bg5.jpg"));
    batch = new SpriteBatch();
    stage = new Stage();
    heading = "Space Simulator";

    Gdx.input.setInputProcessor(stage);

    FreeTypeFontGenerator generator =
        new FreeTypeFontGenerator(Gdx.files.internal("fonts/Philosopher-Regular.ttf"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    buttonFont = generator.generateFont(parameter);
    buttonFont.setColor(1, 1, 1, 1);
    parameter.size = 72;
    headingFont = generator.generateFont(parameter);
    headingFont.setColor(1, 1, 1, 1);
    generator.dispose();

    GlyphLayout layout = new GlyphLayout(headingFont, heading);
    headingX = (int) ((Gdx.graphics.getWidth() / 2) - (layout.width / 2));
    headingY = 550;

    this.skin = new Skin();
    this.skin.add("default", buttonFont);

    Pixmap pixmap = new Pixmap(200, 50, Pixmap.Format.RGB888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    this.skin.add("background", new Texture(pixmap));

    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = this.skin.newDrawable("background", Color.GRAY);
    textButtonStyle.over = this.skin.newDrawable("background", Color.LIGHT_GRAY);
    textButtonStyle.font = this.skin.getFont("default");
    this.skin.add("default", textButtonStyle);

    TextButton startButton = new TextButton("Start", this.skin);
    startButton.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            StartScreen.this.game.setScreen(new GalaxyMapScreen(StartScreen.this.game));
          };
        });
    startButton.setPosition((Gdx.graphics.getWidth() / 2) - (startButton.getWidth() / 2), 300);

    this.stage.addActor(startButton);
  }
Exemple #4
0
  public static void createSkin() {
    /// Create a font
    BitmapFont font = new BitmapFont();
    skin = new Skin();
    skin.add("default", font);

    /// Create a texture
    Pixmap pixmap =
        new Pixmap(
            (int) Gdx.graphics.getWidth() / 4,
            (int) Gdx.graphics.getHeight() / 10,
            Pixmap.Format.RGB888);
    pixmap.setColor(Color.RED);
    pixmap.fill();
    skin.add("background", new Texture(pixmap));

    /// Create a button style
    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("background", Color.GRAY);
    textButtonStyle.down = skin.newDrawable("background", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("background", Color.DARK_GRAY);
    textButtonStyle.over = skin.newDrawable("background", Color.LIGHT_GRAY);
    textButtonStyle.font = skin.getFont("default");
    skin.add("default", textButtonStyle);

    /// Create Title Style
    Label.LabelStyle labelStyle = new Label.LabelStyle();
    labelStyle.fontColor = Color.RED;
    Pixmap titlePixmap =
        new Pixmap(
            (int) Gdx.graphics.getWidth() / 4,
            (int) Gdx.graphics.getHeight() / 10,
            Pixmap.Format.RGB888);
    titlePixmap.setColor(Color.CLEAR);
    titlePixmap.fill();
    skin.add("titleBackground", new Texture(titlePixmap));
    labelStyle.background = skin.newDrawable("titleBackground", Color.CLEAR);
    labelStyle.font = skin.getFont("default");
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Nearest);
    skin.add("default", labelStyle);
  }
  private void showDialog(String errorMessage, ButtonType[] buttons) {

    Dialog out =
        new Dialog(
            "",
            new Window.WindowStyle(
                screen.uiSkin.getFont("default-font"),
                Color.WHITE,
                new TextureRegionDrawable(Assets.miscellaneous.findRegion("dialog_panel")))) {
          @Override
          protected void result(Object object) {
            if (((String) object).contains("continue")) {
              callback.onContinue();
            } else if (((String) object).contains("retry")) {
              if (callback instanceof GetLeaderboardScoresDialogCallback) getLeaderboardScores();
              else updateStats();
            } else { // if goBack
              callback.onGoBack();
            }
          }
        };

    out.getCell(out.getContentTable()).height(306f);
    out.getContentTable().center().padTop(12f);

    out.getCell(out.getButtonTable()).height(303f);
    out.getButtonTable().center().padBottom(23f).defaults().padTop(11f);

    Label.LabelStyle labelStyle =
        new Label.LabelStyle(screen.uiSkin.getFont("default-font"), Color.WHITE);

    Label title = new Label("Erro a guardar a\npontuação", labelStyle);
    title.setAlignment(Align.center);
    out.text(title).getContentTable().row();
    out.getContentTable().getCells().peek().padBottom(40f);

    Label message = new Label(errorMessage, labelStyle);
    message.setAlignment(Align.center);
    message.setFontScale(0.8f);
    out.text(message).getContentTable().row();

    TextButton.TextButtonStyle buttonStyle =
        new TextButton.TextButtonStyle(
            new TextureRegionDrawable(Assets.miscellaneous.findRegion("dialog_button_up")),
            new TextureRegionDrawable(Assets.miscellaneous.findRegion("dialog_button_down")),
            null,
            screen.uiSkin.getFont("default-font"));
    buttonStyle.fontColor = Color.WHITE;

    for (ButtonType buttonType : buttons) {
      switch (buttonType) {
        case CONTINUE:
          out.button("continuar", "continue", buttonStyle).getButtonTable().row();
          break;
        case GO_BACK:
          out.button("cancelar", "goBack", buttonStyle).getButtonTable().row();
          break;
        case RETRY:
          out.button("tentar novamente", "retry", buttonStyle).getButtonTable().row();
          break;
      }
    }

    for (Actor actor : out.getButtonTable().getChildren()) {
      TextButton button = (TextButton) actor;
      button.getLabel().setFontScale(0.8f);
    }

    out.show(stage);
  }
  public WinnerScreen(ArrayList<Integer> playerPositions, Game game, Client client, Server server) {
    super(game, client, server);

    // Set input and viewpoint
    stage = new Stage(new StretchViewport(Constants.SCREENWIDTH, Constants.SCREENHEIGHT));
    Gdx.input.setInputProcessor(stage);

    // Unhides the cursor
    Gdx.input.setCursorCatched(false);

    this.playerPositions = playerPositions;

    // Set background
    rootTable.background(
        new TextureRegionDrawable(new TextureRegion(TextureManager.hostBackground)));
    rootTable.setFillParent(true);
    stage.addActor(rootTable);

    // Initialise Font
    FreeTypeFontGenerator.FreeTypeFontParameter fontOptions =
        new FreeTypeFontGenerator.FreeTypeFontParameter();
    fontOptions.size = 11;
    BitmapFont font = TextureManager.menuFont.generateFont(fontOptions);

    /** ------------------------LABEL STYLE------------------------* */
    Label.LabelStyle labelStyle = new Label.LabelStyle();
    fontOptions.size = 60;
    labelStyle.font = TextureManager.menuFont.generateFont(fontOptions);
    labelStyle.fontColor = Color.GOLD;

    /** ------------------------PLAYER DISPLAY WIDGET------------------------* */
    // Table options
    Table table = new Table();
    table.setFillParent(true);

    // P1 spawn field
    p1Field = new Container();
    p1Field.background(new TextureRegionDrawable(TextureManager.p1WalkingDownAnim.getKeyFrame(0)));
    table.add(p1Field).width(64).height(64);

    // P2 spawn field
    p2Field = new Container();
    p2Field.setVisible(false);
    p2Field.background(new TextureRegionDrawable(TextureManager.p2WalkingDownAnim.getKeyFrame(0)));
    table.add(p2Field).width(64).height(64).padLeft(96);

    // P3 spawn field
    p3Field = new Container();
    p3Field.setVisible(false);
    p3Field.background(new TextureRegionDrawable(TextureManager.p3WalkingDownAnim.getKeyFrame(0)));
    table.add(p3Field).width(64).height(64).padLeft(96);

    // P4 spawn field
    p4Field = new Container();
    p4Field.setVisible(false);
    p4Field.background(new TextureRegionDrawable(TextureManager.p4WalkingDownAnim.getKeyFrame(0)));
    table.add(p4Field).width(64).height(64).padLeft(96);

    // Stage & group options
    joinedPlayerGroup.addActor(table);
    joinedPlayerGroup.setPosition(443, 150);
    stage.addActor(joinedPlayerGroup);

    /** ------------------------PLAYER HIGHLIGHT WIDGET------------------------* */
    // Table options
    Table table2 = new Table();
    table2.setFillParent(true);

    // P1 spawn field
    p1FieldHighlight = new Container();
    p1FieldHighlight.setVisible(false);
    p1FieldHighlight.background(
        new TextureRegionDrawable(new TextureRegion(TextureManager.playerMarker)));
    table2.add(p1FieldHighlight).width(80).height(77);

    // P2 spawn field
    p2FieldHighlight = new Container();
    p2FieldHighlight.setVisible(false);
    p2FieldHighlight.background(
        new TextureRegionDrawable(new TextureRegion(TextureManager.playerMarker)));
    table2.add(p2FieldHighlight).width(80).height(77).padLeft(80);

    // P3 spawn field
    p3FieldHighlight = new Container();
    p3FieldHighlight.setVisible(false);
    p3FieldHighlight.background(
        new TextureRegionDrawable(new TextureRegion(TextureManager.playerMarker)));
    table2.add(p3FieldHighlight).width(80).height(77).padLeft(80);

    // P4 spawn field
    p4FieldHighlight = new Container();
    p4FieldHighlight.setVisible(false);
    p4FieldHighlight.background(
        new TextureRegionDrawable(new TextureRegion(TextureManager.playerMarker)));
    table2.add(p4FieldHighlight).width(80).height(77).padLeft(80);

    // Stage & group options
    playerhighlightWidget.addActor(table2);
    playerhighlightWidget.setPosition(442, 152);
    stage.addActor(playerhighlightWidget);

    /** ------------------------LABELS------------------------* */

    // Titel
    titel = new Label("", labelStyle);
    titel.setAlignment(Align.center);
    titel.setPosition((Constants.SCREENWIDTH - titel.getWidth()) / 2 + 50, 385);
    stage.addActor(titel);

    // If you are the winner
    if (Constants.PLAYERID == playerPositions.get(playerPositions.size() - 1)) {
      titel.setText("YOU WON!");
      isWinner = true;
    } else {
      isWinner = false;
      titel.setText("YOU LOOSE!");
      titel.setColor(Color.RED);
    }

    if (-1 == playerPositions.get(playerPositions.size() - 1)) {
      titel.setText("DRAW!");
      titel.setColor(Color.DARK_GRAY);
      isWinner = false;
    }

    Table positionTable = new Table();
    positionTable.setFillParent(true);

    p1Position = new Label("", labelStyle);
    p1Position.setAlignment(Align.center);

    p2Position = new Label("", labelStyle);
    p2Position.setAlignment(Align.center);

    p3Position = new Label("", labelStyle);
    p3Position.setAlignment(Align.center);

    p4Position = new Label("", labelStyle);
    p4Position.setAlignment(Align.center);

    positionTable.add(p1Position).width(64).height(64);
    positionTable.add(p2Position).width(64).height(64).padLeft(96);
    positionTable.add(p3Position).width(64).height(64).padLeft(96);
    positionTable.add(p4Position).width(64).height(64).padLeft(96);

    positionPlayerWidget.addActor(positionTable);
    positionPlayerWidget.setPosition(443, 230);
    stage.addActor(positionPlayerWidget);

    /** ------------------------MUSIC------------------------* */
    if (isWinner == false) {
      AudioManager.setCurrentMusic(AudioManager.getLooserMusic());
      AudioManager.getCurrentMusic().setLooping(true);
      AudioManager.getCurrentMusic().play();
      AudioManager.getCurrentMusic().setVolume(AudioManager.getMusicVolume() * 4);
    } else {
      AudioManager.setCurrentMusic(AudioManager.getWinnerMusic());
      AudioManager.getCurrentMusic().setLooping(true);
      AudioManager.getCurrentMusic().play();
      AudioManager.getCurrentMusic().setVolume(AudioManager.getMusicVolume() * 6);
    }

    /** ------------------------BUTTONS------------------------* */
    TextButton.TextButtonStyle textButtonStyleBack = new TextButton.TextButtonStyle();
    textButtonStyleBack.font = font;
    textButtonStyleBack.up = backSkin.getDrawable("button_up");
    textButtonStyleBack.down = backSkin.getDrawable("button_down");
    textButtonStyleBack.over = backSkin.getDrawable("button_checked");

    // Back button
    backButton = new TextButton("", textButtonStyleBack);
    backButton.setPosition(0, Constants.SCREENHEIGHT - backButton.getHeight() + 7);
    stage.addActor(backButton);

    renderPlayers();

    // Add click listener --> Back button
    backButton.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            // Add click musik
            AudioManager.playClickSound();

            // Wait till sound is done
            try {
              Thread.sleep(100);

            } catch (InterruptedException ex) {

            }

            if (isWinner) {
              AudioManager.getCurrentMusic().stop();
            } else {
              AudioManager.getCurrentMusic().stop();
            }

            server.stopServer();
            game.setScreen(new MenuScreen(game, client, server));
          }
        });
  }
  public MainMenuScreen(final SpaceLord2Game game, final ActionResolver resolver) {
    this.game = game;
    this.resolver = resolver;

    this.game.font = new BitmapFont();
    this.game.font.getData().scale(3);
    this.game
        .font
        .getRegion()
        .getTexture()
        .setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

    title = new Texture(Gdx.files.internal("space_lord_2_title.png"));

    backGround = new BackGround();

    table = new Table();
    table.defaults().width(600).padBottom(100);

    stage = new Stage(new FitViewport(GameConstants.GAME_WIDTH, GameConstants.GAME_HEIGHT));

    Gdx.input.setInputProcessor(stage);

    launchSound = Gdx.audio.newSound(Gdx.files.internal("sounds/space.mp3"));

    buttonClick = Gdx.audio.newSound(Gdx.files.internal("sounds/button_click.mp3"));

    skin = new Skin();
    skin.add("default", game.font);
    Pixmap pixmap = new Pixmap(100, 100, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.GRAY);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));

    // Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this
    // doesn't overwrite the font.
    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("white", Color.WHITE);
    textButtonStyle.checked = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);

    textButtonStyle.font = skin.getFont("default");

    skin.add("default", textButtonStyle);

    // Create a button with the "default" TextButtonStyle. A 3rd parameter can be used to specify a
    // name other than "default".
    final TextButton playButton = new TextButton("Play", textButtonStyle);
    table.add(playButton);
    table.row();

    final TextButton leaderboardButton = new TextButton("Leaderboard", textButtonStyle);
    table.add(leaderboardButton);
    table.row();

    final TextButton achievementButton = new TextButton("Achievements", textButtonStyle);
    table.add(achievementButton);
    table.row();

    signInButton = new TextButton("Sign In", textButtonStyle);

    table.add(signInButton);
    table.row();

    table.setPosition(GameConstants.GAME_WIDTH / 3, (GameConstants.GAME_HEIGHT / 5) * 2);

    stage.addActor(table);

    playButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            buttonClick.play();
            game.setScreen(new SpaceLord2(game, resolver));
            dispose();
          }
        });

    leaderboardButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            resolver.showLeaderboard();
          }
        });

    achievementButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            resolver.showAchievements();
          }
        });

    signInButton.addListener(
        new ChangeListener() {
          public void changed(ChangeEvent event, Actor actor) {
            buttonClick.play();
            resolver.signIn();
          }
        });

    camera = new OrthographicCamera();
    viewport = new FitViewport(GameConstants.GAME_WIDTH, GameConstants.GAME_HEIGHT, camera);
    viewport.apply();
    camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0);
  }