Inventory system for player characters (for keys, gravity boots, etc.) #16

Closed
opened 2019-07-15 21:28:33 +00:00 by kirsle · 0 comments

Currently, the colored keys and doors system uses a really basic key/value data store on the actor who picked up the key.

These are ideas to extend the inventory system for future growth.

Inventory Struct

Level actors should store their inventory in a key/value map where the keys are the actor filename (i.e. red-key.doodad) and the value is the quantity in the inventory. A value of zero indicates a permanent item that doesn't get consumed when used and doesn't show its quantity in the inventory HUD.

Example:

Player.Inventory = map[string]int{
    "red-key.doodad":   0,  // permanent item
    "small-key.doodad": 2,  // consumable item
}

Usage

In these examples, the red key is a permanent item that unlocks all red doors and the small key is a consumable that only opens one locked door (a door specifically for small keys; small keys don't unlock colored doors).

  • When a red key is touched it calls .AddInventory(Self.Filename, 0) to "add" the item with 0 quantity to the player's inventory.
  • When a small key is touched it calls .AddInventory(Self.Filename, 1) to add 1 small key to the inventory.
  • When a red door is touched, and the player has a red key, the door unlocks.
  • When a locked door is touched, and the player has at least 1 small key, the door unlocks and calls .RemoveInventory("small-key.doodad", 1) to remove 1 small key from the inventory.

The .RemoveInventory function's logic would be like:

  • If you have >= 1 quantity in your inventory, subtract from it. If the resulting count drops to zero, remove the item from your inventory hashmap. So if you have 1 small key, the key is removed from inventory completely.
  • If you have 0 quantity in your inventory (i.e. red key, a permanent item) then it will always be removed if .RemoveInventory is called. So a doodad could remove your permanent key. Even .RemoveInventory("red-key.doodad", 0) would remove it.

The .AddInventory would create the hashmap key and increment it by the "add amount" parameter.

HUD

In Play Mode, show a HUD on-screen in the upper right corner when the player character has at least one item in their inventory. The HUD will display doodad icons (no scripts attached) for each item in their inventory.

  • If the item has a quantity > 0, display the quantity in a small number in the corner.
  • Items with a 0-quantity (permanent) do not show the quantity number.

Use cases and examples

  • Colored keys are permanent items with quantity=0.
  • Small keys (new item) are consumables and unlock one locked door (new item) at a time.
  • Gravity boots are permanent items with quantity=0 and would be added/taken away by various parts of the level.
  • Projectile items (bullets, arrows, etc.) would have quantities and be consumed when fired.
Currently, the colored keys and doors system uses a really basic key/value data store on the actor who picked up the key. These are ideas to extend the inventory system for future growth. ### Inventory Struct Level actors should store their inventory in a key/value map where the keys are the actor filename (i.e. red-key.doodad) and the value is the quantity in the inventory. A value of zero indicates a permanent item that doesn't get consumed when used and doesn't show its quantity in the inventory HUD. Example: ```go Player.Inventory = map[string]int{ "red-key.doodad": 0, // permanent item "small-key.doodad": 2, // consumable item } ``` ### Usage In these examples, the red key is a permanent item that unlocks all red doors and the small key is a consumable that only opens one locked door (a door specifically for small keys; small keys don't unlock colored doors). * When a red key is touched it calls `.AddInventory(Self.Filename, 0)` to "add" the item with 0 quantity to the player's inventory. * When a small key is touched it calls `.AddInventory(Self.Filename, 1)` to add 1 small key to the inventory. * When a red door is touched, and the player has a red key, the door unlocks. * When a locked door is touched, and the player has at least 1 small key, the door unlocks and calls `.RemoveInventory("small-key.doodad", 1)` to remove 1 small key from the inventory. The .RemoveInventory function's logic would be like: * If you have >= 1 quantity in your inventory, subtract from it. If the resulting count drops to zero, **remove** the item from your inventory hashmap. So if you have 1 small key, the key is removed from inventory completely. * If you have 0 quantity in your inventory (i.e. red key, a permanent item) then it will **always** be removed if .RemoveInventory is called. So a doodad could remove your permanent key. Even `.RemoveInventory("red-key.doodad", 0)` would remove it. The .AddInventory would create the hashmap key and increment it by the "add amount" parameter. ### HUD In Play Mode, show a HUD on-screen in the upper right corner when the player character has at least one item in their inventory. The HUD will display doodad icons (no scripts attached) for each item in their inventory. * If the item has a quantity > 0, display the quantity in a small number in the corner. * Items with a 0-quantity (permanent) do not show the quantity number. ### Use cases and examples * Colored keys are permanent items with quantity=0. * Small keys (new item) are consumables and unlock one locked door (new item) at a time. * Gravity boots are permanent items with quantity=0 and would be added/taken away by various parts of the level. * Projectile items (bullets, arrows, etc.) would have quantities and be consumed when fired.
kirsle added the
enhancement
doodad
labels 2019-07-15 21:28:43 +00:00
kirsle added this to the First Beta Release MVP milestone 2019-12-31 02:41:53 +00:00
Sign in to join this conversation.
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: SketchyMaze/doodle#16
There is no content yet.