Skip to content

Sprint 2 Inventory System and Consumables Functionality

Bohankkk edited this page Oct 18, 2022 · 13 revisions

Sprint 2: Refined and Extended Inventory Functionality

Goal

The goal of this sprint was to complete the base features of the inventory, such as populating the inventory display with the correct items in the correct item slots, and extend functionality, such as offering item descriptions on hover. This sprint also saw the creation of the clue item, which will allow the player to use it to add guilt to an npc, or the time item, which will increase the countdown timer giving the player more time to complete their tasks.

UML Diagram

UML Diagram

Design

Mermaid Scales -- 5 pieces

The design below is the key items throughout the whole storyline. These are the shattered scales from Nereus - the princess of Atlantis. There are some hidden message inside the scale, player has to collect these items and give them to Metis for identification.

scales1 scales2 scales3 scales4 scales5

Time Item - gif & png

The item below is a hourglass that will appear on map for players to collect and increase the time limit to avoid game over due to overtime.

time_item time_item

Dive Suit

These items below is the set of gear for players to collect before going underwater during their journey . Players are not allowed to go underwater unless they have got complete suited.

dive glass dive suit folded dive suit oxygen cylinder

Inventory System Layout

These are some layout design of the inventory system for players to view when they access the inventory page.

final Inventory system

inventory system copy inventory_system

Functionality

The current inventory display functionality has been updated since the last sprint. This included additions to allow for items to be populated in the inventory display proper, and changes made to how the player interacts with the inventory to use items. The inventory works by creating 2 rows of imagebuttons on a table, with each button set as an empty inventory slot. This is then updated according to the inventory hashmap to assign these imagebuttons to the item entities. Within the switch statement (of which 1 case is provided below for reference) this assignment is made to drawSlot1 (Inventory item slot 1) and attaches our listener to it. These listeners look for if the mouse is hovering over the item to display its item description, or if the item has been clicked, which removes the item from the inventory and applies its effects to the game.

