aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2026-01-10 10:25:32 +0000
committernathan <nathansmith@disroot.org>2026-01-10 10:25:32 +0000
commit013ac4a2f4ae24d71f425f31edd77a8e29ed1da8 (patch)
treedffc4b36c7c94a734940d0e3fac3536be99c2ad6
parent6e0fabd2798d7e602e243a35a922703cde7ef750 (diff)
downloadFindThings-main.tar.gz
FindThings-main.tar.bz2
FindThings-main.zip
Working on inventoryHEADmain
-rw-r--r--src/entity.h7
-rw-r--r--src/game.c4
-rw-r--r--src/game.h1
-rw-r--r--src/ui.c72
-rw-r--r--src/ui.h11
5 files changed, 84 insertions, 11 deletions
diff --git a/src/entity.h b/src/entity.h
index d0e9f9f..b7c458e 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -1,4 +1,5 @@
#include "utils.h"
+#include "assets.h"
// Pretty much any object in the game.
@@ -71,6 +72,12 @@ struct Entity {
void* data;
};
+typedef struct {
+ EntityId id;
+ AssetId texture;
+ int count;
+} EntityItem;
+
// Cubemap based building.
typedef struct {
Model model;
diff --git a/src/game.c b/src/game.c
index fb7e01d..06ce527 100644
--- a/src/game.c
+++ b/src/game.c
@@ -95,6 +95,9 @@ void initGame(Game* game)
initInteractionChat(&game->interactionChat, &game->settings);
initInteractionMenu(&game->interactionMenu, &game->settings);
+ // Inventory.
+ initInventory(&game->inventory);
+
disableGameCursor(game);
}
@@ -324,6 +327,7 @@ void updateGameScene(Game* game)
updateGameStatus(game);
updateInteractionChat(&game->interactionChat, game);
updateInteractionMenu(&game->interactionMenu, game);
+ updateInventory(&game->inventory);
}
void handleGameResize(Game* game)
diff --git a/src/game.h b/src/game.h
index 971dde3..c59d5e9 100644
--- a/src/game.h
+++ b/src/game.h
@@ -28,6 +28,7 @@ struct Game {
InteractionChat interactionChat;
InteractionMenu interactionMenu;
+ Inventory inventory;
SceneId sceneId;
bool isCursorEnabled;
diff --git a/src/ui.c b/src/ui.c
index 66560bb..ac176b8 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -228,10 +228,19 @@ void updateInteractionMenu(InteractionMenu* menu, Game* game)
}
}
+void resizeInventory(Inventory* inventory)
+{
+ inventory->rect.width = 300.0;
+ inventory->rect.height = 300.0;
+ inventory->rect.x = GetRenderWidth() / 2.0 - inventory->rect.width / 2.0;
+ inventory->rect.y = GetRenderHeight() / 2.0 - inventory->rect.height / 2.0;
+}
+
void initInventory(Inventory* inventory)
{
- inventory->visable = false;
- inventory->itemCount = 0;
+ resizeInventory(inventory);
+ inventory->visable = true;
+ inventory->itemCount = 40;
}
void showInventory(Inventory* inventory)
@@ -244,10 +253,67 @@ void hideInventory(Inventory* inventory)
inventory->visable = false;
}
-void addItemToInventory(Inventory* inventory, InventoryItem item)
+void addItemToInventory(Inventory* inventory, EntityItem item)
{
+ // If item is already in the inventory.
+ for (int index = 0; index < inventory->itemCount; ++index)
+ {
+ if (inventory->items[index].id == item.id)
+ {
+ inventory->items[index].count += item.count;
+ return;
+ }
+ }
+
+ // Add item to inventory.
+ if (inventory->itemCount >= INVENTORY_MAX)
+ {
+ TraceLog(LOG_ERROR, "inventory->itemCount >= INVENTORY_MAX");
+ }
+ else
+ {
+ inventory->items[inventory->itemCount] = item;
+ ++inventory->itemCount;
+ }
}
void updateInventory(Inventory* inventory)
{
+ if (IsWindowResized())
+ {
+ resizeInventory(inventory);
+ }
+
+ if (!inventory->visable)
+ {
+ return;
+ }
+
+ // Draw background.
+ int outlineThickness = 3;
+ DrawRectangleRec(inventory->rect, PINK);
+ DrawRectangleLinesEx(inventory->rect, outlineThickness, BLACK);
+
+ // Draw items.
+ int startX = inventory->rect.x + outlineThickness;
+ int startY = inventory->rect.y + outlineThickness;
+ int maxX = inventory->rect.width + inventory->rect.x - INVENTORY_SPRITE_SIZE;
+ int maxY = inventory->rect.height + inventory->rect.y -
+ INVENTORY_SPRITE_SIZE;
+ int x = startX;
+ int y = startY;
+
+ for (int index = 0; index < inventory->itemCount; ++index)
+ {
+ DrawRectangle(x, y, INVENTORY_SPRITE_SIZE, INVENTORY_SPRITE_SIZE, GRAY);
+ DrawText(TextFormat("%d\n", index), x, y, 16, BLACK);
+
+ x += INVENTORY_SPRITE_SIZE;
+
+ if (x >= maxX)
+ {
+ x = startX;
+ y += INVENTORY_SPRITE_SIZE;
+ }
+ }
}
diff --git a/src/ui.h b/src/ui.h
index b5089a3..eee1d4f 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -8,6 +8,7 @@
#define INTERACTION_COLUMN_MAX 80
#define INVENTORY_MAX 10
+#define INVENTORY_SPRITE_SIZE 42
typedef char InteractionItems[INTERACTION_MENU_MAX][INTERACTION_LABEL_MAX];
@@ -31,15 +32,9 @@ typedef struct {
} InteractionMenu;
typedef struct {
- EntityId id;
- AssetId texture;
- int count;
-} InventoryItem;
-
-typedef struct {
Rectangle rect;
bool visable;
- InventoryItem items[INVENTORY_MAX];
+ EntityItem items[INVENTORY_MAX];
int itemCount;
} Inventory;
@@ -68,7 +63,7 @@ void updateInteractionMenu(InteractionMenu* menu, Game* game);
void initInventory(Inventory* inventory);
void showInventory(Inventory* inventory);
void hideInventory(Inventory* inventory);
-void addItemToInventory(Inventory* inventory, InventoryItem item);
+void addItemToInventory(Inventory* inventory, EntityItem item);
void updateInventory(Inventory* inventory);
#endif