aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/inventory.cpp71
-rw-r--r--src/ui.cpp5
-rw-r--r--src/world.cpp8
3 files changed, 83 insertions, 1 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;
+ }
+ }
}
diff --git a/src/ui.cpp b/src/ui.cpp
index 91da2e9..05b540e 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -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){