diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2015-12-03 07:44:47 -0500 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2015-12-03 07:44:47 -0500 |
commit | dc24164926a7988e018d32fff1977d2b40c89057 (patch) | |
tree | d9e5e18a7b2582f0e0efe19d4b410d3ccdb05902 /src | |
parent | 1d995c34c871bdb48e35c083ef0d9027dc18d719 (diff) |
Added holding vs press key action
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 5 | ||||
-rw-r--r-- | src/gameplay.cpp | 1 | ||||
-rw-r--r-- | src/inventory.cpp | 50 | ||||
-rw-r--r-- | src/ui.cpp | 18 |
4 files changed, 48 insertions, 26 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index 3286784..ee5a542 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -122,7 +122,6 @@ Structures::Structures(){ //sets the structure type inWorld = NULL; } Structures::~Structures(){ - delete inv; delete tex; delete[] name; } @@ -177,7 +176,6 @@ Object::Object(ITEM_ID id, bool qo, const char *pd){ Object::~Object(){ delete[] pickupDialog; - delete inv; delete tex; delete[] name; } @@ -339,7 +337,8 @@ void NPC::interact(){ //have the npc's interact back to the player } } -void Object::interact(void){ + +void Object::interact(void){ if(questObject && alive){ ui::dialogBox("You",":Yes:No",pickupDialog); ui::waitForDialog(); diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 64b3908..6a2036c 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -108,6 +108,7 @@ void initEverything(void){ playerSpawnHill->addStructure(STRUCTURET,(rand()%120*HLINE),10,test,iw); playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE); + playerSpawnHill->addObject(SWORD_WOOD, false, "", 480,200); playerSpawnHill->addObject(SWORD_WOOD, false, "", 500,200); playerSpawnHill->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200); diff --git a/src/inventory.cpp b/src/inventory.cpp index a365204..73e5e32 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -55,18 +55,21 @@ void Inventory::setSelection(unsigned int s){ } int Inventory::addItem(ITEM_ID id,unsigned char count){ - inv[os].id = id; - inv[os].count = count; - os++; + std::cout << id << "," << inv[os].id << std::endl; + for(int i = 0; i < size; i++){ + if(id == inv[i].id){ + inv[i].count += count; + break; + }else if(id ){ + inv[os].id = id; + inv[os].count = count; + os++; + break; + } + } #ifdef DEBUG DEBUG_printf("Gave player %u more %s(s)(ID: %d).\n",count,item[id].name,item[id].id); #endif // DEBUG - - -/*#ifdef DEBUG - DEBUG_printf("Failed to add non-existant item with id %u.\n",id); -#endif // DEBUG*/ - return 0; } @@ -87,7 +90,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){ } void Inventory::draw(void){ - ui::putText(offset.x-SCREEN_WIDTH/2,480,"%d",sel); + std::cout << invHover << std::endl; unsigned int i=0; static unsigned int lop = 0; float y,xoff; @@ -96,12 +99,14 @@ void Inventory::draw(void){ static std::vector<Ray>iray(numSlot); static std::vector<vec2>curCoord(numSlot); static int range = 200; + static int itemWide = 45; float angleB = (float)180/(float)numSlot; float angle = float(angleB/2.0f); unsigned int a = 0; unsigned int end = 0; for(auto &r : iray){ - r.start = player->loc; + r.start.x = player->loc.x + (player->width/2); + r.start.y = player->loc.y + (player->height/2); curCoord[a] = r.start; //dfp[a] = 0; a++; @@ -127,32 +132,33 @@ void Inventory::draw(void){ } if(end >= numSlot)invOpen=false; } - if(invOpen){ + if(invOpen || invHover){ for(auto &r : iray){ angle=180-(angleB*a) - angleB/2.0f; curCoord[a].x += float((dfp[a]) * cos(angle*PI/180)); curCoord[a].y += float((dfp[a]) * sin(angle*PI/180)); r.end = curCoord[a]; - glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)range)*0.3f); + glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)range)*invHover ? 0.2f : 0.5f); glBegin(GL_QUADS); - glVertex2i(r.end.x, r.end.y); - glVertex2i(r.end.x+45, r.end.y); - glVertex2i(r.end.x+45, r.end.y+45); - glVertex2i(r.end.x, r.end.y+45); + glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)); + glVertex2i(r.end.x-(itemWide/2)+itemWide, r.end.y-(itemWide/2)); + glVertex2i(r.end.x-(itemWide/2)+itemWide, r.end.y-(itemWide/2)+itemWide); + glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)+itemWide); glEnd(); if(inv[a].count > 0){ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, itemtex[inv[a].id]); - glColor4f(1.0f, 1.0f, 1.0f, (float)dfp[a]/(float)range); + glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)range)*invHover ? 0.5f : 1.0f); glBegin(GL_QUADS); - glTexCoord2i(0,1);glVertex2i(r.end.x, r.end.y); - glTexCoord2i(1,1);glVertex2i(r.end.x+45, r.end.y); - glTexCoord2i(1,0);glVertex2i(r.end.x+45, r.end.y+45); - glTexCoord2i(0,0);glVertex2i(r.end.x, r.end.y+45); + glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)); + glTexCoord2i(1,1);glVertex2i(r.end.x-(itemWide/2)+itemWide, r.end.y-(itemWide/2)); + glTexCoord2i(1,0);glVertex2i(r.end.x-(itemWide/2)+itemWide, r.end.y-(itemWide/2)+itemWide); + glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)+itemWide); glEnd(); glDisable(GL_TEXTURE_2D); + ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/1.75),"%d",inv[a].count); } a++; } @@ -516,6 +516,7 @@ namespace ui { void handleEvents(void){ static bool left=false,right=false; static vec2 premouse={0,0}; + static int heyOhLetsGo = 0; unsigned char i; SDL_Event e; @@ -611,6 +612,13 @@ DONE: if(SDL_KEY==SDLK_p)toggleBlack(); if(SDL_KEY==SDLK_F3)debug^=true; if(SDL_KEY==SDLK_b & SDL_KEY==SDLK_F3)posFlag^=true; + if(SDL_KEY==SDLK_e){ + if(heyOhLetsGo == 0){ + heyOhLetsGo = loops; + }else if(loops - heyOhLetsGo >= 5 && !(player->inv->invOpen)){ + player->inv->invHover=true; + } + } break; /* KEYUP @@ -623,7 +631,15 @@ DONE: if(SDL_KEY==SDLK_LCTRL)player->speed = 1; if(SDL_KEY==SDLK_h)player->health-=5; if(SDL_KEY==SDLK_f)player->light ^= true; - if(SDL_KEY==SDLK_e)player->inv->invOpening ^= true; + if(SDL_KEY==SDLK_e){ + if(player->inv->invHover){ + player->inv->invHover = false; + heyOhLetsGo = 0; + }else{ + player->inv->invOpening ^= true; + heyOhLetsGo = 0; + } + } if(SDL_KEY==SDLK_RIGHT){player->inv->sel+=1;} if(SDL_KEY==SDLK_LEFT){if(player->inv->sel!=0)player->inv->sel-=1;} break; |