#define DEBUG
-enum ITEM_ID { // Contains item IDs for every item in the game, this is how items are stored. IDs are also used to lookup item strings
- TEST_ITEM = 1, // A test item (duh)
+/*
+ * A list of all item IDs.
+*/
+
+enum ITEM_ID {
+ TEST_ITEM = 1,
SWORD_ITEM = 2
};
int addItem(ITEM_ID id,unsigned char count); // Add 'count' items with an id of 'id' to the inventory
int takeItem(ITEM_ID id,unsigned char count); // Take 'count' items with an id of 'id' from the inventory
+ int useItem(ITEM_ID id);
+
+ bool tossd;
+ int itemToss(void);
void setSelection(unsigned int s);
void draw(void); // Draws a text list of items in this inventory (should only be called for the player for now)
+
};
unsigned int initInventorySprites(void); // Loads as many inventory textures as it can find, returns count
GLuint *ITEM_TEX;
+void itemDraw(Player *p,ITEM_ID id);
+
unsigned int initInventorySprites(void){
unsigned int i,loadCount=0;
ITEM_TEX=(GLuint *)calloc(ITEM_COUNT,sizeof(GLuint));
sel=0;
size=s;
item=(struct item_t *)calloc(size,sizeof(struct item_t));
+ tossd=false;
}
Inventory::~Inventory(void){
unsigned int i;
for(i=0;i<size;i++){
if(item[i].id==id){
+#ifdef DEBUG
+ DEBUG_printf("Took %u of player's %s(s).\n",count,itemName[item[i].id]);
+#endif // DEBUG
item[i].count-=count;
if(item[i].count<0)
return item[i].count*-1;
glDisable(GL_TEXTURE_2D);
i++;
}
+ if(item[sel].count)itemDraw(player,item[sel].id);
+}
+
+static vec2 item_coord = {0,0};
+static vec2 item_velcd = {0,0};
+static bool item_tossd = false;
+static bool yes=false;
+
+void itemDraw(Player *p,ITEM_ID id){
+ static vec2 p1,p2;
+ if(!id)return;
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D,ITEM_TEX[id-1]);
+ if(!yes){
+ p1 = {p->loc.x+p->width/2,
+ p->loc.y+p->width/2+HLINE*3};
+ p2 = {(float)(p1.x+p->width*(p->left?-.5:.5)),
+ p->loc.y+HLINE*3};
+ }
+ if(p->inv->tossd) yes=true;
+ std::cout<<item_coord.x<<" "<<item_coord.y<<std::endl;
+ glBegin(GL_QUADS);
+ glTexCoord2i(0,1);glVertex2f(item_coord.x+p1.x,item_coord.y+p2.y);
+ glTexCoord2i(1,1);glVertex2f(item_coord.x+p2.x,item_coord.y+p2.y);
+ glTexCoord2i(1,0);glVertex2f(item_coord.x+p2.x,item_coord.y+p1.y);
+ glTexCoord2i(0,0);glVertex2f(item_coord.x+p1.x,item_coord.y+p1.y);
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
+}
+
+void itemUse(Player *p,ITEM_ID id){
+ switch(id){
+ default:
+ ui::dialogBox(itemName[id],"You cannot use this item.");
+ break;
+ }
+}
+
+int Inventory::itemToss(void){
+ if(!item_tossd && item[sel].count && item[sel].id){
+ item_tossd = true;
+ item_coord.x = HLINE;
+ item_velcd.x = 0;
+ item_velcd.y = 3;
+ tossd = true;
+ return 1;
+ }else if(item_tossd){
+ if(item_coord.y<0){
+ memset(&item_coord,0,sizeof(vec2));
+ memset(&item_velcd,0,sizeof(vec2));
+ item_tossd = false;
+
+ takeItem(item[sel].id,1);
+
+ tossd = yes = false;
+
+ return 0;
+ }else{
+ item_coord.x += item_velcd.x;
+ item_coord.y += item_velcd.y;
+ //item_velcd.x -= .005;
+ item_velcd.y -= .1;
+ return 1;
+ }
+ }
}