-
Notifications
You must be signed in to change notification settings - Fork 9
Healing Tool
The Healing Tool is a component of the game that allows players to interact with entities and heal them. This document provides an in-depth explanation of the Healing Tool code.
The Healing Tool is a Java class designed for a game development project. It is a subclass of the Tool
class and is responsible for healing entities in the game. Below, we'll dive into the details of the code.
The Healing
class is the main component responsible for healing entities. It is a subclass of the Tool
class.
The Healing
class has a constructor that accepts a map of costs. The cost map is used to specify the resource cost of using this healing tool.
public Healing(ObjectMap<String, Integer> cost) {
super(cost);
}
The interact
method allows the player to interact with entities in the game world. It checks if the player has clicked on an entity, and if so, it attempts to heal the entity by setting its health to its maximum health value.
@Override
public boolean interact(Entity player, GridPoint2 position) {
Entity clickedEntity = determineSelectedEntity(position);
if (clickedEntity == null) {
return false;
}
CombatStatsComponent combatStats = clickedEntity.getComponent(CombatStatsComponent.class);
if (combatStats == null) {
return false;
}
combatStats.setHealth(combatStats.getMaxHealth());
return true;
}
The determineSelectedEntity
method is a private helper function that determines which entity the player has clicked on. It uses the ServiceLocator
to access the StructurePlacementService
and retrieve the entity at the specified position.
private Entity determineSelectedEntity(GridPoint2 position) {
return ServiceLocator.getStructurePlacementService().getStructureAt(position);
}
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files