Player selection - UQcsse3200/2024-studio-1 GitHub Wiki
The game has a Player Select screen that lets you choose from a range of players, each with different health, speed and animations.
Updated player select screen
Selecting a player gives you a choice between different stats and abilities, e.g. the pets of the necromancer or the lower health of the drunk guy. Note that loading a game will reuse the player you chose before and skip the selection screen.
Contents
Player animation
Each player has an animation chosen from their atlas file.
Stat bars
Bars will show the player's starting health and speed. Note that these are relative to other players and not an absolute value (i.e. a player's health (HLTH) bar will show that player's initial health as a proportion of the maximum health of all players).
Select button
A simple text button to select the player, with text containing the player's name.
How to add players
- Add the player's JSON config file in
assets/configs
and add the path to the list of players inPlayerFactoryFactory
. - If necessary, add the animation name, duration and play mode to
PlayerSelectAnimation.PlayerAnimationType
. - Add the atlas file path to
PlayerAnimationType.createFromAtlas
to instruct the class which animation type this player should use.
Now, the player will be visible on the select screen when you run the game.
Code considerations
- Animations are determined by the player atlas, allowing for simple reusability of atlas files between players without having to code in the same animation twice.
- The
PlayerSelectAnimation
extendsActor
, meaning it can be added to aTable
. This way, we can use LibGDX's built-in table-positioning functionality without needing to re-invent it.
Design considerations
- The animations on the players and the stat bars add some flair and engagement value to the screen, an important consideration given that this screen must be passed through to start the game.
Sequence diagram
As the player is chosen in one screen (PlayerSelectScreen
) and created in another (MainGameScreen
), an important consideration is how to store information about the selected player so the MainGameScreen
knows which player to create when the game starts. This has been achieved by creating a new PlayerFactory
based on the user's selection which is stored in the GameOptions
(a member of the GdxGame
). The following sequence diagram shows how this information is stored and retrieved across different screens.