diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-29 15:51:07 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-29 15:51:07 -0400 |
commit | 9ab6025a0cc3ab31c476f0b478ac69bfadd7f670 (patch) | |
tree | 2a4f30084ea02a8dfc80f63cf11caa97c8dd93f8 | |
parent | 9133b5b379f565ca9f268b63864155051c464cb1 (diff) |
inventory visuals / item drop (Q)
-rw-r--r-- | Changelog | 5 | ||||
-rw-r--r-- | include/inventory.h | 13 | ||||
-rw-r--r-- | src/inventory.cpp | 71 | ||||
-rw-r--r-- | src/ui.cpp | 5 | ||||
-rw-r--r-- | src/world.cpp | 8 |
5 files changed, 99 insertions, 3 deletions
@@ -201,3 +201,8 @@ - documented world.h - fixed camera ortho - began working on layer-switching animation + - added variable width backgrounds + - added a debug sprint speed + + - the currently selected item is now drawn on the player + - pressing q discards (w/ visuals) the currently selected item diff --git a/include/inventory.h b/include/inventory.h index cb3e59d..e27391a 100644 --- a/include/inventory.h +++ b/include/inventory.h @@ -5,8 +5,12 @@ #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 }; @@ -26,10 +30,15 @@ public: 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 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; + } + } } @@ -262,6 +262,9 @@ namespace ui { player->ground=false; } } + if(SDL_KEY==SDLK_q){ + player->inv->itemToss(); + } if(SDL_KEY==SDLK_c){ dialogBox("","You pressed `c`, but nothing happened."); } @@ -287,6 +290,8 @@ namespace ui { } } + if(player->inv->tossd)player->inv->itemToss(); + unsigned int i; if(!dialogBoxExists&&AIpreaddr.size()){ // Flush preloaded AI functions if necessary for(i=0;i<AIpreaddr.size();i++){ diff --git a/src/world.cpp b/src/world.cpp index 641dbf9..5ff1f0f 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -602,7 +602,13 @@ void World::addHole(unsigned int start,unsigned int end){ } int World::getTheWidth(void){ - return -x_start*2; + World *hey=this; +LOOP: + if(hey->infront){ + hey=hey->infront; + goto LOOP; + } + return -hey->x_start*2; } IndoorWorld::IndoorWorld(void){ |