aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-03-04 08:47:03 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-03-04 08:47:03 -0500
commit0a06697db87063b77b71388278933807899568ef (patch)
treebb8d876e266761c7aac8656c2d75793855826bd0 /src
parent5fadac5d0f37f574ca160107d832d11b421ad559 (diff)
parent30dd8efe8d71648bea7604ebee5afc4d55b25a6b (diff)
merge
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp12
-rw-r--r--src/inventory.cpp11
-rw-r--r--src/ui.cpp91
-rw-r--r--src/world.cpp19
4 files changed, 103 insertions, 30 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index 73105f1..329af63 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -166,6 +166,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);
@@ -447,9 +449,15 @@ 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();
+ 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;
+ }
}
void Object::interact(void){
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 7400f89..e82d99e 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -68,7 +68,7 @@ int Inventory::takeItem(std::string name,uint count){
}
if(id == 999999)
- return -1;
+ return -1; //if no such item exists
/*
* Inventory lookup
@@ -141,6 +141,15 @@ const char *getItemTexturePath(std::string name){
return NULL;
}
+GLuint getItemTexture(std::string name){
+ for(auto &i : itemMap){
+ if(i->name == name)
+ return Texture::loadTexture(i->texloc);
+ }
+
+ return Texture::loadTexture("assets/items/ITEM_TEST.png");
+}
+
float getItemWidth(std::string name){
for(auto &i : itemMap){
if(i->name == name)
diff --git a/src/ui.cpp b/src/ui.cpp
index 7333fc4..f0cc507 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -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,6 +679,8 @@ namespace ui {
setFontSize(16);
}
}else if(dialogMerchant){
+ //static int dispItem;
+
x=offset.x-SCREEN_WIDTH/6;
y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
@@ -683,31 +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[0][1] = offset.x + (SCREEN_WIDTH / 6.5);
- merchAOptLoc[1][0] = offset.y + (SCREEN_HEIGHT *.25);
- merchAOptLoc[1][1] = offset.y + (SCREEN_HEIGHT *.25);
- merchAOptLoc[2][0] = offset.x - (SCREEN_WIDTH / 6.5);
- merchAOptLoc[2][1] = 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[0][i] && mouse.x < merchAOptLoc[2][i] &&
- mouse.y > merchAOptLoc[1][i] - 8 && mouse.y < merchAOptLoc[1][i] + 8){
- glColor3ub(255, 255, 0);
+ 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){
+ 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[1][0]);
- glVertex2f(merchAOptLoc[2][0],merchAOptLoc[1][0]-8);
- glVertex2f(merchAOptLoc[2][0],merchAOptLoc[1][0]+8);
-
- glVertex2f(merchAOptLoc[2][1],merchAOptLoc[1][1]);
- glVertex2f(merchAOptLoc[0][1],merchAOptLoc[1][1]-8);
- glVertex2f(merchAOptLoc[0][1],merchAOptLoc[1][1]+8);
- glEnd();
// draw / handle dialog options if they exist
for(i = 0; i < dialogOptCount; i++){
@@ -1407,7 +1454,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 5dbbe21..a0ae0f3 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -325,7 +325,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;
@@ -1411,6 +1411,7 @@ loadWorldFromXMLNoSave( std::string path ) {
while(vil){
name = vil->Name();
randx = 0;
+ //static BuySell bs;
/**
* READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE
@@ -1432,10 +1433,18 @@ loadWorldFromXMLNoSave( std::string path ) {
vil->StrAttribute("texture"),
vil->StrAttribute("inside"));
tmp->addMerchant(0,100);
- if(!strcmp(name,"buy")){
- std::cout << "Buying";
- }else if(!strcmp(name,"sell")){
- std::cout << "Selling";
+ if(vil->FirstChildElement("buy")){
+ std::cout << "Buy" << std::endl;
+ //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");