Skip to content
Jackson Trenerry edited this page Aug 30, 2023 · 15 revisions

Items

Overview

The ItemFactory is a crucial part of the Entity-Component-System (ECS) architecture within our game. It represents the properties and behaviour of an in-game item. Items can be anything from weapons, tools, plants, to any other interactable objects that players can use or manipulate.

To make items using the ECS approach, components are added to the entity. This modular approach allows shorter and less complicated code.

How to create your own custom items

Example - Hoe

In the itemFactory.java a base item is shown below. With the default components added shown in green. image

To extend this base item into a hoe, we need to add the relevant components to this Entity to make it a hoe. For example a hoe would have the following added components.

image

Ensure when writing your own constructor for items, that you use the provided base item constructor and then add your required components to this entity.

Component breakdown

Item Component

Arguably the most important component for an item, item component allows the item to tell other entities and bits of code what it is and how it should be treated. It has variables like selling price, it's name, a Texture of it's inventory sprite and a description. Most getters and setters are within this component.

Item Actions

Item actions allows items to interact with the ground and/or entities around the player. The most important part of setting up a Item to do something is to simply make a new value in the enum and add it to switch case in ItemActions.use() and then call a function when it is true to add in the item being used.

Animating items

Very similar to ItemActions, head over to the player's animation controller and look at the function use, then customize it to correctly call the right animation when triggered. For more general animations like planting a seed it isn't necessary to have the string manipulation occuring currently so feel free to switch it to if else prior to make sure the correct animation plays.

Item type

Not a component but vital to making your own item. ItemType enum is used to mark what it should do in various switch statements like in ItemActions or how to animate the usage of the item. Just add your own values to the enum, one for each different action or animation (for example each tool has their own since they all do different actions and animations).

Summary

In summary, the ItemFactory is a crucial part of our game's design, defining how in-game items work. These items can be things like weapons, tools, or plants that players can use. The factory uses a smart way of organizing things, making the game's code easier to manage.

To create new items, like a hoe, we start with a basic item and then add specific features to it. This way of building items lets us create a lot of different things in the game without making the code overly complicated. This makes the game development process smoother and gives designers the flexibility to create a variety of items for players to interact with.

Clone this wiki locally