Skip to content

Main Menu Button Code

7ayuu edited this page Oct 5, 2021 · 1 revision

Description

the making of a button on the main menu, its listeners, event triggers, initialization and everything that makes a main menu accessible.

code snipets

  • listeners:

the listeners for events that trigger specific function which in turn cause a speicif case to occus and the appropriate screen to be set accordingly.

@Override
  public void create() {
    entity.getEvents().addListener("start", this::onStart);
    entity.getEvents().addListener("load", this::onLoad);
    entity.getEvents().addListener("exit", this::onExit);
    entity.getEvents().addListener("settings", this::onSettings);
    entity.getEvents().addListener("gameOver", this::onGameOver);
    //Team History Score board
    entity.getEvents().addListener("displayPropsShop", this::onDisplayPropsShop);
    entity.getEvents().addListener("displayHistoryScores", this::onDisplayHistoryScores);
    entity.getEvents().addListener("achievements", this::onAchievements);
    entity.getEvents().addListener("unlockedAttires", this::onUnlockedAttires);
    entity.getEvents().addListener("monsterMenu", this::onDisplayMonsterMenu);
    entity.getEvents().addListener("buffMenu", this::onDisplayBuffManualMenu);
    entity.getEvents().addListener("GameTutorial", this::onDisplayInstructions);

  }
 }

  /**
   * Swaps to the Main Game screen.
   */
  private void onStart() {
    logger.info("Start game");
    game.setScreen(GdxGame.ScreenType.MAIN_GAME);
  }

  /**
   * Intended for loading a saved game state.
   * Load functionality is not actually implemented.
   */
  private void onLoad() {
    logger.info("Load game");
  }

  /**
   * Exits the game.
   */
  private void onExit() {
    logger.info("Exit game");
    game.exit();
  }

  /**
   * Swaps to the Settings screen.
   */
  private void onSettings() {
    logger.info("Launching settings screen");
    game.setScreen(GdxGame.ScreenType.SETTINGS);
  }

  /**
   * Swaps to the GameOver screen.
   */
  private void onGameOver() {
    logger.info("Launching GameOver screen");
    game.setScreen(GdxGame.ScreenType.GAME_OVER);
  }

  private void onDisplayPropsShop() {
    logger.info("Open the propsShop");
    game.setScreen(GdxGame.ScreenType.PROPS_SHOP);
  }

  private void onDisplayHistoryScores() {
    logger.info("Open the history scores board");
    game.setScreen(GdxGame.ScreenType.HISTORY_SCORES);
  }

  private void onAchievements(){
    logger.info("Launching Achievements screen");
    game.setScreen(GdxGame.ScreenType.ACHIEVEMENTS);
  }

  private void onUnlockedAttires(){
    logger.info("Launching Unlocked Attires screen");
    game.setScreen(GdxGame.ScreenType.UNLOCKED_ATTIRES);
  }

  private void onDisplayMonsterMenu() {
    //logger.info("Open the history scores board");
    game.setScreen(GdxGame.ScreenType.MONSTER_MENU);
  }

  private void onDisplayBuffManualMenu() {
    game.setScreen(GdxGame.ScreenType.BUFF_MENU);
  }

  private void onDisplayInstructions() {
    System.out.println("check 1");
    game.setScreen(GdxGame.ScreenType.INSTRUCTIONS);
  }
  • initializing a button :

making the button, giving it texture, adding it to the table to put it on the main menu list or in a specific position depending on the button

