gamedev
inventory.h
1 #ifndef INVENTORY_H
2 #define INVENTORY_H
3 
4 #include <common.h>
5 #include <string.h>
6 
7 #define DEBUG
8 
9 #define ID Item(
10 #define NAME ,
11 #define TYPE ,
12 #define WIDTH ,
13 #define HEIGHT ,
14 #define STACKSIZE ,
15 #define TEX ,
16 #define ENI ),
17 #define STOP )
18 
19 /*
20  * A list of all item IDs.
21 */
22 
23 enum ITEM_ID {
24  DEBUG_ITEM = 0,
25  TEST_ITEM = 1,
26  PLAYER_BAG = 2,
27  FLASHLIGHT = 3,
28  SWORD_WOOD = 4
29 };
30 
31 enum ITEM_TYPE{
32  TOOL = 1,
33  SWORD = 2,
34  RANGED = 3,
35  EQUIP = 4,
36  FOOD = 5
37 };
38 
39 class Item{
40 protected:
41 public:
42  ITEM_ID id; // ID of the item
43  char *name;
44  ITEM_TYPE type; // What category the item falls under
45  float width;
46  float height;
47  int maxStackSize;
48  char* textureLoc;
49  Texturec *tex;
50  GLuint text;
51 
52  Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl);
53  GLuint rtex(){
54  return tex->image[0];
55  }
56 };
57 
58 struct item_t{
59  int count;
60  ITEM_ID id;
61 } __attribute__((packed));
62 
63 
64 class Inventory {
65 private:
66  unsigned int size; // Size of 'item' array
67  item_t *inv;
68  int os = 0;
69 public:
70  unsigned int sel;
71  bool invOpen = false;
72  bool invOpening = false;
73  bool invHover = false;
74  bool selected = false;
75  bool mouseSel = false;
76 
77 
78  Inventory(unsigned int s); // Creates an inventory of size 's'
79  ~Inventory(void); // Free's allocated memory
80 
81  int addItem(ITEM_ID id,unsigned char count); // Add 'count' items with an id of 'id' to the inventory
82  int takeItem(ITEM_ID id,unsigned char count); // Take 'count' items with an id of 'id' from the inventory
83  int useItem(void);
84 
85  void setSelection(unsigned int s);
86 
87  void draw(void); // Draws a text list of items in this inventory (should only be called for the player for now)
88 
89 };
90 
91 void itemUse(void *p);
92 void initInventorySprites(void);
93 char *getItemTexturePath(ITEM_ID id);
94 int getItemWidth(ITEM_ID);
95 int getItemHeight(ITEM_ID);
96 
97 #endif // INVENTORY_H
Definition: Texture.h:12
Definition: inventory.h:39
Definition: inventory.h:58
Definition: inventory.h:64