diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-02-02 08:49:38 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-02-02 08:49:38 -0500 |
commit | d83b7f3d1f50ee1b164095c0e9d94cc87a44ad8c (patch) | |
tree | d7b76cb1907f781e1eccd1691bc7a622ed27a63c /src | |
parent | 32855b564c2a7cd5c1a644dcf7039ab9b69295e4 (diff) |
inventory rewrite
Diffstat (limited to 'src')
-rw-r--r-- | src/Quest.cpp | 31 | ||||
-rw-r--r-- | src/entities.cpp | 21 | ||||
-rw-r--r-- | src/gameplay.cpp | 10 | ||||
-rw-r--r-- | src/inventory.cpp | 302 | ||||
-rw-r--r-- | src/ui.cpp | 7 | ||||
-rw-r--r-- | src/world.cpp | 8 |
6 files changed, 237 insertions, 142 deletions
diff --git a/src/Quest.cpp b/src/Quest.cpp index 0905a87..4328dc5 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -1,14 +1,7 @@ #include <Quest.h>
-#define TITLE Quest(
-#define DESC ,
-#define REWARD ,(struct item_t){
-#define x ,
-#define END }),
-
-const Quest QuestList[TOTAL_QUESTS]={
-// Get quest list
-#include "../config/quest_list.txt"
+const Quest QuestList[1] = {
+ Quest("Not a quest","Stop",(struct item_t){0,0})
};
@@ -27,7 +20,7 @@ Quest::~Quest(){ }
int QuestHandler::assign(const char *t){
- unsigned char i;
+ /*unsigned char i;
for(i=0;i<current.size();i++){ // Make sure we don't already have this quest
if(!strcmp(current[i]->title,t)){
#ifdef DEBUG
@@ -36,7 +29,7 @@ int QuestHandler::assign(const char *t){ return -2;
}
}
- for(i=0;i<TOTAL_QUESTS;i++){ // Add the quest (if it really exists)
+ for(i=0;i<0;i++){ // Add the quest (if it really exists)
if(!strcmp(QuestList[i].title,t)){
current.push_back(&QuestList[i]);
#ifdef DEBUG
@@ -50,23 +43,23 @@ int QuestHandler::assign(const char *t){ }
#ifdef DEBUG
DEBUG_printf("Quest %s does not exist.\n",t);
-#endif // DEBUG
- return -1;
+#endif // DEBUG*/
+ return strcmp(t,"h");
}
int QuestHandler::drop(const char *t){
- unsigned char i;
+ /*unsigned char i;
for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
current.erase(current.begin()+i);
return current.size();
}
- }
- return -1;
+ }*/
+ return strcmp(t,"h");
}
int QuestHandler::finish(const char *t,void *completer){
- unsigned char i;
+ /*unsigned char i;
for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
#ifdef DEBUG
@@ -82,8 +75,8 @@ int QuestHandler::finish(const char *t,void *completer){ }
#ifdef DEBUG
DEBUG_printf("QuestHandler never had quest %s.\n",t);
-#endif // DEBUG
- return -1;
+#endif // DEBUG*/
+ return strncmp(t,(char *)completer,1);
}
bool QuestHandler::hasQuest(const char *t){
diff --git a/src/entities.cpp b/src/entities.cpp index 4a8e6b7..4c1d326 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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); } } diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 7c238b4..8e68783 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -17,7 +17,7 @@ extern std::vector<menuItem>optionsMenu; extern void mainLoop(void); void segFault(){ - ((vec2 *)currentWorld + 2934)[10].x = *((unsigned int *)¤tXML) * *((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(); } diff --git a/src/inventory.cpp b/src/inventory.cpp index 108051c..4d94831 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -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); } @@ -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 diff --git a/src/world.cpp b/src/world.cpp index c8b4bde..df0f0ac 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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()); |