-
Notifications
You must be signed in to change notification settings - Fork 9
TutorialScreen Class Documentation
The TutorialScreen
class is a part of the game developed using LibGDX. It serves as the screen for the tutorial map, offering a guided experience for players to learn the game's mechanics and features.
The TutorialScreen
class is responsible for managing the tutorial gameplay. It includes the following features:
- Initialization of game areas, entities, and UI elements.
- Displaying tutorial images and buttons.
- Handling player input.
- Advancing through tutorial steps.
- Managing the camera to follow the player's movements.
- Integration with the
TutorialGameArea
class to provide the tutorial map. - Display of tutorial images and buttons to guide the player.
- Handling user interactions with buttons and other UI elements.
- Progression through tutorial steps (commented out in the provided code).
The TutorialScreen
class may have dependencies on external libraries, assets, or other components. Some of the notable dependencies include:
- LibGDX: The game development framework.
- Various textures and images for UI elements.
-
TutorialGameArea
: The tutorial-specific game area class. - Other utility and game-specific libraries.
To use the TutorialScreen
class in your LibGDX game, follow these steps:
- Create an instance of the
TutorialScreen
class, passing theGdxGame
instance and a screen name.
GdxGame game = ...; // Initialize your game instance
String screenName = "Tutorial Screen"; // Set a screen name
TutorialScreen tutorialScreen = new TutorialScreen(game, screenName);
- Use the
game.setScreen
method to set theTutorialScreen
as the active screen when needed.
game.setScreen(tutorialScreen);
- The
TutorialScreen
class initializes game areas, entities, and UI elements. Ensure that you have loaded the necessary assets before displaying the screen.
create()
- Initializes the tutorial gameplay, including game areas, entities, UI, and tutorial steps.
render(float delta)
- Handles the rendering of the tutorial screen, updating physics and UI elements.
resize(int width, int height)
- Resizes the screen's viewport to fit the new dimensions.
dispose()
- Disposes of the tutorial screen, releasing any allocated resources and memory.
onExit()
- Transition to the main menu when the exit button is clicked.
clear()
- Performs cleanup and disposal of resources when exiting the tutorial screen.
loadAssets()
- Loads necessary assets for the tutorial screen, such as textures and images.
unloadAssets()
- Unloads assets that are no longer needed to free up memory.
createUI()
- Creates UI elements, including a stage for displaying tutorial images and buttons.
followPlayer()
- Adjusts the camera to follow the player's movements within the map boundaries.
GdxGame game = ...; // Initialize your game instance
String screenName = "Tutorial Screen"; // Set a screen name
TutorialScreen tutorialScreen = new TutorialScreen(game, screenName);
// Set the tutorial screen as the active screen
game.setScreen(tutorialScreen);
In the above example, replace the ellipses (...
) with the game instance and resources.
- TutorialGameArea
// TutorialGameArea.java
package com.csse3200.game.areas;
import com.badlogic.gdx.math.GridPoint2;
import com.csse3200.game.GdxGame;
import com.csse3200.game.areas.terrain.TerrainFactory;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.configs.PlayerConfig;
import com.csse3200.game.entities.factories.PlayerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TutorialGameArea extends MapGameArea {
private static final Logger logger = LoggerFactory.getLogger(TutorialGameArea.class);
private int stepIndex = 0;
public TutorialGameArea(TerrainFactory terrainFactory, GdxGame game) {
super("tutorial", "main_area", terrainFactory, game);
}
/**
* Create the game area
*/
@Override
public void create() {
super.create();
}
public Entity spawnPlayer() {
Entity newPlayer;
PlayerConfig playerConfig = null;
if (mapConfig.areaEntityConfig != null) {
playerConfig = mapConfig.areaEntityConfig.getEntity(PlayerConfig.class);
}
if (playerConfig != null) {
newPlayer = PlayerFactory.createPlayer(playerConfig);
} else {
logger.info("Player not found in config file - creating generic player");
newPlayer = PlayerFactory.createPlayer();
}
if (playerConfig != null && playerConfig.position != null) {
spawnEntityAt(newPlayer, playerConfig.position, true, true);
} else {
logger.info("Failed to load player position - created player at middle of map");
//If no position specified spawn in middle of map.
GridPoint2 pos = new GridPoint2(terrain.getMapBounds(0).x/2,terrain.getMapBounds(0).y/2);
spawnEntityAt(newPlayer, pos, true, true);
}
return newPlayer;
}
}
All code implementation can be found in TutorialScreen
and TutorialGameArea
.
- Yash Mittal (@YashMitttal} (s4823869)
- Rachit Chaurasia (@rachitchaurasia) (s4823870)
- Dev Gupta (@DRG31) (xdrgx)
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files