Inventory Display

 private Table createInventory() {

        //empty slot
        Texture texture = new Texture(Gdx.files.internal("images/inventory/emptyInventorySlot.png"));
        Drawable emptySlot = new TextureRegionDrawable(new TextureRegion(texture));

        //Confirm down <a href="https://www.flaticon.com/free-icons/pixelated" title="pixelated icons">Pixelated icons created by Freepik - Flaticon</a>
        Texture confirmTexture = new Texture(Gdx.files.internal("images/inventory/confirm.png"));
        Drawable confirmDown = new TextureRegionDrawable(new TextureRegion(confirmTexture));

        // instantiating buttons
        ImageButton drawSlot1 = new ImageButton(emptySlot);
        ImageButton drawSlot2 = new ImageButton(emptySlot);
        ImageButton drawSlot3 = new ImageButton(emptySlot);
        ImageButton drawSlot4 = new ImageButton(emptySlot);
        ImageButton drawSlot5 = new ImageButton(emptySlot);
        ImageButton drawSlot6 = new ImageButton(emptySlot);
        ImageButton drawSlot7 = new ImageButton(emptySlot);
        ImageButton drawSlot8 = new ImageButton(emptySlot);
        ImageButton drawSlot9 = new ImageButton(emptySlot);
        ImageButton drawSlot10 = new ImageButton(emptySlot);

        // Get the entities existing in the game
        Array<Entity> entities = ServiceLocator.getEntityService().getEntities();

        // used to check each slot for its available item
        int slotIncrement = 1;

        // Implicitly going up. Should be done 1-10 for each inventory item
        for (Map.Entry<Integer, Integer> entry  : inventoryHashMap.entrySet()) {
            Integer key = entry.getKey();
            Integer value = entry.getValue();

            for (Entity i: entities)
            {
                switch (slotIncrement) {
                    case 1:
                        // Check if the hashmap value is equal to the entity registered in the entity service to get the appropriate functionality
                        if (i.getId() == value)
                        {
                            Drawable buttonGraphic = new TextureRegionDrawable((i.getComponent(TextureRenderComponent.class)).getTexture());
                            drawSlot1 = new ImageButton(buttonGraphic, confirmDown);

                            //Hover popup for item description and Item slot click event
                            drawSlot1.addListener(new InputListener() {
                                //Shows item description when mouse hovers item slot
                                @Override
                                public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
                                    showItemDescription(i);
                                }
                                //Removes item description when not hovering
                                @Override
                                public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
                                    destroyItemDescription();
                                }
                                //Uses the item once an item slot is clicked
                                @Override
                                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                                    useItem(i, key);
                                    destroyItemDescription();
                                    return true;
                                }

                            });

                        }

Once an item is clicked in the inventory display, the 'useItem' function is ran to determine what item has just been used and what effect function should be applied. Once a 'time item' is used, the useItem function then applies the 'consumeTimeItem' function as shown below. This function locates the time display entity and increases its countdown clock.

Consume Time Item

public void consumeTimeItem(Entity i, int key){
        /// Funky locator magic to identify the entity that contains the time display
        Array<Entity> entityLocator = ServiceLocator.getEntityService().getEntities();
        for (Entity timeDisplay: entityLocator)
        {
            if (timeDisplay.getComponent(countdownDisplay.class) != null)
            {
                float increaseValue = i.getComponent(ConsumeableItemComponent.class).increaseTime();
                (timeDisplay.getComponent(countdownDisplay.class)).increaseRemainingTime(increaseValue);

                inventoryHashMap.remove(key);
                destroyInventory();

            }

        }
    }

This is one of the factories used to create items within the inventory.

Consumable Item Factory

public class ConsumableItemFactory extends ItemFactory {
    private static int consumeableTimeIncrease = 30;
    ConsumableItemFactory() {
        super();
    }
    public static Entity createItem(Entity target, String texturePath) {
        Entity item = createBaseItem(target);

        item
                .addComponent(new TextureRenderComponent(texturePath))
                .addComponent(new ColliderComponent());
        return item;
    }

    /**
     * Creates a generic item to be used as a base entity by more specific item creation methods.
     *
     * @return entity
     */
    private static Entity createBaseItem(Entity target) {
        AITaskComponent aiComponent =
                new AITaskComponent()
                        .addTask(new WanderTask(new Vector2(2f, 2f), 2f));
        Entity item =
                new Entity()
                        .addComponent(new PhysicsComponent())
                        .addComponent(new PhysicsMovementComponent())
                        .addComponent(new ColliderComponent())
                        .addComponent(new HitboxComponent().setLayer(PhysicsLayer.Item))
                        .addComponent(aiComponent)
                        .addComponent(new AddToInventoryComponent(PhysicsLayer.Item))
                        .addComponent(new ConsumeableItemComponent(getConsumeableTimeIncrease()));

        PhysicsUtils.setScaledCollider(item, 0.9f, 0.4f);
        return item;
    }

    public static int getConsumeableTimeIncrease() {
        return consumeableTimeIncrease;
    }
}

Table of Contents

Home

Game Design

User survey

Sprint 4

Eviction Menu and Win/lose Logic: Polishing tasks (Team 7)

Button Sounds and Ending Menu improve (Team 3)

Sound effect and Fixing the clue bug (Team 6)

Improvement of Enemy and Attack (Team 1)

Add Features When The Player Get Attacked and Overall UI Improvement (Team 8)

Sprint 1

Achievement System (Team 2)

Player Eviction Menu (Team 7)

Countdown Clock (Team 4)

Music (Team3)

Map (Team6)

Sprint 2

Player Eviction Menu (Team 7)

Character Design & Animation (Team 1)

Music (Team 3)

Inventory System and Consumables Items (Team 8)

Scenario design

Achievement System(team 2)

Storyline (Team 5)

Countdown Clock (Team 4)

Sprint 3

Ending Menu (Team 3)

NPC interaction (Team 2)

Win/lose Condition (Based on Eviction Menu) (Team 7)

Player Profile (Team 4)

Game Logo (Team 8)

Clue storage (Team 6)

Enemy Design and Attack (Team 1)

Scenario design for village(Team5)

Game design
Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally