diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-03-04 08:42:00 -0500 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-03-04 08:42:00 -0500 |
commit | 30dd8efe8d71648bea7604ebee5afc4d55b25a6b (patch) | |
tree | 73cf4dbaa2be340597f6fac7fd7a1cedae9cbdea /src | |
parent | 6af8dcbaa41a7db52ff8f6074d2b113ec7eaf12d (diff) |
You can buy sausages from meme
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 6 | ||||
-rw-r--r-- | src/inventory.cpp | 9 | ||||
-rw-r--r-- | src/ui.cpp | 91 | ||||
-rw-r--r-- | src/world.cpp | 15 |
4 files changed, 85 insertions, 36 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index 8abc727..cd534cd 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -147,6 +147,8 @@ Merchant::Merchant(){ //sets all of the Merchant specific traits on object creat maxHealth = health = 100; canMove = true; + + trade.reserve(100); //tex = new Texturec(1,"assets/NPC.png"); //inv = new Inventory(NPC_INV_SIZE); @@ -449,10 +451,12 @@ void NPC::interact(){ //have the npc's interact back to the player } void Merchant::interact(){ - ui::merchantBox(name, &bsinv, ":Accept:Good-Bye", false, "Welcome to Smithy\'s. Buy your sausages here you freaking meme lording screw-face"); + ui::merchantBox(name, trade.back(), ":Accept:Good-Bye", false, "Welcome to Smithy\'s. Buy your sausages here you freaking meme lording screw-face"); ui::waitForDialog(); if(ui::dialogOptChosen == 1){ std::cout << "Gimme ye' munny" << std::endl; + if(player->inv->takeItem(trade.back().item[1],trade.back().quantity[1]) >= 0) + player->inv->addItem(trade.back().item[0],trade.back().quantity[0]); }else{ std::cout << "See ye!" << std::endl; } diff --git a/src/inventory.cpp b/src/inventory.cpp index cd8bb71..d75a1bf 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -66,7 +66,7 @@ int Inventory::takeItem(std::string name,uint count){ } if(id == 999999) - return -1; + return -1; //if no such item exists /* * Inventory lookup @@ -142,12 +142,13 @@ const char *getItemTexturePath(std::string name){ return NULL; } -Texturec *getItemTexture(std::string name){ +GLuint getItemTexture(std::string name){ for(auto &i : itemMap){ if(i->name == name) - return i->tex; + return Texture::loadTexture(i->texloc); } - return NULL; + + return Texture::loadTexture("assets/items/ITEM_TEST.png"); } float getItemWidth(std::string name){ @@ -120,8 +120,8 @@ namespace ui { bool posFlag=false; bool dialogPassive = false; bool dialogMerchant = false; - std::vector<BuySell> *minv; int dialogPassiveTime = 0; + Trade merchTrade; /* @@ -131,6 +131,7 @@ namespace ui { bool dialogBoxExists = false; bool dialogImportant = false; unsigned char dialogOptChosen = 0; + unsigned char merchOptChosen = 0; unsigned int textWrapLimit = 110; @@ -313,6 +314,7 @@ namespace ui { unsigned int i=0; float xo=x,yo=y; vec2 add; + //vec2 off = { (float)floor(x), (float)floor(y) }; /* * Loop on each character: @@ -325,6 +327,14 @@ namespace ui { if(s[i] == ' ') i++; } + if(i && (i / (float)textWrapLimit == i / textWrapLimit)){ + yo -= fontSize * 1.05; + xo = x; + + // skip a space if it's there since we just newline'd + if(s[i] == ' ') + i++; + } if(s[i] == '\n'){ yo-=fontSize*1.05; xo=x; @@ -523,13 +533,17 @@ namespace ui { ret[0] = '\0'; } - void merchantBox(const char *name,std::vector<BuySell> *bsinv,const char *opt,bool passive,const char *text,...){ + + void merchantBox(const char *name,Trade trade,const char *opt,bool passive,const char *text,...){ std::cout << "Buying and selling on the bi-weekly!" << std::endl; va_list dialogArgs; size_t len; - minv = bsinv; dialogPassive = passive; + + std::cout << "Market Trading: " << trade.quantity[0] << " " << trade.item[0] << " for " << trade.quantity[1] << " " << trade.item[1] << std::endl; + + merchTrade = trade; // clear the buffer memset(dialogBoxText, '\0', 512); @@ -665,7 +679,7 @@ namespace ui { setFontSize(16); } }else if(dialogMerchant){ - static int dispItem; + //static int dispItem; x=offset.x-SCREEN_WIDTH/6; y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8; @@ -685,33 +699,62 @@ namespace ui { // draw typeOut'd text putString(x + HLINE, y - fontSize - HLINE, (rtext = typeOut(dialogBoxText))); - merchAOptLoc[0][0] = offset.x - (SCREEN_WIDTH / 6.5) - 16; - merchAOptLoc[1][0] = offset.x + (SCREEN_WIDTH / 6.5); - merchAOptLoc[0][1] = offset.y + (SCREEN_HEIGHT *.25); - merchAOptLoc[1][1] = offset.y + (SCREEN_HEIGHT *.25); - merchAOptLoc[0][2] = offset.x - (SCREEN_WIDTH / 6.5); - merchAOptLoc[1][2] = offset.x + (SCREEN_WIDTH / 6.5) + 16; + + std::string itemString1 = std::to_string(merchTrade.quantity[0]); + itemString1 += "x"; + + std::string itemString2 = std::to_string(merchTrade.quantity[1]); + itemString2 += "x"; + + putStringCentered(offset.x - (SCREEN_WIDTH / 10) + 20, offset.y + (SCREEN_HEIGHT / 5) + 40 + (fontSize*2), itemString1.c_str()); + putStringCentered(offset.x - (SCREEN_WIDTH / 10) + 20, offset.y + (SCREEN_HEIGHT / 5) + 40 + fontSize, merchTrade.item[0].c_str()); + + putStringCentered(offset.x + (SCREEN_WIDTH / 10) - 20, offset.y + (SCREEN_HEIGHT / 5) + 40 + (fontSize*2), itemString2.c_str()); + putStringCentered(offset.x + (SCREEN_WIDTH / 10) - 20, offset.y + (SCREEN_HEIGHT / 5) + 40 + fontSize, merchTrade.item[1].c_str()); + + putStringCentered(offset.x,offset.y + (SCREEN_HEIGHT / 5) + 60, "for"); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[0])); + glBegin(GL_QUADS); + glTexCoord2d(0,1);glVertex2f(offset.x - (SCREEN_WIDTH / 10) ,offset.y + (SCREEN_HEIGHT/5)); + glTexCoord2d(1,1);glVertex2f(offset.x - (SCREEN_WIDTH / 10) + 40,offset.y + (SCREEN_HEIGHT/5)); + glTexCoord2d(1,0);glVertex2f(offset.x - (SCREEN_WIDTH / 10) + 40,offset.y + (SCREEN_HEIGHT/5) + 40); + glTexCoord2d(0,0);glVertex2f(offset.x - (SCREEN_WIDTH / 10) ,offset.y + (SCREEN_HEIGHT/5) + 40); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[1])); + glBegin(GL_QUADS); + glTexCoord2d(0,1);glVertex2f(offset.x + (SCREEN_WIDTH / 10) - 40,offset.y + (SCREEN_HEIGHT/5)); + glTexCoord2d(1,1);glVertex2f(offset.x + (SCREEN_WIDTH / 10) ,offset.y + (SCREEN_HEIGHT/5)); + glTexCoord2d(1,0);glVertex2f(offset.x + (SCREEN_WIDTH / 10) ,offset.y + (SCREEN_HEIGHT/5) + 40); + glTexCoord2d(0,0);glVertex2f(offset.x + (SCREEN_WIDTH / 10) - 40,offset.y + (SCREEN_HEIGHT/5) + 40); + glEnd(); + glDisable(GL_TEXTURE_2D); + + merchAOptLoc[0][0] = offset.x - (SCREEN_WIDTH / 8.5) - 16; + merchAOptLoc[1][0] = offset.x + (SCREEN_WIDTH / 8.5) + 16; + merchAOptLoc[0][1] = offset.y + (SCREEN_HEIGHT *.2); + merchAOptLoc[1][1] = offset.y + (SCREEN_HEIGHT *.2); + merchAOptLoc[0][2] = offset.x - (SCREEN_WIDTH / 8.5); + merchAOptLoc[1][2] = offset.x + (SCREEN_WIDTH / 8.5); for(i = 0; i < 2; i++){ - if(mouse.x > merchAOptLoc[i][0] && mouse.x < merchAOptLoc[i][2] && + if(((merchAOptLoc[i][0] < merchAOptLoc[i][2]) ? + (mouse.x > merchAOptLoc[i][0] && mouse.x < merchAOptLoc[i][2]) : + (mouse.x < merchAOptLoc[i][0] && mouse.x > merchAOptLoc[i][2])) && mouse.y > merchAOptLoc[i][1] - 8 && mouse.y < merchAOptLoc[i][1] + 8){ - dispItem++; - glColor3ub(255,255, 0); + glColor3ub(255,255, 0); }else{ glColor3ub(255,255,255); } + glBegin(GL_TRIANGLES); + glVertex2f(merchAOptLoc[i][0],merchAOptLoc[i][1]); + glVertex2f(merchAOptLoc[i][2],merchAOptLoc[i][1]-8); + glVertex2f(merchAOptLoc[i][2],merchAOptLoc[i][1]+8); + glEnd(); } - glBegin(GL_TRIANGLES); - glVertex2f(merchAOptLoc[0][0],merchAOptLoc[0][1]); - glVertex2f(merchAOptLoc[0][2],merchAOptLoc[0][1]-8); - glVertex2f(merchAOptLoc[0][2],merchAOptLoc[0][1]+8); - - glVertex2f(merchAOptLoc[1][2],merchAOptLoc[1][1]); - glVertex2f(merchAOptLoc[1][0],merchAOptLoc[1][1]-8); - glVertex2f(merchAOptLoc[1][0],merchAOptLoc[1][1]+8); - glEnd(); - // draw / handle dialog options if they exist for(i = 0; i < dialogOptCount; i++){ @@ -1410,7 +1453,7 @@ DONE: //currentWorld->addVillage(player->loc.x, player->loc.y, 5, 10, 100, NULL); break; case SDLK_b: - currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, NULL, NULL); + currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, "", ""); currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); break; case SDLK_F12: diff --git a/src/world.cpp b/src/world.cpp index e4ce1fd..8283e8c 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -303,7 +303,7 @@ update( Player *p, unsigned int delta ) } // iterate through particles - particles.erase( std::remove_if( particles.begin(), particles.end(), [&delta](Particles part){ return part.kill( delta ); }), particles.end()); + particles.erase( std::remove_if( particles.begin(), particles.end(), [&delta](Particles &part){return part.kill(delta);}), particles.end()); for ( auto part = particles.begin(); part != particles.end(); part++ ) { if ( (*part).canMove ) { (*part).loc.y += (*part).vely * delta; @@ -464,7 +464,7 @@ draw( Player *p ) } glEnd(); - for ( i = 4; i--; ) { + for (i = 0; i < 4; i++) { bgTex->bindNext(); safeSetColorA( bgDraw[i][0] - shadeBackground, bgDraw[i][0] - shadeBackground, bgDraw[i][0] - shadeBackground, bgDraw[i][1] ); @@ -1440,15 +1440,16 @@ loadWorldFromXMLNoSave( std::string path ) { tmp->addMerchant(0,100); if(vil->FirstChildElement("buy")){ std::cout << "Buy" << std::endl; - /*bs.member = 0; - bs.cost.type = 0; - bs.cost.item = vil->FirstChildElement("buy")->Attribute("item"); - bs.cost.price =vil->FirstChildElement("buy")->IntAttribute("cost");*/ - tmp->merchant.back()->bsinv.push_back({0,"Dank MayMay",420}); + //Trade goodMeme(1,"Dank MayMay",1,"Sword"); + //tmp->merchant.back()->trade.push_back(Trade()); }if(vil->FirstChildElement("sell")){ std::cout << "Sell" << std::endl; }if(vil->FirstChildElement("trade")){ std::cout << "Trade" << std::endl; + tmp->merchant.back()->trade.push_back(Trade(vil->FirstChildElement("trade")->IntAttribute("quantity"), + vil->FirstChildElement("trade")->Attribute("item"), + vil->FirstChildElement("trade")->IntAttribute("quantity1"), + vil->FirstChildElement("trade")->Attribute("item1"))); } strcpy(tmp->merchant.back()->name,"meme"); |