/** build new start button */
    Button.ButtonStyle start = new Button.ButtonStyle();
    start.up= new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/start1.png"))));
    start.over= new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/start2.png"))));
    Button startBtn = new Button(start);

    /** build select unlocked attire button */
    Button.ButtonStyle attires = new Button.ButtonStyle();
    attires.up = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/select1.png"))));
    attires.over = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/select2.png"))));
    Button attiresBtn = new Button(attires);

    /** build new setting button */
    Button.ButtonStyle setting = new Button.ButtonStyle();
    setting.up = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/setting1.png"))));
    setting.over = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/setting2.png"))));
    Button settingBtn = new Button(setting);

    /** build new exit button */
    Button.ButtonStyle exit = new Button.ButtonStyle();
    exit.up = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/exit1.png"))));
    exit.over = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/exit2.png"))));
    Button exitBtn = new Button(exit);

    /** build new prop shop button */
    Button.ButtonStyle propShop = new Button.ButtonStyle();
    propShop.up = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/shop1.png"))));
    propShop.over = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/shop2.png"))));
    Button shopBtn = new Button(propShop);
    shopBtn.setPosition(820,650);

    /** build new score button */
    Button.ButtonStyle score = new Button.ButtonStyle();
    score.up = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/score1.png"))));
    score.over = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/score2.png"))));
    Button scoreBtn = new Button(score);
    scoreBtn.setPosition(960,685);

    /** build new achievement button */
    Button.ButtonStyle achievement = new Button.ButtonStyle();
    achievement.up = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/achievement1.png"))));
    achievement.over = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/achievement2.png"))));
    Button achievementBtn = new Button(achievement);
    achievementBtn.setPosition(1100,682);

    /** build new monster button */
    Button.ButtonStyle monster = new Button.ButtonStyle();
    monster.up = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/monster1.png"))));
    monster.over = new TextureRegionDrawable(new TextureRegion(
            new Texture(Gdx.files.internal("button/monster2.png"))));

    Button monsterBtn = new Button(monster);
    monsterBtn.setPosition(1120,40);


  Button.ButtonStyle buff = new Button.ButtonStyle();
      buff.up = new TextureRegionDrawable(new TextureRegion(
          new Texture(Gdx.files.internal("button/buff1.png"))));
      buff.over = new TextureRegionDrawable(new TextureRegion(
          new Texture(Gdx.files.internal("button/buff2.png"))));

  Button buffBtn = new Button(buff);
      buffBtn.setPosition(1120,170);

      Button.ButtonStyle tutorial = new Button.ButtonStyle();
      tutorial.up = new TextureRegionDrawable(new TextureRegion(
              new Texture(Gdx.files.internal("button/tutorial1.png"))));
      tutorial.over = new TextureRegionDrawable(new TextureRegion(
              new Texture(Gdx.files.internal("button/tutorial2.png"))));


      Button tutorialBtn = new Button(tutorial);
  • assigning screens to each case:

depending on what button has been clicked an what event has occurred there will be an associated screen that we're taken to depending on the case that event and hence that event was associated to

    private void switchScreen(GdxGame game, ScreenType screenType) {
        game.setScreen(screenType);
    }

    public enum ScreenType {
        MAIN_MENU, MAIN_GAME, SETTINGS, GAME_OVER, PROPS_SHOP, HISTORY_SCORES,
        ACHIEVEMENTS,MONSTER_MENU, UNLOCKED_ATTIRES,BUFF_MENU, INSTRUCTIONS
    }

    @Override
    public void create() {
        logger.info("Creating game");
        loadSettings();

        // Sets background to light yellow
        Gdx.gl.glClearColor(248f / 255f, 249 / 255f, 178 / 255f, 1);

        setScreen(ScreenType.MAIN_MENU);
    }

    /**
     * Loads the game's settings.
     */
    private void loadSettings() {
        logger.debug("Loading game settings");
        UserSettings.Settings settings = UserSettings.get();
        UserSettings.applySettings(settings);
    }

    /**
     * Sets the game's screen to a new screen of the provided type.
     *
     * @param screenType screen type
     */
    public void setScreen(ScreenType screenType) {
        logger.info("Setting game screen to {}", screenType);
        Screen currentScreen = getScreen();
        if (currentScreen != null) {
            currentScreen.dispose();
        }
        setScreen(newScreen(screenType));
    }

    @Override
    public void dispose() {
        logger.debug("Disposing of current screen");
        getScreen().dispose();
    }

    /**
     * Create a new screen of the provided type.
     *
     * @param screenType screen type
     * @return new screen
     */
    private Screen newScreen(ScreenType screenType) {
        switch (screenType) {
            case MAIN_MENU:
                return new MainMenuScreen(this);
            case MAIN_GAME:
                return new MainGameScreen(this);
            case SETTINGS:
                return new SettingsScreen(this);
            case GAME_OVER:
                return new GameOverScreen(this);
            case PROPS_SHOP:
                return new PropsShopScreen(this);
            case HISTORY_SCORES:
                return new HistoryScoreScreen(this);
            case ACHIEVEMENTS:
                return new AchievementsScreen(this);
            case UNLOCKED_ATTIRES:
                return new UnlockedAttiresScreen(this);
            case MONSTER_MENU:
                return new MonsterMenuScreen(this);
            case BUFF_MENU:
                return new BuffManualMenuScreen(this);
            case INSTRUCTIONS:
                return new InstructionsScreen(this);
            default:
                return null;
        }
    }

    /**
     * Exit the game.
     */
    public void exit() {
        app.exit();
    }
}

