aboutsummaryrefslogtreecommitdiffstats
path: root/src/inventory.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-10-29 15:51:07 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-10-29 15:51:07 -0400
commit9ab6025a0cc3ab31c476f0b478ac69bfadd7f670 (patch)
tree2a4f30084ea02a8dfc80f63cf11caa97c8dd93f8 /src/inventory.cpp
parent9133b5b379f565ca9f268b63864155051c464cb1 (diff)
inventory visuals / item drop (Q)
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r--src/inventory.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 2eb0087..3043e80 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -20,6 +20,8 @@ const char *ITEM_SPRITE[]={
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));
@@ -36,6 +38,7 @@ Inventory::Inventory(unsigned int s){
sel=0;
size=s;
item=(struct item_t *)calloc(size,sizeof(struct item_t));
+ tossd=false;
}
Inventory::~Inventory(void){
@@ -74,6 +77,9 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
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;
@@ -105,4 +111,69 @@ void Inventory::draw(void){
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;
+ }
+ }
}