Main Game Screen - UQcsse3200/2024-studio-2 GitHub Wiki
MainGameScreen
MainGameScreen is the primary game screen for the main game in the project. It extends the PausableScreen class and integrates various components, services, and entities to manage the main game environment.
Class Definition
public class MainGameScreen extends PausableScreen {
// Class content here
}
Key Components
- Logger (logger): Used to log different levels of information, such as debug, info, and trace, for monitoring and debugging purposes.
- Textures (mainGameTextures): Array of file paths for textures used in the main game.
- Camera Position (CAMERA_POSITION): The initial position of the camera in the game world.
- Game Reference (game): A reference to the main game instance (GdxGame).
- Renderer (renderer): Manages the rendering of game elements.
- Physics Engine (physicsEngine): Handles the physics simulation for the game.
- Lighting Engine (lightingEngine): Manages lighting effects in the game.
- Day Night Cycle (dayNightCycle): Controls the day-night cycle in the game.
- Mini Map Display (miniMapDisplay): Handles the display of the mini-map.
- Game Area (gameArea): Represents the current game area or map.
Constructor
public MainGameScreen(GdxGame game) {
// Constructor content here
}
The constructor initializes the main game screen, setting up essential services, loading assets, creating the user interface (UI), and setting up the game area.
Services Initialization
- Game Time: Registered to manage time-based events in the game.
- Physics Service: Handles physics-related computations.
- Input Service: Manages input handling.
- Resource Service: Responsible for loading and unloading game assets.
- Entity Service: Manages game entities.
- Render Service: Handles rendering tasks, including managing the game's stage.
- In-Game Time: Manages the passage of time within the game.
- Lighting Service: Manages lighting effects in the game.
- Particle Service: Handles particle effects in the game.
- Dialogue Box Service: Manages in-game dialogues.
Entity Setup
- Renderer: Initialized using RenderFactory to handle the game's rendering pipeline. The camera is positioned at CAMERA_POSITION.
- Lighting Engine: Set up to handle lighting effects in the game world.
- Day Night Cycle: Manages the day-night cycle in the game.
- Game Area: Created using MapHandler, which sets up the game's terrain and environment.
Methods
render(float delta)
@Override
public void render(float delta) {
// Method content here
}
Updates the physics engine, entities, day-night cycle, and renders the game screen if not paused.
resize(int width, int height)
@Override
public void resize(int width, int height) {
// Method content here
}
Adjusts the renderer to the new screen dimensions and logs the new width and height.
pause()
@Override
public void pause() {
// Method content here
}
Pauses the game, stops music, and pauses in-game time.
resume()
@Override
public void resume() {
// Method content here
}
Resumes the game, restarts music if not in resting state, and resumes in-game time.
dispose()
@Override
public void dispose() {
// Method content here
}
Disposes of the screen and all associated resources, and clears all services registered with ServiceLocator.
loadAssets()
private void loadAssets() {
// Method content here
}
Loads textures and other assets required by the main game.
unloadAssets()
private void unloadAssets() {
// Method content here
}
Unloads textures and assets when they are no longer needed.
createUI()
private void createUI() {
// Method content here
}
Creates and sets up the game's UI, including various display components and input handling.
setMap(MapHandler.MapType mapType)
public void setMap(MapHandler.MapType mapType) {
// Method content here
}
Sets the current game map to the specified map type.
rest()
@Override
public void rest() {
// Method content here
}
Puts the screen into a resting state, pausing music and resting all entities.
wake()
@Override
public void wake() {
// Method content here
}
Wakes the screen from a resting state, resetting player input and resuming music.
Dependencies
The MainGameScreen class depends on various components, services, and libraries:
- LibGDX: For screen management, input handling, and rendering.
- ServiceLocator: For registering and accessing game services.
- Entities: For managing game entities and their components.
- MapHandler: For creating and switching between game areas.
- Various game-specific services: For handling physics, lighting, particles, dialogues, etc.
UML Class Diagram
classDiagram
class PausableScreen
class MainGameScreen
class Renderer
class PhysicsEngine
class LightingEngine
class DayNightCycle
class MiniMapDisplay
class GameArea
PausableScreen <|-- MainGameScreen
MainGameScreen *-- Renderer
MainGameScreen *-- PhysicsEngine
MainGameScreen *-- LightingEngine
MainGameScreen *-- DayNightCycle
MainGameScreen *-- MiniMapDisplay
MainGameScreen *-- GameArea
MainGameScreen : -Logger logger
MainGameScreen : -String[] mainGameTextures
MainGameScreen : -Vector2 CAMERA_POSITION
MainGameScreen : -boolean isPaused
MainGameScreen : +MainGameScreen(GdxGame game)
MainGameScreen : +void render(float delta)
MainGameScreen : +void resize(int width, int height)
MainGameScreen : +void pause()
MainGameScreen : +void resume()
MainGameScreen : +void dispose()
MainGameScreen : -void loadAssets()
MainGameScreen : -void unloadAssets()
MainGameScreen : -void createUI()
MainGameScreen : +void setMap(MapHandler.MapType mapType)
MainGameScreen : +void rest()
MainGameScreen : +void wake()
MainGameScreen : +GameArea getGameArea()
UML Sequence Diagram
sequenceDiagram
participant MainGameScreen
participant ServiceLocator
participant RenderFactory
participant MapHandler
participant ResourceService
MainGameScreen->>ServiceLocator: registerTimeSource(new GameTime())
MainGameScreen->>ServiceLocator: registerPhysicsService(new PhysicsService())
MainGameScreen->>ServiceLocator: registerInputService(new InputService())
MainGameScreen->>ServiceLocator: registerResourceService(new ResourceService())
MainGameScreen->>ServiceLocator: registerEntityService(new EntityService())
MainGameScreen->>ServiceLocator: registerRenderService(new RenderService())
MainGameScreen->>ServiceLocator: registerInGameTime(new InGameTime())
MainGameScreen->>RenderFactory: createRenderer()
MainGameScreen->>MainGameScreen: loadAssets()
MainGameScreen->>ResourceService: loadTextures(mainGameTextures)
MainGameScreen->>MapHandler: createNewMap(MapType.FOREST, renderer, game)
MainGameScreen->>MainGameScreen: createUI()
MainGameScreen->>ServiceLocator: registerDialogueBoxService(new DialogueBoxService(stage))