UML diagram

UML.png

Gameplay

Home

Main Character

πŸ‘Ύ Obstacle/Enemy

Food & Water

Pickable Items

Game achievements

Game Design

Emotional Goals

Game Story

Influences

Style

Pixel Grid Resolution

Camera Angle and The Player's Perspective

Features Design

Achievements Screen

Achievements Trophies and Cards

Music Selection GUI

πŸ‘Ύ Obstacle/Enemy

 Monster Manual
 Obstacles/Enemies
  - Alien Plants
  - Variation thorns
  - Falling Meteorites
  - FaceHugger
  - AlienMonkey
 Spaceship & Map Entry
 Particle effect

Buffs

Debuffs

Buffs and Debuffs manual

Game Instruction

[code for debuff animations](code for debuff animations)

Infinite loop game system

Main Menu Screen

New Setting Screen

Hunger and Thirst

Goals and Objectives

HUD User Interface

Inventory System

Item Bar System

Scoring System

Props store

BGM design

Sound Effect design

Main game interface

Invisible ceiling

New terrain sprint 4

New game over screen sprint 4

Code Guidelines

Main Character Movement, Interactions and Animations - Code Guidelines

Item Pickup

ItemBar & Recycle system

Main Menu Button Code

Game Instructions Code

πŸ‘Ύ Obstacle/Enemy

 Obstacle/Enemy
 Monster Manual
 Spaceship Boss
 Particle effects
 Other Related Code
 UML & Sequence diagram of enemies/obstacles

Scoring System Implementation Explanation

Music Implementation

Buff and Debuff Implementation

Score History Display

code improvement explanation

Infinite generating terrains Implementation Explanation

Game Over Screen and functions explaination

Buffer timer before game start

Scrolling background

Multiple Maps

Invisible ceiling

Rocks and woods layout optimization

Magma and nails code implementation

Background Music Selection

Chooser GUI Implementation

Chooser GUI Logic Persistence

Guide: Adding Background music for a particular screen

Achievements Ecosystem - Code Guidelines

Achievements System

Achievements Screen

Adding Achievements (Guide)

Game Records

DateTimeUtils

History Scoreboard - Score Details

Listening for important events in the Achievements ecosystem

Food and Water System

Food System Water System

Hunger and Thirst icon code guidelines

Asset Creation

In Game Background Music

User Testing

Hunger and Thirst User Testing

Main Character Testing

Buffs and Debuffs Testing

Buff and Debuff Manual User Testing

Game Instruction User Testing

The Main Menu User Test

The New Button User Test in Setting Page

The Main Menu Buttons User Testing

Hunger and Thirst User Test

Infinite loop game and Terrain Testing

Item Bar System Testing

Randomised Item Drops

Recycle System Testing

Scoring System Testing

Music User test

https://github.com/UQdeco2800/2021-ext-studio-2.wiki.git

πŸ‘Ύ Obstacle/Enemy

 Obstacle testing
  - Alien Plants & Variation Thorns
  - Falling Meteorites
 Enemy testing
  - Alien Monkeys & Facehugger
  - Spaceship Boss
 Monster Manual
 Particle-effect
 Player attack testing
  - Player Attack

Inventory system UI layout

Props store user testing

Achievements User Testing

Sprint 1

Sprint 2

Sprint 3

Sprint 4

Items testing

Player Status testing

Changeable background & Buffer time testing

Main game interface test

Invisible ceiling test

Game over screen test sprint 4

New terrain textures on bonus map test sprint 4

Buying Props User Testing

Testing

Hunger and Thirst Testing

Main Character Player

Achievements System, Game Records and Unlockable Chapters

DateTimeUtils Testing

Scoring System Testing Plan

Distance Display Testing Plan

Musics Implementation Testing plan

History Board Testing plan

Rocks and woods testing plan

Sprint 4 terrain tests

Items

Item Bar System Testing Plan

Recycle System Testing Plan

Game Engine

Game Engine Help

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally