]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Look at my fancy inventory
authordrumsetmonkey <abelleisle@roadrunner.com>
Mon, 30 Nov 2015 12:29:39 +0000 (07:29 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Mon, 30 Nov 2015 12:29:39 +0000 (07:29 -0500)
16 files changed:
Changelog
Makefile
config/items.h
include/Texture.h
include/common.h
include/entities.h
include/inventory.h
main.cpp
src/Makefile
src/Quest.cpp
src/Texture.cpp
src/common.cpp
src/entities.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp

index 50e8f44570f5547e929cb7e8dfa4b397f6d6f46c..0444f3d485b6b6f1c3784c209403ff89107fc1c0 100644 (file)
--- a/Changelog
+++ b/Changelog
        - moved background drawing to World class
        - re-did the item system
        - actually tiled background images to save space
+
+11/23/2015:
+===========
+       - 2 month Changelog anniversary :)
+       - Created the new inventory ui
+       - Fixed texture loading bugs
+
+11/24/2015:
+===========
+
+       - Bug fixes related to memory allocation
+       - Broke item textures...
+       - Finshed new inventory ui animations
index 8ecebf8e3828ece551b912c41c4b177eafdcbc79..307b137944b5304b16e5c7353407e9ff40f5b4bc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-LIBS = -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
+LIBS = -lpthread -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
 \r
 WIN_LIBS = -lopengl32 -lglew32 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype\r
 \r
index a3ec683716dc67540c1b9ca00359b896b5e2210e..3189a296a3bca63d5dd58939c48558f01a2d3c8a 100644 (file)
@@ -1,5 +1,5 @@
 ID DEBUG_ITEM
-       NAME "Debug"
+       NAME "Debug\0"
        TYPE TOOL 
        WIDTH 1 
        HEIGHT 1 
@@ -8,7 +8,7 @@ ID DEBUG_ITEM
        ENI
 
 ID TEST_ITEM   
-       NAME "Dank MayMay" 
+       NAME "Dank MayMay\0
        TYPE TOOL 
        WIDTH HLINE 
        HEIGHT HLINE 
@@ -17,7 +17,7 @@ ID TEST_ITEM
        ENI
 
 ID PLAYER_BAG  
-       NAME "Your Bag" 
+       NAME "Your Bag\0
        TYPE EQUIP 
        WIDTH HLINE*5 
        HEIGHT HLINE*5 
@@ -26,7 +26,7 @@ ID PLAYER_BAG
        ENI
 
 ID FLASHLIGHT  
-       NAME "Flashlight" 
+       NAME "Flashlight\0
        TYPE TOOL 
        WIDTH HLINE*2 
        HEIGHT HLINE*4 
@@ -35,7 +35,7 @@ ID FLASHLIGHT
        ENI
 
 ID SWORD_WOOD  
-       NAME "Wood Sword" 
+       NAME "Wood Sword\0
        TYPE SWORD 
        WIDTH HLINE*4 
        HEIGHT HLINE*10 
