-
Notifications
You must be signed in to change notification settings - Fork 1
Interactions and Items
- Interactions and Items In an interactive story, players can interact with characters and objects. Items play a crucial role in the story and can be picked up, used, or exchanged between characters.
In this section, we'll cover how to handle interactions and items using Audax Engine.
Step 1: Implement Interactions In the interactedBy method of a character, you can implement how the character interacts with other entities or objects.
java Copy code @Override public void interactedBy(Interactable interactable) { // Implement how the character interacts with other entities or objects. } Step 2: Creating an Item To create an item, create a new class that extends the Item class provided by Audax Engine. For example:
java Copy code package me.adversing.story.objects;
import me.adversing.engine.obj.entities.character.Character; import me.adversing.engine.obj.entities.gameobject.info.ObjectInformation; import me.adversing.engine.obj.entities.gameobject.type.ObjectType; import me.adversing.engine.obj.items.Item; import me.adversing.story.characters.MainCharacter;
public class Sword extends Item { private static final Character mainCharacter = new MainCharacter(); public Sword() { super(new ObjectInformation("object-sword", "Sword", ObjectType.ITEM, 100, 100, "A sword", mainCharacter.getInventory()), true, mainCharacter, 10); } } Step 3: Configuring Items In the constructor of your Sword class, you can configure various properties of the item, such as its information, type, and quantity.
java Copy code public Sword() { super(new ObjectInformation("object-sword", "Sword", ObjectType.ITEM, 100, 100, "A sword", mainCharacter.getInventory()), true, mainCharacter, 10); } Here's a breakdown of the parameters:
"object-sword": This is the unique ID of the item. Replace it with a suitable ID for your item. "Sword": The name of the item, which will be displayed to players. ObjectType.ITEM: The type of the object, which indicates that it is an item. 100: The maximum durability of the item. Replace it with an appropriate value. 100: The current durability of the item. Replace it with an appropriate value. "A sword": A brief description or information about the item. mainCharacter.getInventory(): The inventory to which the item belongs. In this example, the item belongs to the main character's inventory. true: Indicates whether the item is stackable. Set to false if the item should not be stackable. mainCharacter: The character that owns or uses the item. 10: The quantity of the item. Replace it with an appropriate value. With these steps, you have successfully created and configured interactions and items using Audax Engine. Players can now interact with characters and use or collect items in your interactive story.