]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added holding vs press key action
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 3 Dec 2015 12:44:47 +0000 (07:44 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 3 Dec 2015 12:44:47 +0000 (07:44 -0500)
assets/names_en-us
config/quest_list.txt
include/inventory.h
main.cpp
src/entities.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp

index 2d1f8d9eaca223147972b2e9b5afc9fa6debac36..c65808bdd2083131ddf6fbe22f967ff8d67869b6 100644 (file)
@@ -105,4 +105,5 @@ fSylvia
 fStarla
 fMonserrate
 fAnn
-fAshley
\ No newline at end of file
+fAshley
+fAbby Ross
\ No newline at end of file
index 3014ede6895d44f0a795da2d8d319bb920f3dd42..484a2ccc18e814153507aa5bae1ad587c1b3b73a 100644 (file)
@@ -1 +1 @@
-TITLE "Test" DESC "A test quest" REWARD 1 x TEST_ITEM END
+TITLE "Test" DESC "A test quest" REWARD 1 x SWORD_WOOD END
index b62e491f362133548c246226380b99229b4460fd..18ef6c4f18e744c27a5178883e0feb3fde1fc70b 100644 (file)
@@ -73,6 +73,7 @@ public:
        unsigned int sel;
        bool invOpen = false;
        bool invOpening = false;
+       bool invHover = false;
 
        Inventory(unsigned int s);      // Creates an inventory of size 's'
        ~Inventory(void);                       // Free's allocated memory
index 6230e72c7ebf77b0caf3fa671dc5ee99eaf80208..19d67e7cdb9c745a3abd0a9fc0c02c01c056657f 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -504,7 +504,6 @@ void mainLoop(void){
        */
        
        ui::handleEvents();
-       
        if(prevPrevTime + MSEC_PER_TICK <= currentTime){
                logic();
                prevPrevTime = currentTime;
@@ -529,7 +528,7 @@ void mainLoop(void){
                debugY = player->loc.y;
        }
 
-       render();       // Call the render loop
+       render();       // Call the render loop;
 }
 
 extern bool fadeEnable;
@@ -951,8 +950,10 @@ void logic(){
                                                        o->interact();
                                                        objectInteracting=false;
                                                }
+
                                        }
                                }
+
                        }
                }
        }
index 32867841bcae6f45cbbb7d658a7ac8297c9efb2e..ee5a5420a16e8e7b89111b44b89851a3797b49c0 100644 (file)
@@ -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();
index 64b3908404cb56cfd641dc7dd26df637354a1792..6a2036c8a97a4b5bbead2e77d11126ebaf1dd7a3 100644 (file)
@@ -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);
        
index a365204e714c0d7b5baf95dcab4b88fb7a819228..73e5e32d7f3f76f4e1be7a318989d63160a975bc 100644 (file)
@@ -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++;
                }
index e10ed466ca16e63c0012a98c898432536fc2d9e7..437c9f760405d938f0efa83b964ee461d7e265dd 100644 (file)
@@ -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;