index 81a743eaa4da84bbbe0373cf6fae43b5abe46a5a..a3f242be1bdfce43821ddfc60d3ca87e282c012f 100644 (file)
@@ -11,7 +11,6 @@ namespace Texture{
 
 class Texturec{
 private:
-       GLuint *image;
        int texState;
 public:
        Texturec(uint amt, ...);
@@ -19,6 +18,8 @@ public:
        void bindPrev();
        void bind(int);
        void walk();
+
+       GLuint *image;
 };
 
 #endif //TEXTURE_H
index bfd9db66d6df0118af96e9c64b9915b5fd793da7..525a4cd420a006a977175700ba173bb8ba5bcf8f 100644 (file)
@@ -9,6 +9,8 @@
 #include <cstdlib>
 #include <vector>
 #include <math.h>
+ #include <thread>
+
 
 /*
  *     Include GLEW and the SDL 2 headers
@@ -60,8 +62,8 @@ typedef struct {
 
 #define GAME_NAME              "Independent Study v.0.3 alpha"
 
-#define SCREEN_WIDTH   1200
-#define SCREEN_HEIGHT  720
+#define SCREEN_WIDTH   1792
+#define SCREEN_HEIGHT  1008
 
 //#define FULLSCREEN
 
@@ -134,4 +136,9 @@ void DEBUG_prints(const char* file, int line, const char *s,...);
 void safeSetColor(int r,int g,int b);
 void safeSetColorA(int r,int g,int b,int a);
 
+unsigned int safe_strlen(const char*);
+
+void DrawCircle(float cx, float cy, float r, int num_segments);
+
+
 #endif // COMMON_H
index 403c3c50144fe58920309eb5fba17b838fb25f7b..be5c000cc67f0b3d14c053c2c19961f8d5bb6176 100644 (file)
@@ -114,9 +114,12 @@ class Object : public Entity{
 public:
        Object(int);
        Object(int, bool, char*);
-       void interact();
+       void interact(void);
        bool questObject = false;
        char *pickupDialog;
+       std::thread runInteract() {
+          return std::thread([=] { interact(); });
+    }
 private:
        int identifier;
 };
index dc5c04e34b348b2098413fbb4d474678213091fb..3fdbf528f3e924efe2cf6838e9b8eb338272d4c9 100644 (file)
@@ -2,6 +2,7 @@
 #define INVENTORY_H
 
 #include <common.h>
+#include <string.h>
 
 #define DEBUG
 
@@ -19,8 +20,6 @@
  * A list of all item IDs.
 */
 
-static unsigned int sel;
-
 enum ITEM_ID {
        DEBUG_ITEM = 69,
        TEST_ITEM = 1,
@@ -49,15 +48,23 @@ public:
        float height;
        int maxStackSize;
        char* textureLoc;
+       Texturec *tex;
        int count;
        Item(ITEM_ID i, char* n, ITEM_TYPE t, float w, float h, int m, char* tl):
-               id(i), name(n), type(t), width(w), height(h), maxStackSize(m), textureLoc(tl){
+               id(i), type(t), width(w), height(h), maxStackSize(m){
                count = 0;
+
+               name            = (char*)calloc(strlen(n ),sizeof(char));
+               textureLoc      = (char*)calloc(strlen(tl),sizeof(char));
+
+               strcpy(name,n);
+               strcpy(textureLoc,tl);
+
+               tex= new Texturec(1,textureLoc);
        }
-       void addCount(int c){
-               count += c;
+       GLuint rtex(){
+               return tex->image[0];
        }
-
 };
 
 static Item item[5]= {
@@ -66,20 +73,20 @@ static Item item[5]= {
 
 struct item_t{
        int count;
-       ITEM_ID itmid;
-       void addC(int c, ITEM_ID i){
-               count = c;
-               itmid = i;
-               item[itmid].addCount(count);
-       }
+       ITEM_ID id;
 } __attribute__((packed));
 
 
 class Inventory {
 private:
        unsigned int size;              // Size of 'item' array
+       item_t *inv;
+       int os = 0;
        //struct item_t *item;  // An array of the items contained in this inventory.
 public:
+       unsigned int sel;
+       bool invOpen = false;
+       bool invOpening = false;
 
        Inventory(unsigned int s);      // Creates an inventory of size 's'
        ~Inventory(void);                       // Free's 'item'
@@ -97,7 +104,6 @@ public:
        
 };
 
-unsigned int initInventorySprites(void);       // Loads as many inventory textures as it can find, returns count
 void itemUse(void *p);
 
 #endif // INVENTORY_H
index 1e311ad3d3b5b57943f83ac9faaec11fdfbfbd56..30ee463b311d48940d1aae0a2b4028ff7d51c3a5 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -433,9 +433,9 @@ int main(int argc, char *argv[]){
        invUI = Texture::loadTexture("assets/invUI.png" );
        
        //std::cout << "Before invSprites\n";
-       initInventorySprites();
+       //initInventorySprites();
        //std::cout << "After invSprites\n";
-       
+
        /**************************
        ****     GAMELOOP      ****
        **************************/
@@ -457,12 +457,6 @@ int main(int argc, char *argv[]){
     SDL_GL_DeleteContext(mainGLContext);
     SDL_DestroyWindow(window);
     
-    FILE *worldSave = fopen("world.dat","w");
-    char *worldBuf;
-    unsigned int worldSize;
-    worldBuf=currentWorld->save(&worldSize);
-    fclose(worldSave);
-    
     return 0;  // Calls everything passed to atexit
 }
 
@@ -680,29 +674,8 @@ void render(){
                        //for length
                        for(int l = 0;l<=lightStr;l++){
                                //std::cout << a << ": " << curCoord.x << "," << curCoord.y << "\n";
-                               if(angle == 0){
-                                       curCoord.x += HLINE;
-                                       curCoord.y += 0;
-                               }
-                               if(angle == 90){
-                                       curCoord.y += HLINE;
-                                       curCoord.x += 0;
-                               }
-                               if(angle == 180){
-                                       curCoord.x -= HLINE;
-                                       curCoord.y += 0;
-                               }
-                               if(angle == 270){
-                                       curCoord.y -= HLINE;
-                                       curCoord.x += 0;
-                               }
-                               if(angle == 360){
-                                       curCoord.x += HLINE;
-                                       curCoord.y += 0;
-                               }else{
-                                       curCoord.x += float((HLINE) * cos(angle*PI/180));
-                                       curCoord.y += float((HLINE) * sin(angle*PI/180));
-                               }
+                               curCoord.x += float((HLINE) * cos(angle*PI/180));
+                               curCoord.y += float((HLINE) * sin(angle*PI/180));
                                for(auto &en : currentWorld->entity){
                                        if(curCoord.x > en->loc.x && curCoord.x < en->loc.x + en->width && en->type!=STRUCTURET){
                                                if(curCoord.y > en->loc.y && curCoord .y < en->loc.y + en->height){
@@ -972,7 +945,8 @@ void logic(){
                                        */
 
                                        if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
-                                               o->interact();
+                                               std::thread thr(o->runInteract());
+                                               thr.detach();
                                        }
                                }
                        }
index f40ab90a71f66e964e39fda497f82619ee95bcce..03652fce3b9408c90cad9602af19b579d5e400d5 100644 (file)
@@ -1,4 +1,4 @@
-LIBS = -lGL -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
+LIBS = -lpthread -lGL -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
 
 FLAGS = -std=c++11 -I../include -I../include/freetype2
 
index 5fd7726fbb6a9ec62788f5c5d44a19bb18348fb3..6789a05e267f133b2d893ef6b4e872fdafb220b2 100644 (file)
@@ -14,15 +14,6 @@ const Quest QuestList[TOTAL_QUESTS]={
 \r
 };\r
 \r
-// Trust nobody\r
-#define STRLEN_MIN 16\r
-\r
-unsigned int safe_strlen(const char *s){\r
-       unsigned int size=0;\r
-       while(s[size])size++;\r
-       if(size<STRLEN_MIN)return STRLEN_MIN;\r
-       else return size;\r
-}\r
 \r
 Quest::Quest(const char *t,const char *d,struct item_t r){\r
        title=(char *)calloc(safe_strlen(t),sizeof(char));\r
@@ -85,7 +76,7 @@ int QuestHandler::finish(const char *t,void *completer){
 #ifdef DEBUG\r
                        DEBUG_printf("Completing quest %s.\n",t);\r
 #endif // DEBUG\r
-                       ((Entity *)completer)->inv->addItem(current[i]->reward.itmid,current[i]->reward.count);\r
+                       ((Entity *)completer)->inv->addItem(current[i]->reward.id,current[i]->reward.count);\r
                        current.erase(current.begin()+i);\r
 #ifdef DEBUG\r
                        DEBUG_printf("QuestHandler now has %u active quests.\n",current.size());\r
index b17d20445b5c51a47baa66b7a17af094955b1aa1..82baa71767b77a8e4dba9d655a9b1fd7713efddb 100644 (file)
@@ -54,7 +54,7 @@ namespace Texture{
                SDL_FreeSurface(image); // Free the surface
                
                LoadedTexture[LoadedTextureCounter]               = (struct texture_t *)malloc(sizeof(struct texture_t));
-               LoadedTexture[LoadedTextureCounter]->name = (char *)malloc(strlen(fileName));
+               LoadedTexture[LoadedTextureCounter]->name = (char *)malloc(safe_strlen(fileName));
                LoadedTexture[LoadedTextureCounter]->tex  = object;
                strcpy(LoadedTexture[LoadedTextureCounter]->name,fileName);
                LoadedTextureCounter++;
index a8a964e2301af30defecbf6809573473d289072e..f3c399923b1dd26bdfb0df9b5884686c95e3455c 100644 (file)
@@ -32,3 +32,29 @@ void safeSetColorA(int r,int g,int b,int a){
        if(a<0)a=0;
        glColor4ub(r,g,b,a);
 }
+
+//only trust the NSA
+#define STRLEN_MIN 32
+
+unsigned int safe_strlen(const char *s){
+       unsigned int size=0;
+       while(s[size])size++;
+       if(size<STRLEN_MIN)return STRLEN_MIN;
+       else return size;
+}
+
+void DrawCircle(float cx, float cy, float r, int num_segments) 
+{ 
+       glBegin(GL_LINE_LOOP); 
+       for(int ii = 0; ii < num_segments; ii++) 
+       { 
+               float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle 
+
+               float x = r * cosf(theta);//calculate the x component 
+               float y = r * sinf(theta);//calculate the y component 
+
+               glVertex2f(x + cx, y + cy);//output vertex 
+
+       } 
+       glEnd(); 
+}
\ No newline at end of file
index af32cd6c18442723d5c679b328eaab1983e6aa18..c2c560aecb4c2a4a14023ed3a3c293555e4521ed 100644 (file)
@@ -108,7 +108,7 @@ Object::Object(int id):identifier(id){
        height = HLINE * 8;
 
        maxHealth = health = 1;
-       tex = new Texturec(1, "assets/items/ITEM_SWORD.png");
+       tex = new Texturec(1, item[id].textureLoc);
 
        questObject = false;
        pickupDialog="\0";
@@ -122,7 +122,7 @@ Object::Object(int id, bool qo, char *pd):identifier(id),questObject(qo),pickupD
        height = HLINE * 8;
 
        maxHealth = health = 1;
-       tex = new Texturec(1, "assets/items/ITEM_SWORD.png");   
+       tex = new Texturec(1, item[id].textureLoc);     
 }
 
 
@@ -316,14 +316,16 @@ void NPC::interact(){ //have the npc's interact back to the player
 }
 
 extern void waitForDialog(void);
-void Object::interact(){
+void Object::interact(void){
        if(questObject){
-               char opt[]=":No:Yes";
+               char opt[]=":Yes:No";
                ui::dialogBox("You",opt,pickupDialog);
-               if(ui::dialogOptChosen == 1){
-                       this->alive = false;
-                       player->inv->addItem((ITEM_ID)(identifier), (char)1);
-               }
+               do{
+                       if(ui::dialogOptChosen == 1 && this->alive == true){
+                               player->inv->addItem((ITEM_ID)(identifier), (char)1);
+                               this->alive = false;
+                       }
+               }while(ui::dialogBoxExists);
        }else{
                this->alive = false;
                player->inv->addItem((ITEM_ID)(identifier), (char)1);
index 52aceb89ba7c998d9cb6870da0f1cc40bbb2fd61..6e85b6db5344a2b1e218fde0b83ffe209ad6928a 100644 (file)
@@ -162,6 +162,13 @@ void initEverything(void){
        
        currentWorld->addObject(SWORD_WOOD, false, NULL, 500,200);
        currentWorld->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200);
+
+       /*currentWorld->addObject(DEBUG_ITEM, 500,200);
+       currentWorld->addObject(TEST_ITEM,  550,200);
+       currentWorld->addObject(PLAYER_BAG, 600,200);
+       currentWorld->addObject(SWORD_WOOD, 650,200);
+       currentWorld->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",700,200);
+       */
        /*
         *      Link all the entities that were just created to the initial world, and setup a test AI function. 
        */
index edc88ff59b6ebbfe0a7cd1590346170635f61e4b..25477603dff9201dbd51fbb855768a8260f7d5ed 100644 (file)
@@ -7,26 +7,12 @@
 extern Player *player;
 extern GLuint invUI;
 
-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));
-       for(i=0;i<ITEM_COUNT;i++){
-               if((ITEM_TEX[i]=Texture::loadTexture(item[i].textureLoc)))loadCount++;
-       }
-#ifdef DEBUG
-       DEBUG_printf("Loaded %u/%u item texture(s).\n",loadCount,ITEM_COUNT);
-#endif // DEBUG
-       return loadCount;
-}
-
 Inventory::Inventory(unsigned int s){
        sel=0;
        size=s;
-       //item=(struct item_t *)calloc(size,sizeof(struct item_t));
+       inv=(struct item_t *)calloc(size,sizeof(struct item_t));
        tossd=false;
 }
 
@@ -39,43 +25,29 @@ void Inventory::setSelection(unsigned int s){
 }
 
 int Inventory::addItem(ITEM_ID id,unsigned char count){
-       unsigned int i;
-
-       for(i=0;i<size;i++){
-               if(item[i].id==id){
-                       item[i].count+=count;
-
-                       #ifdef DEBUG
-                       DEBUG_printf("Gave player %u more %s(s).\n",count,item[i].name);
-                       #endif // DEBUG
-
-                       return 0;
-               }else if(!item[i].count){
-                       item[i].id=id;
-                       item[i].count=count;
+       inv[os].id = id;
+       inv[os].count = count;
+       os++;
 
-                       #ifdef DEBUG
-                       DEBUG_printf("Gave player %u %s(s).\n",count,item[i].name);
-                       #endif // DEBUG
 
-                       return 0;
-               }
-       }
+       #ifdef DEBUG
+       DEBUG_printf("Gave player %u more %s(s)(%d).\n",count,item[id].name,item[id].id);
+       #endif // DEBUG
 
-#ifdef DEBUG
+       /*#ifdef DEBUG
        DEBUG_printf("Failed to add non-existant item with id %u.\n",id);
-#endif // DEBUG
-       return -1;
+       #endif // DEBUG*/
+       return 0;
 }
 
 int Inventory::takeItem(ITEM_ID id,unsigned char count){
        unsigned int i;
        for(i=0;i<size;i++){
-               if(item[i].id==id){
+               if(inv[i].id==id){
 #ifdef DEBUG
                        DEBUG_printf("Took %u of player's %s(s).\n",count,item[i].name);
 #endif // DEBUG
-                       item[i].count-=count;
+                       inv[i].count-=count;
                        if(item[i].count<0)
                                return item[i].count*-1;
                        return 0;
@@ -85,36 +57,104 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
 }
 
 void Inventory::draw(void){
+       ui::putText(offset.x-SCREEN_WIDTH/2,480,"%d",sel);
        unsigned int i=0;
-       float y=offset.y,xoff;
-       glEnable(GL_TEXTURE_2D);
-       glBindTexture(GL_TEXTURE_2D, invUI);
-       glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2i(offset.x-SCREEN_WIDTH/2,                   0);
-               glTexCoord2i(1,1);glVertex2i(offset.x-SCREEN_WIDTH/2+261,               0);
-               glTexCoord2i(1,0);glVertex2i(offset.x-SCREEN_WIDTH/2+261,          57);
-               glTexCoord2i(0,0);glVertex2i(offset.x-SCREEN_WIDTH/2,              57);
-       glEnd();
-       glDisable(GL_TEXTURE_2D);
-       while(item[i].count){
-               y-=HLINE*12;
-               xoff=ui::putText(offset.x-SCREEN_WIDTH/2,y,"%d x ",item[i].count);
+       float y,xoff;
+
+
+       static int numSlot = 7;
+       static std::vector<int>dfp(numSlot);
+       static std::vector<Ray>iray(numSlot);
+       static std::vector<vec2>curCoord(numSlot);
+       static int range = 200;
+       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;
+               curCoord[a] = r.start;
+               //dfp[a] = 0;
+               a++;
+       }a=0;
+       if(invOpening){
+               end = 0;
+               for(auto &d : dfp){
+                       if(a != 0){
+                               if(dfp[a-1]>25)d+=25;
+                       }else{
+                               d += 25;
+                       }
+                       if(d >= range)
+                               d = range;
+                       a++;
+               }a=0;
+               if(end < numSlot)invOpen=true;
+       }else if(!invOpening){
+               for(auto &d : dfp){
+                       if(d > 0){
+                               if(a != 0){
+                                       //d-=25;
+                                       if(dfp[a-1]+25<d || dfp[a-1]<=0)d-=25;
+                               }else{
+                                       d-=25;
+                               }
+                       }else end++;
+                       a++;
+               }a=0;
+               if(end >= numSlot)invOpen=false;
+       }
+       if(invOpen){
+               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];
+
+                       item[inv[i].id].tex->bind(0);                   
+                       glColor4f(1.0f, 1.0f, 1.0f, (float)dfp[a]/(float)range);
+                       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);
+                       glEnd();
+                       a++;
+               }
+       }
+
+
+       /*else if(!invOpen){
+               for(auto &d : dfp){
+                       d = 0;
+               }
                glEnable(GL_TEXTURE_2D);
-               glBindTexture(GL_TEXTURE_2D,ITEM_TEX[item[i].id]);
-               if(sel==i)glColor3ub(255,0,255);
-               else      glColor3ub(255,255,255);
+               glBindTexture(GL_TEXTURE_2D, invUI);
                glBegin(GL_QUADS);
-                       glTexCoord2i(0,1);glVertex2i(xoff                 ,y);
-                       glTexCoord2i(1,1);glVertex2i(xoff+HLINE*10,y);
-                       glTexCoord2i(1,0);glVertex2i(xoff+HLINE*10,y+HLINE*10);
-                       glTexCoord2i(0,0);glVertex2i(xoff                 ,y+HLINE*10);
+                       glTexCoord2i(0,1);glVertex2i(offset.x-SCREEN_WIDTH/2,                   0);
+                       glTexCoord2i(1,1);glVertex2i(offset.x-SCREEN_WIDTH/2+261,               0);
+                       glTexCoord2i(1,0);glVertex2i(offset.x-SCREEN_WIDTH/2+261,          57);
+                       glTexCoord2i(0,0);glVertex2i(offset.x-SCREEN_WIDTH/2,              57);
                glEnd();
-               y-=ui::fontSize*1.15;
-               ui::putText(offset.x-SCREEN_WIDTH/2,y,"%s",item[i].name);
                glDisable(GL_TEXTURE_2D);
-               i++;
-       }
-       if(item[sel].count)itemDraw(player,item[sel].id);
+               while(i<size && inv[i].count > 0 && i<5){
+                       y = 6;
+                       xoff = (offset.x - (SCREEN_WIDTH /2)) + (51*i) + 6;
+                       glEnable(GL_TEXTURE_2D);
+                       item[inv[i].id].tex->bind(0);
+                       if(sel==i)glColor3ub(255,0,255);
+                       else      glColor3ub(255,255,255);
+                       glBegin(GL_QUADS);
+                               glTexCoord2i(0,1);glVertex2i(xoff,              y);
+                               glTexCoord2i(1,1);glVertex2i(xoff+45,   y);
+                               glTexCoord2i(1,0);glVertex2i(xoff+45,   y+45);
+                               glTexCoord2i(0,0);glVertex2i(xoff,              y+45);
+                       glEnd();
+                       glDisable(GL_TEXTURE_2D);
+                       i++;
+               }
+       }*/
+       if(inv[sel].count)itemDraw(player,inv[sel].id);
 }
 
 static vec2 item_coord = {0,0};
@@ -126,7 +166,7 @@ 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]);
+       item[id].tex->bind(0);
        if(!yes){
                p1 = {p->loc.x+p->width/2,
                          p->loc.y+p->width/2+HLINE*3};
@@ -134,23 +174,24 @@ void itemDraw(Player *p,ITEM_ID id){
                          p->loc.y+HLINE*3};
        }
        if(p->inv->tossd) yes=true;
+       glColor4ub(255,255,255,255);
        glBegin(GL_QUADS);
                glTexCoord2i(0,1);glVertex2f(item_coord.x+p->loc.x,                                             item_coord.y+p->loc.y);
-               glTexCoord2i(1,1);glVertex2f(item_coord.x+item[sel].width+p->loc.x,             item_coord.y+p->loc.y);
-               glTexCoord2i(1,0);glVertex2f(item_coord.x+item[sel].width+p->loc.x,             item_coord.y+item[sel].height+p->loc.y);
-               glTexCoord2i(0,0);glVertex2f(item_coord.x+p->loc.x,                                             item_coord.y+item[sel].height+p->loc.y);
+               glTexCoord2i(1,1);glVertex2f(item_coord.x+item[id].width+p->loc.x,              item_coord.y+p->loc.y);
+               glTexCoord2i(1,0);glVertex2f(item_coord.x+item[id].width+p->loc.x,              item_coord.y+item[id].height+p->loc.y);
+               glTexCoord2i(0,0);glVertex2f(item_coord.x+p->loc.x,                                             item_coord.y+item[id].height+p->loc.y);
        glEnd();
        glDisable(GL_TEXTURE_2D);
 }
 
 int Inventory::useItem(void){
-       ITEM_ID id = item[sel].id;
+       ITEM_ID id = item[inv[sel].id].id;
        switch(id){
-       case SWORD_WOOD:
-
+       case FLASHLIGHT:
+               player->light ^= true;
                break;
        default:
-               ui::dialogBox(item[id].name,NULL,"You cannot use this item.");
+               //ui::dialogBox(item[id].name,NULL,"You cannot use this item.");
                break;
        }
        return 0;
index 21df830084ab25ae6f064040445c1d0aa3435dee..790248b11e8e56ace6a37fd9bc5417a6575e7e4e 100644 (file)
@@ -527,7 +527,7 @@ DONE:
                                KEYDOWN
                        */
                        case SDL_KEYDOWN:
-                               if(SDL_KEY==SDLK_ESCAPE)gameRunning=false;                                                      // Exit the game with ESC
+                       if(SDL_KEY==SDLK_ESCAPE)gameRunning=false;                                                      // Exit the game with ESC
                        if(!dialogBoxExists&&!fadeEnable){
                                if(SDL_KEY==SDLK_a){                                                                                            // Move left
                                        left=true;
@@ -583,17 +583,12 @@ DONE:
                                if(SDL_KEY==SDLK_q){
                                        player->inv->itemToss();
                                }
-                               if(SDL_KEY==SDLK_e){
-                                       player->inv->useItem();
-                               }
                                if(SDL_KEY==SDLK_LSHIFT)player->speed = debug?4:3;                                                      // Sprint
                                if(SDL_KEY==SDLK_LCTRL)player->speed = .5;
                        }
                                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_UP)handAngle++;
-                               if(SDL_KEY==SDLK_DOWN)handAngle--;
                                break;
                        /*
                                KEYUP
@@ -606,9 +601,9 @@ 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_UP)handAngle+=0;
-                               if(SDL_KEY==SDLK_DOWN)handAngle-=0;
-
+                               if(SDL_KEY==SDLK_e)player->inv->invOpening ^= true;
+                               if(SDL_KEY==SDLK_RIGHT){player->inv->sel+=1;}
+                               if(SDL_KEY==SDLK_LEFT){if(player->inv->sel!=0)player->inv->sel-=1;}
                                break;
                        default:
                                break;