-
Notifications
You must be signed in to change notification settings - Fork 1
Scoring System
The CoinsComponent
is designed to manage the coin collection and spending mechanics in the game. It tracks of player's attacks and when player has successfully killed an NPC, it adds their strength as coins which can be be used later in the game. Moreover, this system also updates the coins on UI accordingly.
The implementation of the CoinsComponent
follows a component-based architecture, allowing for modular and reusable components across different entities. This design enables easier maintenance and scalability of the game code. By decoupling the coin management from the player entity, it is convenient to extend or modify the coin system without affecting other parts of the codebase.
- Coin Component: Tracks the number of coins owned by the player, allowing for adding and spending of coins.
- Event Handling: Listens for coin collection events triggered by other components, particularly NPCs, to update the player's coin count in real time.
- Integration with Inventory: Links with the player's inventory to ensure seamless updates and interactions.
-
CoinsComponent.java: Responsible for handling the coins, this includes adding coins, setting coins to a value and spending coins
-
PlayerCoinDisplay: This UI component displays the current coin count on the screen. It listens out for any change in coin amount and updates the label whenever it changes, ensuring players can see their current currency at a glance. Moreover, it adds sound effects when an animal is defeated and displays the amount of coins earned from each animal
-
NPCDeathHandler: This component triggers coin collection events when an NPC dies based on the NPC's strength, which directly affects how many coins are awarded to the player.
-
NPCConfigs: This file was modified to store the strength of different NPCs. This is important as NPCs with different strength will award different scores.
-
InventoryComponent: The
CoinsComponent
relies on theInventoryComponent
to access the player's events and trigger updates related to coin management.
To use the CoinsComponent
in your game, you must add it to the player entity during its creation. Here's an example:
import com.csse3200.game.components.player.inventory.CoinsComponent;
import com.csse3200.game.components.player.InventoryComponent;
// Inside your player creation method
public Entity createPlayer(PlayerConfig config) {
Entity player = new Entity();
InventoryComponent inventoryComponent = new InventoryComponent();
player.addComponent(inventoryComponent);
CoinsComponent coinsComponent = new CoinsComponent(inventoryComponent.getInventory());
player.addComponent(coinsComponent); // adding scoring system
player.addComponent(new PlayerCoinDisplay(coinsComponent)); // displaying the coins on UI
// Other player setup...
return player;
}
To access or modify the player's coin count, you can use the following methods provided by the CoinsComponent
:
-
Get Coins: Retrieve the current coin count.
int currentCoins = coinsComponent.getCoins();
-
Add Coins: Add a specified amount of coins.
coinsComponent.addCoins(5); // Adds 5 coins
-
Spend Coins: Spend a specified amount of coins, ensuring the player has enough.
coinsComponent.spend(3); // Attempts to spend 3 coins
-
Set Coins: Directly set the coin count, ensuring it does not go below zero.
coinsComponent.setCoins(10); // Sets coins to 10
the coins appear on the top of the screen like:
Please refer to the following link to view the test plans for Scoring System: Test Plans for Scoring System
The CoinsComponent
is a crucial part of the game's economy system, enabling players to collect, spend, and manage their currency effectively. By leveraging event-driven programming and a component-based architecture, it provides a flexible and maintainable approach to coin management in your game.
Design Choices
Utilities
Animals
Menus/screens
Character
- Character Animations
- Character's Inventory On Display
- Character's Inventory System
- Character's HealthBar
- Character's Interaction with Items
- Character achievements
- Saving Character
- Player-(and-other-NPC)-invincibility-frames
- Player Factory
- Scoring System
- Test Plan for Inventory System
- Test Plan for Player's Interaction with Items
- Test Plan for Player's Inventory Display
- Test Plan for Saving Character State
- Test Plan for Scoring System
Map
Weapon
- Weapon Overview
- Weapon Types
- Weapon Structure
- Weapon Stats Display
- Testing Plan for Weapon Factory
- Testing Plan for Firing Controller Component
- Testing Plan for Position Tracker Component
- Testing Plan for Weapon Animation Controller component
- Testing Plan for Concrete Melee Weapon class
- Testing Plan for Concrete Ranged Weapon class