]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
inventory rewrite
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 2 Feb 2016 13:49:38 +0000 (08:49 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 2 Feb 2016 13:49:38 +0000 (08:49 -0500)
15 files changed:
.gitignore
Changelog
config/items.xml [new file with mode: 0644]
include/Quest.h
include/entities.h
include/inventory.h
include/world.h
main.cpp
src/Quest.cpp
src/entities.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp
src/world.cpp
xml/playerSpawnHill1.xml

index c00a3b1de5954f0d9dfba189f03a6ccc812d2b0c..c3f16959d71aa2ef3831b47a64da0c282378c2fd 100644 (file)
@@ -1,3 +1,2 @@
-main.exe\r
 main\r
 doc/**\r
index c74cbc22af9c8f11e1d87f1048e1b60b89dee56e..f5b68470b6b7601ec5ddd68efa3b3933404618a6 100644 (file)
--- a/Changelog
+++ b/Changelog
        - Game has a menu API
        - Pause Menu
 
+1/26/2016:
+==========
+
+       - wrote paper regarding what we've learned, and where we're at
+       - ported game to Windows, left EXE and DLLs in repo
+       
+2/1/2016:
+=========
+
+       - began rewriting item/inventory system
+       - worked on option menu actually modifying options (updating settings.xml)
diff --git a/config/items.xml b/config/items.xml
new file mode 100644 (file)
index 0000000..02d199e
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+
+<item name="Debug"       type="Tool"  maxStackSize="1"   width="1"  height="1"  sprite="assets/items/ITEM_TEST.png" />
+<item name="Dank Maymay" type="Tool"  maxStackSize="420" width="10" height="10" sprite="assets/items/ITEM_TEST.png" />
+<item name="Your Bag"    type="Equip" maxStackSize="1"   width="5"  height="5"  sprite="assets/items/ITEM_TEST.png" />
+<item name="Flashlight"  type="Tool"  maxStackSize="1"   width="4"  height="8"  sprite="assets/items/flashlight_off.png" />
+<item name="Wood Sword"  type="Sword" maxStackSize="1"   width="4"  height="10" sprite="assets/items/SWORD_WOOD.png" />
index 8f5446ca953cda30a74fa4c967be113d124fba14..d17ade4a36db57f7e6657b050361b0aababa3723 100644 (file)
 \r
 #define DEBUG\r
 \r
-/**\r
- * Contains the total number of quests in the game at compile time, see Quest.cpp\r
- * for the actual definition of these quests.\r
- */\r
-\r
-#define TOTAL_QUESTS 1\r
-\r
 /**\r
  * The Quest class.\r
  * \r
index 28fd7e955e932a8c75be8cbbdb332d1e9d4a4dca..f4959d6032ae29042c8b3d8902a74f509c55bcfb 100644 (file)
@@ -220,13 +220,15 @@ public:
 
 class Object : public Entity{
 private:
-       ITEM_ID identifier;
+       std::string iname;
+       //ITEM_ID identifier;
 public:
        char *pickupDialog;
        bool questObject = false;
        
        Object();
-       Object(ITEM_ID id,const char *pd);
+       //Object(ITEM_ID id,const char *pd);
+       Object(std::string in,const char *pd);
        ~Object();
        
        void reloadTexture(void);
index a08954aeef8dccf0e002373293ff5d314201de7c..d3bdd4dc823c2a5eb5a9ce395f84f15bd1139afc 100644 (file)
@@ -6,7 +6,7 @@
 
 #define DEBUG
 
-#define ID                     Item(
+/*#define ID                   Item(
 #define NAME           ,
 #define TYPE           ,
 #define WIDTH          ,
 #define STACKSIZE      ,
 #define TEX            ,
 #define ENI            ),
-#define STOP           )
+#define STOP           )*/
 
 /*
  * A list of all item IDs.
 */
 
+/*#define ITEM_COUNT 5
+
 enum ITEM_ID {
        DEBUG_ITEM = 0,
-       TEST_ITEM = 1,
-       PLAYER_BAG = 2,
-       FLASHLIGHT = 3,
-       SWORD_WOOD = 4
+       TEST_ITEM,
+       PLAYER_BAG,
+       FLASHLIGHT,
+       SWORD_WOOD
 };
 
-enum ITEM_TYPE{
+enum ITEM_TYPE {
        TOOL = 1,
-       SWORD = 2,
-       RANGED = 3,
-       EQUIP = 4,
-       FOOD = 5
-};
+       SWORD,
+       RANGED,
+       EQUIP,
+       FOOD
+};*/
 
 class Item{
 protected:
 public:
-       ITEM_ID id;                             // ID of the item
-       char *name;
-       ITEM_TYPE type;                 // What category the item falls under
+       //ITEM_ID id;                           // ID of the item
+       //ITEM_TYPE type;                       // What category the item falls under
+       
+       //char *name;
+       //char *type;
+       
+       std::string name,type;
+       
        float width;
        float height;
-       int maxStackSize;
-       char* textureLoc;
+       int   maxStackSize;
+       
+       std::string texloc;
        Texturec *tex;
-       GLuint text;
 
-       Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl);
+       //Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl);
        GLuint rtex(){
                return tex->image[0];
        }
 };
 
 struct item_t{
-       int count;
-       ITEM_ID id;
+       uint count;
+       uint/*ITEM_ID*/ id;
 } __attribute__((packed));
 
