diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2015-11-20 08:47:34 -0500 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2015-11-20 08:47:34 -0500 |
commit | 0a30bd1b2e2f02b6f34225d8976f645c99b53b7e (patch) | |
tree | 16a47672bf5f5bc65efb245b2e9d84a08c1ce2a6 /src | |
parent | 20b29fccb6da62d5a07a02477fabac3a80d350dd (diff) |
Started inv ui, new item system
Diffstat (limited to 'src')
-rw-r--r-- | src/Quest.cpp | 2 | ||||
-rw-r--r-- | src/entities.cpp | 34 | ||||
-rw-r--r-- | src/gameplay.cpp | 34 | ||||
-rw-r--r-- | src/inventory.cpp | 66 | ||||
-rw-r--r-- | src/ui.cpp | 5 | ||||
-rw-r--r-- | src/world.cpp | 7 |
6 files changed, 107 insertions, 41 deletions
diff --git a/src/Quest.cpp b/src/Quest.cpp index a361418..5fd7726 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -85,7 +85,7 @@ int QuestHandler::finish(const char *t,void *completer){ #ifdef DEBUG
DEBUG_printf("Completing quest %s.\n",t);
#endif // DEBUG
- ((Entity *)completer)->inv->addItem(current[i]->reward.id,current[i]->reward.count);
+ ((Entity *)completer)->inv->addItem(current[i]->reward.itmid,current[i]->reward.count);
current.erase(current.begin()+i);
#ifdef DEBUG
DEBUG_printf("QuestHandler now has %u active quests.\n",current.size());
diff --git a/src/entities.cpp b/src/entities.cpp index a8e9bfb..e979e33 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -8,6 +8,8 @@ extern World *currentWorld; extern Player *player; +extern const char *itemName; + void Entity::spawn(float x, float y){ //spawns the entity you pass to it based off of coords and global entity settings loc.x = x; loc.y = y; @@ -91,7 +93,21 @@ Mob::Mob(int sub){ inv = new Inventory(NPC_INV_SIZE); } -Object::Object(int id):ID(id){ +Object::Object(int id):identifier(id){ + type = OBJECTT; + alive = true; + near = false; + width = HLINE * 8; + height = HLINE * 8; + + maxHealth = health = 1; + tex = new Texturec(1, "assets/items/ITEM_SWORD.png"); + + questObject = false; + pickupDialog="\0"; +} + +Object::Object(int id, bool qo, char *pd):identifier(id),questObject(qo),pickupDialog(pd){ type = OBJECTT; alive = true; near = false; @@ -175,8 +191,6 @@ void Entity::draw(void){ //draws the entities default: break; } - }else if(type == OBJECTT){ - tex->bind(0); }else{ tex->bind(0); } @@ -294,9 +308,19 @@ void NPC::interact(){ //have the npc's interact back to the player } } +extern void waitForDialog(void); void Object::interact(){ - this->alive = false; - player->inv->addItem((ITEM_ID)(ID), (char)1); + if(questObject){ + char opt[]=":No:Yes"; + ui::dialogBox("You",opt,pickupDialog); + if(ui::dialogOptChosen == 1){ + this->alive = false; + player->inv->addItem((ITEM_ID)(identifier), (char)1); + } + }else{ + this->alive = false; + player->inv->addItem((ITEM_ID)(identifier), (char)1); + } } /* diff --git a/src/gameplay.cpp b/src/gameplay.cpp index fcc501c..18bf327 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -6,6 +6,35 @@ extern World *currentWorld; extern Player *player; extern void mainLoop(void); +extern SDL_Window *window; +extern bool fadeEnable; + +void story(void){ + for(int i=0;i<600;i++){ + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glEnable(GL_STENCIL_TEST); + glPushMatrix(); + + glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT ); + glClear(GL_COLOR_BUFFER_BIT); + + glColor4f(0.0f,0.0f,0.0f,0.0f); + glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT); + glColor4f(1.0f,1.0f,1.0f,1.0f); + ui::importantText("Oh hello, where are you?"); + //ui::setFontSize(16); + //ui::putText(54,540,"BITC."); + + glPopMatrix(); + SDL_GL_SwapWindow(window); + } +} void waitForDialog(void){ do{ @@ -110,12 +139,11 @@ void initEverything(void){ test->addMob(MS_RABBIT,200,100); test->addMob(MS_BIRD,-500,500); - currentWorld->addObject(2, 500,200); - + currentWorld->addObject(SWORD_WOOD, 500,200); + currentWorld->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200); /* * Link all the entities that were just created to the initial world, and setup a test AI function. */ currentWorld->npc[0]->addAIFunc(giveTestQuest,false); - } diff --git a/src/inventory.cpp b/src/inventory.cpp index 217fd18..edc88ff 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -2,21 +2,10 @@ #include <entities.h> #include <ui.h> -#define ITEM_COUNT 2 // Total number of items that actually exist +#define ITEM_COUNT 5 // Total number of items that actually exist extern Player *player; - -const char *itemName[]={ - "\0", - "Dank Maymay", - "Sword" -}; - -const char *ITEM_SPRITE[]={ - "\0", // Null - "assets/items/ITEM_TEST.png", // Dank maymay - "assets/items/ITEM_SWORD.png" -}; +extern GLuint invUI; GLuint *ITEM_TEX; @@ -26,7 +15,7 @@ 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_SPRITE[i+1])))loadCount++; + if((ITEM_TEX[i]=Texture::loadTexture(item[i].textureLoc)))loadCount++; } #ifdef DEBUG DEBUG_printf("Loaded %u/%u item texture(s).\n",loadCount,ITEM_COUNT); @@ -37,7 +26,7 @@ unsigned int initInventorySprites(void){ Inventory::Inventory(unsigned int s){ sel=0; size=s; - item=(struct item_t *)calloc(size,sizeof(struct item_t)); + //item=(struct item_t *)calloc(size,sizeof(struct item_t)); tossd=false; } @@ -51,22 +40,28 @@ 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,itemName[item[i].id]); -#endif // DEBUG + + #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; -#ifdef DEBUG - DEBUG_printf("Gave player %u %s(s).\n",count,itemName[item[i].id]); -#endif // DEBUG + + #ifdef DEBUG + DEBUG_printf("Gave player %u %s(s).\n",count,item[i].name); + #endif // DEBUG + return 0; } } + #ifdef DEBUG DEBUG_printf("Failed to add non-existant item with id %u.\n",id); #endif // DEBUG @@ -78,7 +73,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){ for(i=0;i<size;i++){ if(item[i].id==id){ #ifdef DEBUG - DEBUG_printf("Took %u of player's %s(s).\n",count,itemName[item[i].id]); + DEBUG_printf("Took %u of player's %s(s).\n",count,item[i].name); #endif // DEBUG item[i].count-=count; if(item[i].count<0) @@ -92,12 +87,20 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){ void Inventory::draw(void){ unsigned int i=0; float y=offset.y,xoff; - ui::putText(offset.x-SCREEN_WIDTH/2,y,"Inventory:"); + 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); glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D,ITEM_TEX[item[i].id-1]); + glBindTexture(GL_TEXTURE_2D,ITEM_TEX[item[i].id]); if(sel==i)glColor3ub(255,0,255); else glColor3ub(255,255,255); glBegin(GL_QUADS); @@ -107,7 +110,7 @@ void Inventory::draw(void){ glTexCoord2i(0,0);glVertex2i(xoff ,y+HLINE*10); glEnd(); y-=ui::fontSize*1.15; - ui::putText(offset.x-SCREEN_WIDTH/2,y,"%s",itemName[(unsigned)item[i].id]); + ui::putText(offset.x-SCREEN_WIDTH/2,y,"%s",item[i].name); glDisable(GL_TEXTURE_2D); i++; } @@ -132,10 +135,10 @@ void itemDraw(Player *p,ITEM_ID id){ } if(p->inv->tossd) yes=true; glBegin(GL_QUADS); - glTexCoord2i(0,1);glVertex2f(item_coord.x+p1.x,item_coord.y+p2.y); - glTexCoord2i(1,1);glVertex2f(item_coord.x+p2.x,item_coord.y+p2.y); - glTexCoord2i(1,0);glVertex2f(item_coord.x+p2.x,item_coord.y+p1.y); - glTexCoord2i(0,0);glVertex2f(item_coord.x+p1.x,item_coord.y+p1.y); + 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); glEnd(); glDisable(GL_TEXTURE_2D); } @@ -143,8 +146,11 @@ void itemDraw(Player *p,ITEM_ID id){ int Inventory::useItem(void){ ITEM_ID id = item[sel].id; switch(id){ + case SWORD_WOOD: + + break; default: - ui::dialogBox(itemName[id],NULL,"You cannot use this item."); + ui::dialogBox(item[id].name,NULL,"You cannot use this item."); break; } return 0; @@ -274,6 +274,7 @@ namespace ui { width+=fontSize/2; }else if(s[i]=='\b'){ // Handle backspaces? // Why? + // Cuz }else{ width+=ftexwh[i].x+fontSize*.1; } @@ -304,7 +305,7 @@ namespace ui { * Reset values if a new string is being passed. */ - if(!size || ((linc>15)&(strncmp(ret,str,15)))){ + if(strncmp(ret,str,linc-1)){ memset(ret,0,512); // Zero the buffer size=strlen(str); // Set the new target string size linc=0; // Reset the incrementers @@ -470,7 +471,7 @@ namespace ui { hub.y-=fontSize*1.15; glRectf(hub.x, hub.y, - hub.x+(player->health/player->maxHealth)*100, + hub.x+(player->health/player->maxHealth)*130, hub.y+12); } diff --git a/src/world.cpp b/src/world.cpp index 2757471..8d003c9 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -591,6 +591,13 @@ void World::addObject(int i, float x, float y){ entity.push_back(object.back()); } +void World::addObject(int i, bool q, char *p, float x, float y){ + object.push_back(new Object(i,q, p)); + object.back()->spawn(x,y); + + entity.push_back(object.back()); +} + /*void World::removeObject(Object i){ object.delete(i); }*/ |