-
Notifications
You must be signed in to change notification settings - Fork 7
Creating Plants using PlantFactory.java
New plants are created using the PlantFactory
. A file called plant.json
contains the necessary properties of each plant. These properties are used to set up the attributes of the plants generated by the factory.
private static PlantConfigs stats
: holds the plant properties defined in plant.json
.
public static Entity createBasePlant()
: creates a generic plant entity to be used in the createPlantName
methods.
public static Entity createPlantName(CropTileComponent cropTile)
: Creates a plant entity of the specified plant type. cropTile is a CropTileComponent which indicates the in-game location where the user has placed the plant. The method retrieves the attributes of the specified plant type from stats
and assigns it to the newly created plant.
Methods following this structure include: createCosmicCob
, createAloeVera
, createHammerPlant
, createSpaceSnapper
, createAtomicAlgae
and createDeadlyNightshade
.
Each factory method accepts a reference to the CropTileComponent that the plant is being planted on and returns a new plant entity. The CropTileComponent
is required to be attached to an entity, since the factory method handles positioning the plant at the position of the crop tile entity. The plant entity returned by the factory needs to be registered to the entity service by the caller.
Plant entities (which have an attached PlantComponent
) listen out for events triggered on the entity. Plant entities have a sensor collider component so that any object (such as a player or animal) wanting to interact with the plant can acquire a reference to the plant entity.
Plants will listen out for various events:
-
"harvest"
- Triggers harvesting of the plant (not yet implemented). -
"destroyPlant"
- Tells the plant to destroy itself. The plant will handle informing theCropTileComponent
it is planted on that it has been destroyed. -
"attack"
- Applies damage to the plant. When triggered, expects an integer value containing how much damage to apply. -
"minuteUpdate"
- Allows the plant to check for any actions that need to take place every minute of in game time. -
"hourUpdate"
- Allows the plant to check for any actions that need to take place every hour of in game time. -
"dayUpdate"
- Allows the plant to check for any actions that need to take place every day of in game time. -
"forceSeedling"
- Used for debugging. Allows the plant to instantly become a seedling. -
"forceSprout"
- Used for debugging. Allows the plant to instantly become a sprout. -
"forceAdult"
- Used for debugging. Allows the plant to instantly become an adult. -
"forceDecay"
- Used for debugging. Allows the plant to instantly start decaying. -
"forceDead"
- Used for debugging. Allows the plant to instantly die.
Due to the flexibility of this interaction system, more events can be easily added to add more interactions with the plant if other components of the game wish to do so.
See these crop tile sequence diagrams for more detail on the plant's interaction with the crop tile.
To create a plant using PlantFactory.java:
1. Import the necessary classes
import com.csse3200.game.entities.factories.PlantFactory;
import com.csse3200.game.areas.terrain.CropTileComponent;
import com.csse3200.game.entities.Entity;
2. Call 'create' methods
Entity aloeVera = PlantFactory.createAloeVera(cropTile);
where cropTile
is the tile at which you would like the plant to be placed.
- Test the instantiation of the plants created in
PlantFactory
fromplant.json
- Test the attributes of created plants from
PlantComponents
- Verify components attached to the plants
- Verify the texture path of the plants match the expected path
- Checks if properties of created plants match expected values
- Test plant position
- Test scaling functionalities of plants