-typedef struct {
-       unsigned int size;
-       int os;
-       unsigned int sel;
-} __attribute__ ((packed)) InventorySavePacket;
-
 class Inventory {
 private:
+
+       std::vector<item_t> items;
+
        unsigned int size;              // Size of 'item' array
-       item_t *inv;
+       //item_t *inv;
        int os = 0;
 public:
        unsigned int sel;
@@ -83,34 +87,22 @@ public:
        Inventory(unsigned int s);      // Creates an inventory of size 's'
        ~Inventory(void);                       // Free's allocated memory
        
-       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 addItem(std::string name,uint count);
+       int takeItem(std::string name,uint count);
+       
        int useItem(void);
        bool detectCollision(vec2,vec2);
        
        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)
-       
-       char *save(void){
-               static InventorySavePacket *isp = new InventorySavePacket();
-               isp->size = size;
-               isp->os = os;
-               isp->sel = sel;
-               return (char *)isp;
-       }
-       void load(InventorySavePacket *isp){
-               size = isp->size;
-               os = isp->os;
-               sel = isp->sel;
-       }
 };
 
 void initInventorySprites(void);
 void destroyInventory(void);
 
-char *getItemTexturePath(ITEM_ID id);
-int getItemWidth(ITEM_ID);
-int getItemHeight(ITEM_ID);
+const char *getItemTexturePath(std::string name);
+float getItemWidth(std::string name);
+float getItemHeight(std::string name);
 
 #endif // INVENTORY_H
index d7527283542a84a5880c8b4cc8f574ea1775bacf..a0c9a6334a71feb52a02ca06aba10a75106007fc 100644 (file)
@@ -285,7 +285,7 @@ public:
         * upon object interaction.
         */
        
-       void addObject(ITEM_ID id,const char *pickupDialog, float x, float y);
+       void addObject(/*ITEM_ID id*/std::string in,const char *pickupDialog, float x, float y);
        
        /**
         * Adds a particle to the world with the specified coordinates, dimensions,
index 320b87baa42d829432e05006bc227240fbcf0340..4aef26842e2559e00428360ca6e21deeb5d385b2 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -503,8 +503,7 @@ void mainLoop(void){
                debugY = player->loc.y;
        }       
 
-       MENU:
-
+MENU:
        render();       // Call the render loop;
 }
 
@@ -789,7 +788,7 @@ void logic(){
        /*
         *      NPCSelected is used to insure that only one NPC is made interactable with the mouse
         *      if, for example, multiple entities are occupying one space.
-       */
+        */
 
        static bool NPCSelected = false;
 
