Story Screen - UQcsse3200/2024-studio-2 GitHub Wiki
StoryScreen Class Documentation
Overview
The StoryScreen
class is part of the com.csse3200.game.screens
package and is responsible for displaying the introduction story for each animal in the game. It transitions between the AnimalSelectionScreen
and the LoadingScreen
. The screen dynamically adjusts the story content based on the animal selected by the player.
Key Features:
- Dynamic Story Backgrounds: The screen displays different story sequences for each selected animal (Dog, Crocodile, and Bird). The correct set of background images is loaded based on the player's choice.
- UI Creation: The screen is equipped with a user interface that renders the story and handles user inputs.
- Services: The class registers several core services needed for rendering, input handling, resource management, and entity management.
Key Components
1. Fields and Constants
-
game: A reference to the
GdxGame
instance, used to navigate between screens. -
renderer: A
Renderer
instance used to draw the textures and handle window resizing. -
backgroundTextures: An array of
Texture
objects representing the background images of the current story.Static Story Paths:
DOG_STORY_PATHS
: Background image paths for the Dog story.CROC_STORY_PATHS
: Background image paths for the Crocodile story.BIRD_STORY_PATHS
: Placeholder paths for the Bird story.
2. Constructor
public StoryScreen(GdxGame game, String selectedAnimal)
The constructor takes the selected animal as input and initializes the required services (input, rendering, resources, and entities). It also loads the appropriate story textures based on the selected animal and creates the UI elements required for displaying the story.
- selectedAnimal: The animal chosen by the player, which determines which story background images to load.
3. Methods
-
render(float delta): Updates the game screen and renders the current frame.
-
resize(int width, int height): Handles screen resizing and adjusts the renderer accordingly.
-
dispose(): Disposes of resources when the screen is no longer needed, including the renderer, textures, and services.
-
createUI(): Creates and sets up the UI elements for displaying the story, including the
StoryDisplay
,StoryActions
, andInputDecorator
components. These components are registered with the entity service. -
loadStoryTextures(String selectedAnimal): This method determines which set of background textures to load based on the player's animal selection (Dog, Crocodile, Bird). It returns an array of textures corresponding to the chosen story.
Story Integration
- Dog Story: Displays a sequence of 6 images (
DogStory1.png
toDogStory6.png
). - Crocodile Story: Displays a sequence of 7 images (
CrocStory1.png
toCrocStory7.png
). - Bird Story: Currently uses a placeholder image (
bird.png
).
If an invalid animal is selected, the story defaults to the Dog story.
Service Management
The class registers several core services using ServiceLocator
:
- InputService: Captures and handles player inputs.
- ResourceService: Manages game assets, including textures.
- EntityService: Manages game entities.
- RenderService: Manages rendering and handles drawing on the game screen.
The services are properly disposed of when the screen is no longer in use to free up memory.
Example Usage
// Example of initializing the StoryScreen with a selected animal
StoryScreen storyScreen = new StoryScreen(game, "croc");
game.setScreen(storyScreen);
This will load and display the Crocodile's story, transitioning from the AnimalSelectionScreen
.
Future Enhancements
- Bird Story: The bird story currently uses placeholder images and will need updates to reflect the actual story. - which will be integrated by Team 6
- Additional Animals: Future updates may involve adding more animals and corresponding stories by expanding the
loadStoryTextures
method.
Conclusion
The StoryScreen
class plays a crucial role in delivering a narrative experience based on the player's animal selection. It ensures dynamic loading of story elements while maintaining a consistent user experience by leveraging core services like rendering, input handling, and resource management.