@@ -802,7 +801,8 @@ void logic(){
        /*
         *      Run the world's detect function. This handles the physics of the player and any entities
         *      that exist in this world.
-       */
+        */
+       
        currentWorld->detect(player);
        if(player->loc.y<.02)gameRunning=false;
 
@@ -810,20 +810,23 @@ void logic(){
         *      Entity logic: This loop finds every entity that is alive and in the current world. It then
         *      basically runs their AI functions depending on what type of entity they are. For NPCs,
         *      click detection is done as well for NPC/player interaction.
-        *
-       */
+        */
+        
        for(auto &n : currentWorld->npc){
                if(n->alive){
+                       
                        /*
                         *      Make the NPC 'wander' about the world if they're allowed to do so.
                         *      Entity->canMove is modified when a player interacts with an NPC so
                         *      that the NPC doesn't move when it talks to the player.
-                        *
-                       */
+                        */
 
-                       if(n->canMove) n->wander((rand() % 120 + 30));
-                       if(!player->inv->usingi) n->hit = false;
-                       if(player->inv->usingi && !n->hit && player->inv->detectCollision(vec2{n->loc.x, n->loc.y},vec2{n->loc.x+n->width,n->loc.y+n->height})){
+                       if(n->canMove)
+                               n->wander((rand() % 120 + 30));
+                       
+                       /*if(!player->inv->usingi) n->hit = false;
+                       
+                       if(player->inv->usingi && !n->hit && player->inv->detectCollision((vec2){n->loc.x, n->loc.y},(vec2){n->loc.x+n->width,n->loc.y+n->height})){
                                n->health -= 25;
                                n->hit = true;
                                for(int r = 0; r < (rand()%5);r++)
@@ -832,10 +835,11 @@ void logic(){
                                        for(int r = 0; r < (rand()%30)+15;r++)
                                                currentWorld->addParticle(rand()%HLINE*3 + n->loc.x - .05f,n->loc.y + n->height*.5, HLINE,HLINE, -(rand()%10)*.01,((rand()%10)*.01-.05), {(rand()%75)+10/100.0f,0,0}, 10000);
                                }
-                       }
+                       }*/
+                       
                        /*
                         *      Don't bother handling the NPC if another has already been handled.
-                       */
+                        */
 
                        if(NPCSelected){
                                n->near=false;
@@ -844,7 +848,7 @@ void logic(){
 
                        /*
                         *      Check if the NPC is under the mouse.
-                       */
+                        */
 
                        if(ui::mouse.x >= n->loc.x                              &&
                           ui::mouse.x <= n->loc.x + n->width   &&
@@ -856,15 +860,15 @@ void logic(){
                                 *      considered legal. In other words, require the player to be close to
                                 *      the NPC in order to interact with it.
                                 *
-                                *      This uses the Pythagorean theorem to check for NPCs within a certain                     *
-                               */
+                                *      This uses the Pythagorean theorem to check for NPCs within a certain
+                                */
 
                                if(pow((n->loc.x - player->loc.x),2) + pow((n->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
 
                                        /*
                                         *      Set Entity->near so that this NPC's name is drawn under them, and toggle NPCSelected
                                         *      so this NPC is the only one that's clickable.
-                                       */
+                                        */
 
                                        n->near=true;
                                        NPCSelected=true;
@@ -872,7 +876,7 @@ void logic(){
                                        /*
                                         *      Check for a right click, and allow the NPC to interact with the
                                         *      player if one was made.
-                                       */
+                                        */
 
                                        if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
 
@@ -884,17 +888,18 @@ void logic(){
 
                                /*
                                 *      Hide the NPC's name if the mouse isn't on the NPC.
-                               */
+                                */
 
                        }else n->near=false;
                }
        }
+       
        for(auto &m : currentWorld->mob){
                if(m->alive){
 
                        /*
                         *      Run the Mob's AI function.
-                       */
+                        */
 
                        switch(m->subtype){
                        case MS_RABBIT:
@@ -913,6 +918,7 @@ void logic(){
                        }
                }
        }
+       
        if(!objectInteracting){
                for(auto &o : currentWorld->object){
                        if(o->alive){
index 0905a8745e2fcf538aa61ffb7ec8a605f6270d5a..4328dc528017389dd89968ed27dd5b8d599ba05e 100644 (file)
@@ -1,14 +1,7 @@
 #include <Quest.h>\r
 \r
-#define TITLE  Quest(\r
-#define DESC   ,\r
-#define REWARD ,(struct item_t){\r
-#define x              ,\r
-#define END            }),\r
-\r
-const Quest QuestList[TOTAL_QUESTS]={\r
-// Get quest list\r
-#include "../config/quest_list.txt"\r
+const Quest QuestList[1] = {\r
+       Quest("Not a quest","Stop",(struct item_t){0,0})\r
 };\r
 \r
 \r
@@ -27,7 +20,7 @@ Quest::~Quest(){
 }\r
 \r
 int QuestHandler::assign(const char *t){\r
-       unsigned char i;\r
+       /*unsigned char i;\r
        for(i=0;i<current.size();i++){                          // Make sure we don't already have this quest\r
                if(!strcmp(current[i]->title,t)){\r
 #ifdef DEBUG\r
@@ -36,7 +29,7 @@ int QuestHandler::assign(const char *t){
                        return -2;\r
                }\r
        }\r
-       for(i=0;i<TOTAL_QUESTS;i++){                            // Add the quest (if it really exists)\r
+       for(i=0;i<0;i++){                               // Add the quest (if it really exists)\r
                if(!strcmp(QuestList[i].title,t)){\r
                        current.push_back(&QuestList[i]);\r
 #ifdef DEBUG\r
@@ -50,23 +43,23 @@ int QuestHandler::assign(const char *t){
        }\r
 #ifdef DEBUG\r
        DEBUG_printf("Quest %s does not exist.\n",t);\r
-#endif // DEBUG\r
-       return -1;\r
+#endif // DEBUG*/\r
+       return strcmp(t,"h");\r
 }\r
 \r
 int QuestHandler::drop(const char *t){\r
-       unsigned char i;\r
+       /*unsigned char i;\r
        for(i=0;i<current.size();i++){\r
                if(!strcmp(current[i]->title,t)){\r
                        current.erase(current.begin()+i);\r
                        return current.size();\r
                }\r
-       }\r
-       return -1;\r
+       }*/\r
+       return strcmp(t,"h");\r
 }\r
 \r
 int QuestHandler::finish(const char *t,void *completer){\r
-       unsigned char i;\r
+       /*unsigned char i;\r
        for(i=0;i<current.size();i++){\r
                if(!strcmp(current[i]->title,t)){\r
 #ifdef DEBUG\r
@@ -82,8 +75,8 @@ int QuestHandler::finish(const char *t,void *completer){
        }\r
 #ifdef DEBUG\r
        DEBUG_printf("QuestHandler never had quest %s.\n",t);\r
-#endif // DEBUG\r
-       return -1;\r
+#endif // DEBUG*/\r
+       return strncmp(t,(char *)completer,1);\r
 }\r
 \r
 bool QuestHandler::hasQuest(const char *t){\r
index 4a8e6b76850674dea585aee2766e2d537c0f7af9..4c1d32629a73002e4b8c0208b6ae25e937c41865 100644 (file)
@@ -214,8 +214,9 @@ Object::Object(){
        inv = NULL;
 }
 
-Object::Object(ITEM_ID id, const char *pd){
-       identifier = id;
+Object::Object(/*ITEM_ID id*/std::string in, const char *pd){
+       //identifier = id;
+       iname = in;
 
        if(pd){
                pickupDialog = new char[strlen(pd)+1];
@@ -230,11 +231,11 @@ Object::Object(ITEM_ID id, const char *pd){
        type = OBJECTT;
        alive = true;
        near = false;
-       width  = getItemWidth(id);
-       height = getItemHeight(id);
+       width  = getItemWidth(in);
+       height = getItemHeight(in);
 
        maxHealth = health = 1;
-       tex = new Texturec(1,getItemTexturePath(id));
+       tex = new Texturec(1,getItemTexturePath(in));
        inv = NULL;
 }
 Object::~Object(){
@@ -247,9 +248,9 @@ void Object::reloadTexture(void){
        if(tex)
                delete tex;
                
-       tex = new Texturec(1,getItemTexturePath(identifier));
-       width  = getItemWidth(identifier);
-       height = getItemHeight(identifier);
+       tex = new Texturec(1,getItemTexturePath(iname));
+       width  = getItemWidth(iname);
+       height = getItemHeight(iname);
 }
 
 void Entity::draw(void){               //draws the entities
@@ -449,12 +450,12 @@ void Object::interact(void){
                ui::dialogBox(player->name,":Yes:No",false,pickupDialog);               
                ui::waitForDialog();
                if(ui::dialogOptChosen == 1){
-                       player->inv->addItem((ITEM_ID)(identifier), (char)1);
+                       player->inv->addItem(/*(ITEM_ID)(identifier)*/iname, 1);
                        alive = false;
                }
        }else{
                alive = false;
-               player->inv->addItem((ITEM_ID)(identifier), (char)1);
+               player->inv->addItem(iname, 1);
        }
 }
 
index 7c238b4bdb11b185c2a32bca387bfea8d57a1926..8e68783fe91bd316263a79a9f76d824ad500378b 100644 (file)
@@ -17,7 +17,7 @@ extern std::vector<menuItem>optionsMenu;
 extern void mainLoop(void);
 
 void segFault(){
-       ((vec2 *)currentWorld + 2934)[10].x = *((unsigned int *)&currentXML) * *((int *)NULL);
+       (*((int *)NULL))++;
 }
 
 
@@ -26,7 +26,7 @@ typedef struct {
        unsigned int index;
 } NPCDialog;
 
-std::vector<XMLElement *>              dopt;
+std::vector<XMLElement *> dopt;
 
 int commonAIFunc(NPC *speaker){
        XMLDocument xml;
@@ -66,7 +66,7 @@ int commonAIFunc(NPC *speaker){
                                
                                if((oxml = exml->FirstChildElement("give"))){
                                        while(oxml){
-                                               player->inv->addItem((ITEM_ID)oxml->UnsignedAttribute("id"),oxml->UnsignedAttribute("count"));
+                                               player->inv->addItem(oxml->Attribute("id"),oxml->UnsignedAttribute("count"));
                                                oxml = oxml->NextSiblingElement();
                                        }
                                }
@@ -77,7 +77,7 @@ int commonAIFunc(NPC *speaker){
                                
                                if((oxml = exml->FirstChildElement("take"))){
                                        while(oxml){
-                                               player->inv->takeItem((ITEM_ID)oxml->UnsignedAttribute("id"),oxml->UnsignedAttribute("count"));
+                                               player->inv->takeItem(oxml->Attribute("id"),oxml->UnsignedAttribute("count"));
                                                oxml = oxml->NextSiblingElement();
                                        }
                                }
@@ -128,7 +128,7 @@ int commonAIFunc(NPC *speaker){
                                        /*
                                         * No options - simply print the text.
                                         */
-                                       
+
                                        ui::dialogBox(speaker->name,"",false,exml->GetText());
                                        ui::waitForDialog();
                                }
index 108051c10cd0ff891c51c7662069e5723a11cc24..4d948316076e4594e2bb95e58975b943cb85d7c3 100644 (file)
@@ -2,27 +2,89 @@
 #include <entities.h>
 #include <ui.h>
 
-#define ITEM_COUNT 5   // Total number of items that actually exist
+#include <tinyxml2.h>
+using namespace tinyxml2;
 
 extern Player *player;
 extern GLuint invUI;
 static float hangle = 0.0f;
 static bool swing = false;
-static float xc,yc;
+//static float xc,yc;
 static vec2 itemLoc;
 Mix_Chunk* swordSwing;
 
-static const Item item[ITEM_COUNT]= {
+std::vector<Item *> itemMap;
+
+void items(void){
+       XMLDocument xml;
+       XMLElement *exml;
+       xml.LoadFile("config/items.xml");
+       exml = xml.FirstChildElement("item");
+       while(exml){
+               
+               itemMap.push_back(new Item());
+               itemMap.back()->width  = exml->FloatAttribute("width") * HLINE;
+               itemMap.back()->height = exml->FloatAttribute("height") * HLINE;
+               itemMap.back()->maxStackSize = exml->UnsignedAttribute("maxstack");
+               
+               itemMap.back()->name = exml->Attribute("name");
+               itemMap.back()->type = exml->Attribute("type");
+               itemMap.back()->texloc = exml->Attribute("sprite");
+
+               exml = exml->NextSiblingElement();
+       }
+}
+
+int Inventory::addItem(std::string name,uint count){
+       for(unsigned int i=0;i<itemMap.size();i++){
+               if(itemMap[i]->name == name){
+                       for(auto &in : items){
+                               if(in.id == i){
+                                       in.count += count;
+                                       return 0;
+                               }
+                       }
+                       items.push_back((item_t){i,count});
+                       return 0;
+               }
+       }
+       return -1;
+}
+
+int Inventory::takeItem(std::string name,uint count){
+       unsigned int id = 999999;
+       for(unsigned int i=0;i<itemMap.size();i++){
+               if(itemMap[i]->name == name){
+                       id = i;
+                       break;
+               }
+       }
+       for(unsigned int i=0;i<items.size();i++){
+               if(items[i].id == id){
+                       if(count > items[i].count)
+                               items.erase(items.begin()+i);
+                       else 
+                               items[i].count -= count;
+                       return 0;
+               }
+       }
+       return -1;
+}
+
+/*static const Item item[ITEM_COUNT]= {
        #include "../config/items.h"
-};
+};*/
 
-static GLuint itemtex[ITEM_COUNT];
-void itemDraw(Player *p,ITEM_ID id, ITEM_TYPE type);
+static GLuint *itemtex;//[ITEM_COUNT];
+void itemDraw(Player *p,uint id);
 
 void initInventorySprites(void){
-       unsigned int i;
-       for(i = 0;i < ITEM_COUNT;i++){
-               itemtex[i] = Texture::loadTexture(getItemTexturePath((ITEM_ID)i));
+       
+       items();
+       itemtex = new GLuint[itemMap.size()];
+       
+       for(unsigned int i = 0;i<itemMap.size();i++){
+               itemtex[i] = Texture::loadTexture(getItemTexturePath(itemMap[i]->name));
        }
 
        swordSwing = Mix_LoadWAV("assets/sounds/shortSwing.wav");
@@ -33,19 +95,43 @@ void destroyInventory(void){
        Mix_FreeChunk(swordSwing);
 }
 
-char *getItemTexturePath(ITEM_ID id){
+const char *getItemTexturePath(std::string name){
+       for(auto &i : itemMap){
+               if(i->name == name)
+                       return i->texloc.c_str();
+       }
+       return NULL;
+}
+
+/*char *getItemTexturePath(ITEM_ID id){
        return item[id].textureLoc;
+}*/
+
+float getItemWidth(std::string name){
+       for(auto &i : itemMap){
+               if(i->name == name)
+                       return i->width;
+       }
+       return 0;
 }
 
-int getItemWidth(ITEM_ID id){
+/*int getItemWidth(ITEM_ID id){
        return item[id].width;
+}*/
+
+float getItemHeight(std::string name){
+       for(auto &i : itemMap){
+               if(i->name == name)
+                       return i->height;
+       }
+       return 0;
 }
 
-int getItemHeight(ITEM_ID id){
+/*int getItemHeight(ITEM_ID id){
        return item[id].height;
-}
+}*/
 
-Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl){
+/*Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl){
        id = i;
        type = t;
        width = w;
@@ -59,24 +145,24 @@ Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const
        strcpy(textureLoc,tl);
 
        //tex= new Texturec(1,textureLoc);
-}
+}*/
 
 Inventory::Inventory(unsigned int s){
        sel=0;
        size=s;
-       inv = new struct item_t[size];
-       memset(inv,0,size*sizeof(struct item_t));
+       //inv = new struct item_t[size];
+       //memset(inv,0,size*sizeof(struct item_t));
 }
 
 Inventory::~Inventory(void){
-       delete[] inv;
+       //delete[] inv;
 }
 
 void Inventory::setSelection(unsigned int s){
        sel=s;
 }
 
-int Inventory::addItem(ITEM_ID id,unsigned char count){
+/*int Inventory::addItem(ITEM_ID id,unsigned char count){
        //std::cout << id << "," << inv[os].id << std::endl;
        
        for(unsigned int i = 0; i < size; i++){
@@ -94,9 +180,9 @@ int Inventory::addItem(ITEM_ID id,unsigned char count){
 #endif // DEBUG
 
        return 0;
-}
+}*/
 
-int Inventory::takeItem(ITEM_ID id,unsigned char count){
+/*int Inventory::takeItem(ITEM_ID id,unsigned char count){
        for(unsigned int i = 0;i < size;i++){
                if(inv[i].id == id){
 #ifdef DEBUG
@@ -107,7 +193,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
                }
        }
        return -1;
-}
+}*/
 
 void Inventory::draw(void){
        static unsigned int lop = 0;
@@ -122,72 +208,83 @@ void Inventory::draw(void){
        unsigned int a = 0;
        unsigned int end = 0;
        static vec2 mouseStart = {0,0};
+       
        for(auto &r : iray){
                r.start.x = player->loc.x + (player->width/2);
                r.start.y = player->loc.y + (player->height/2);
-               curCoord[a] = r.start;
+               curCoord[a++] = r.start;
                //dfp[a] = 0;
-               a++;
+               //a++;
        }a=0;
+       
        if(invOpening){
-               end = 0;
+               //end = 0;
+               
                for(auto &d : dfp){
-                       if(a != 0){
-                               if(dfp[a-1]>50)d+=1.65*deltaTime;
-                       }else{
-                               d += 1.65*deltaTime;
-                       }
+                       if(!a || dfp[a - 1] > 50)
+                               d += 1.65 * deltaTime;
                        if(d >= range)
                                d = range;
                        a++;
                }a=0;
-               if(end < numSlot)invOpen=true;
-       }else if(!invOpening){
+               
+               // if(end < numSlot)
+               if(numSlot > 0)invOpen=true;
+       }else{
                for(auto &d : dfp){
                        if(d > 0){
-                               d-=1.65*deltaTime;
+                               d -= 1.65 * deltaTime;
                        }else end++;
                }
-               if(end >= numSlot)invOpen=false;
+               if(end >= numSlot)
+                       invOpen = false;
        }
+       
+       /*
+        *      a = 0
+        */
+       
        if(invOpen){
+               
                for(auto &r : iray){
-                       angle=180-(angleB*a) - angleB/2.0f;
+                       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?range:1))*0.5f);
                        glBegin(GL_QUADS);
-                               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);
+                               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){
+                       if(!items.empty() && a < items.size() && items[a].count){
                                glEnable(GL_TEXTURE_2D);
-                               glBindTexture(GL_TEXTURE_2D, itemtex[inv[a].id]);                       
+                               glBindTexture(GL_TEXTURE_2D, itemtex[items[a].id/*inv[a].id*/]);
                                glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)(range?range:1))*0.8f);
-                               glBegin(GL_QUADS);
-                                       if(item[inv[a].id].height > item[inv[a].id].width){
-                                               glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)),       r.end.y-(itemWide/2));
-                                               glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)),       r.end.y-(itemWide/2));
-                                               glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)),       r.end.y+(itemWide/2));
-                                               glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)),       r.end.y+(itemWide/2));
+                               glBegin(GL_QUADS);
+                                       if(itemMap[items[a].id]->height > itemMap[items[a].id]->width){//item[inv[a].id].width){
+                                               glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),   r.end.y-(itemWide/2));
+                                               glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),   r.end.y-(itemWide/2));
+                                               glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),   r.end.y+(itemWide/2));
+                                               glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),   r.end.y+(itemWide/2));
                                        }else{
-                                               glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),      r.end.y-(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
-                                               glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),      r.end.y-(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
-                                               glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),      r.end.y+(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
-                                               glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),      r.end.y+(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
+                                               glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+                                               glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+                                               glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+                                               glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
                                        }
                                glEnd();
                                glDisable(GL_TEXTURE_2D);
-                               ui::putText(r.end.x-(itemWide/2),r.end.y-(itemWide*.9),"%s",item[inv[a].id].name);
-                               ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",inv[a].count);
+                               ui::putText(r.end.x-(itemWide/2),r.end.y-(itemWide*.9),"%s",itemMap[items[a].id]->name);
+                               ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",items[a].count);
                        }
+
                        a++;
-                       if(sel==a){
+                       
+                       if(sel == a){
                                glBegin(GL_LINES);
                                        glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
                                        glVertex2i(r.start.x,r.start.y);
@@ -200,6 +297,8 @@ void Inventory::draw(void){
                static unsigned int highlight = 0;
                static unsigned int thing = 0;
 
+               std::cout<<"Inventory2???"<<std::endl;
+
                if(!mouseSel){
                        mouseStart.x = ui::mouse.x - offset.x;
                        highlight = sel;
@@ -243,41 +342,43 @@ void Inventory::draw(void){
                                glVertex2i(r.end.x-(itemWide/2),        r.end.y+(itemWide/2));
                        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, a == highlight ? 0.8f : 0.2f);
-                               glBegin(GL_QUADS);
-                                       if(item[inv[a].id].height > item[inv[a].id].width){
-                                               glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)),       r.end.y-(itemWide/2));
-                                               glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)),       r.end.y-(itemWide/2));
-                                               glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)),       r.end.y+(itemWide/2));
-                                               glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)),       r.end.y+(itemWide/2));
-                                       }else{
-                                               glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),      r.end.y-(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
-                                               glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),      r.end.y-(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
-                                               glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),      r.end.y+(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
-                                               glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),      r.end.y+(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
-                                       }
-                               glEnd();
-                               glDisable(GL_TEXTURE_2D);
-                               //ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/1.75),"%d",inv[a].count);
-                       }
+                       glEnable(GL_TEXTURE_2D);
+                       glBindTexture(GL_TEXTURE_2D, itemtex[items[a].id]);
+                       glColor4f(1.0f, 1.0f, 1.0f, a == highlight ? 0.8f : 0.2f);
+                       glBegin(GL_QUADS);
+                               if(itemMap[items[a].id]->height > itemMap[items[a].id]->width){
+                                       glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y-(itemWide/2));
+                                       glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y-(itemWide/2));
+                                       glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y+(itemWide/2));
+                                       glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y+(itemWide/2));
+                               }else{
+                                       glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+                                       glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+                                       glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+                                       glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+                               }
+                       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++;
                }
-               if(inv[highlight].count > 0)ui::putStringCentered(player->loc.x+player->width/2, player->loc.y + range*.75,item[inv[highlight].id].name);
+               ui::putStringCentered(player->loc.x+player->width/2, player->loc.y + range*.75,itemMap[items[highlight].id]->name.c_str());
        }
-       if(inv[sel].count)itemDraw(player,inv[sel].id,item[inv[sel].id].type);
+       
+       if(!items.empty() && items[sel].count)
+               itemDraw(player,items[sel].id);
        lop++;
 }
 
-void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
+void itemDraw(Player *p,uint id){
        itemLoc.y = p->loc.y+(p->height/3);
        itemLoc.x = p->left?p->loc.x:p->loc.x+p->width;
        glPushMatrix();
+       
        if(!id)return;
-       switch(type){
-       case SWORD:
+       
+       if(itemMap[id]->type == "Sword"){
                if(p->left){
                        if(hangle < 15){
                                hangle=15.0f;
@@ -291,10 +392,8 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
                                //swing=false;
                        }
                }
-               break;
-       default:
-               hangle = 0.0f;
-       }
+       }else hangle = 0.0f;
+       
        glUseProgram(shaderProgram);
        glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
        glTranslatef(itemLoc.x,itemLoc.y,0);
@@ -304,10 +403,10 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
        glBindTexture(GL_TEXTURE_2D,itemtex[id]);
        glColor4ub(255,255,255,255);
        glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2f(itemLoc.x,                           itemLoc.y);
-               glTexCoord2i(1,1);glVertex2f(itemLoc.x+item[id].width,itemLoc.y);
-               glTexCoord2i(1,0);glVertex2f(itemLoc.x+item[id].width,itemLoc.y+item[id].height);
-               glTexCoord2i(0,0);glVertex2f(itemLoc.x,                           itemLoc.y+item[id].height);
+               glTexCoord2i(0,1);glVertex2f(itemLoc.x,                                   itemLoc.y);
+               glTexCoord2i(1,1);glVertex2f(itemLoc.x+itemMap[id]->width,itemLoc.y);
+               glTexCoord2i(1,0);glVertex2f(itemLoc.x+itemMap[id]->width,itemLoc.y+itemMap[id]->height);
+               glTexCoord2i(0,0);glVertex2f(itemLoc.x,                                   itemLoc.y+itemMap[id]->height);
        glEnd();
        glDisable(GL_TEXTURE_2D);
        glTranslatef(player->loc.x*2,0,0);
@@ -317,10 +416,11 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
 
 int Inventory::useItem(void){
        static bool up = false;
-       ITEM_TYPE type = item[inv[sel].id].type;
+       //ITEM_TYPE type = item[inv[sel].id].type;
        if(!invHover){
-               switch(type){
-               case SWORD:
+               
+               if(itemMap[items[sel].id]->type == "Sword"){
+               
                        if(swing){
                                if(!player->left){
                                        if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);}
@@ -345,28 +445,30 @@ int Inventory::useItem(void){
                                swing=true;
                                Mix_PlayChannel(2,swordSwing,0);
                        }
-                       break;
-               default:
                        //hangle++;
-                       break;
+                       //break;
                }
        }
        return 0;
 }
 
 bool Inventory::detectCollision(vec2 one, vec2 two){
-       float i = 0.0f;
-       if(item[inv[sel].id].type == SWORD){
-               while(i<item[inv[sel].id].height){
+       //float i = 0.0f;
+       
+       /*if(items.empty() || !items[sel].count)
+               return false;
+       if(itemMap[items[sel].id]->type == "Sword"){
+               std::cout<<"Collision???"<<std::endl;
+               while(i<itemMap[items[sel].id]->height){
                        xc = itemLoc.x; yc = itemLoc.y;
                        xc += float(i) * cos((hangle+90)*PI/180);
                        yc += float(i) * sin((hangle+90)*PI/180);
 
-                       /*glColor4f(1.0f,1.0f,1.0f,1.0f);
+                       *glColor4f(1.0f,1.0f,1.0f,1.0f);
                        glBegin(GL_LINES);
                                glVertex2f(player->loc.x,player->loc.y+player->height/3);
                                glVertex2f(xc,yc);
-                       glEnd();*/
+                       glEnd();*
 
                        if(xc >= one.x && xc <= two.x){
                                if(yc >= one.y && yc <= two.y){
@@ -376,7 +478,7 @@ bool Inventory::detectCollision(vec2 one, vec2 two){
 
                        i+=HLINE;
                }
-       }
-       return false;
+       }*/
+       return !(one.x == two.y);
 }
 
index 1520e9f02feee07e10afa786e4fc2709020ccd9c..28b8314767bb2b91e41b9232bd095525ec67ca31 100644 (file)
@@ -806,6 +806,7 @@ DONE:
                        setFontSize(16);
                        toggleBlack();
                }
+
                dialogBoxExists = false;
        }
        void handleEvents(void){
@@ -828,12 +829,10 @@ DONE:
                                premouse.y=e.motion.y;
                                break;
                        case SDL_MOUSEBUTTONDOWN:
-                               if((e.button.button&SDL_BUTTON_RIGHT)&&dialogBoxExists){
+                               if((e.button.button & SDL_BUTTON_RIGHT) && dialogBoxExists)
                                        dialogAdvance();
-                               }
-                               if((e.button.button&SDL_BUTTON_LEFT)&&!dialogBoxExists){
+                               if((e.button.button & SDL_BUTTON_LEFT) && !dialogBoxExists)
                                        player->inv->usingi = true;
-                               }
                                break;
                        /*
                                KEYDOWN
index c8b4bde069c6dc388f69087190677760fd9fd234..df0f0ac15593ba8e9f583b866bb2c735f48a34bc 100644 (file)
@@ -284,9 +284,9 @@ void World::update(Player *p,unsigned int delta){
        
        p->loc.y += p->vel.y                     * delta;
        p->loc.x +=(p->vel.x * p->speed) * delta;
-       if(p->inv->usingi){
+       /*if(p->inv->usingi){
                p->inv->useItem();
-       }
+       }*/
 
        /*
         *      Update coordinates of all entities except for structures.
@@ -1001,8 +1001,8 @@ void World::addNPC(float x,float y){
        entity.push_back(npc.back());
 }
 
-void World::addObject(ITEM_ID i,const char *p, float x, float y){
-       object.push_back(new Object(i,p));
+void World::addObject(/*ITEM_ID i*/std::string in,const char *p, float x, float y){
+       object.push_back(new Object(in,p));
        object.back()->spawn(x,y);
 
        entity.push_back(object.back());
index 7911bfd135a95c408d0b44a8769b1102276783ef..6fe220cedb0896cb2417b50225bfa754547ed6b1 100644 (file)
@@ -38,6 +38,6 @@
        
        <text id="1" >
                My name's Johnny.
-               <give id="0" count="1" />
+               <give id="Dank Maymay" count="1" />
        </text>
 </Dialog>