]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
You can buy sausages from meme
authordrumsetmonkey <abelleisle@roadrunner.com>
Fri, 4 Mar 2016 13:42:00 +0000 (08:42 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Fri, 4 Mar 2016 13:42:00 +0000 (08:42 -0500)
13 files changed:
assets/items/coin1.png [new file with mode: 0644]
assets/items/coin2.png [new file with mode: 0644]
assets/items/coin3.png [new file with mode: 0644]
assets/style/classic/bg/moon.png [new file with mode: 0644]
config/items.xml
include/entities.h
include/inventory.h
include/ui.h
src/entities.cpp
src/inventory.cpp
src/ui.cpp
src/world.cpp
xml/playerSpawnHill1.xml

diff --git a/assets/items/coin1.png b/assets/items/coin1.png
new file mode 100644 (file)
index 0000000..6b8ba8c
Binary files /dev/null and b/assets/items/coin1.png differ
diff --git a/assets/items/coin2.png b/assets/items/coin2.png
new file mode 100644 (file)
index 0000000..5bfd622
Binary files /dev/null and b/assets/items/coin2.png differ
diff --git a/assets/items/coin3.png b/assets/items/coin3.png
new file mode 100644 (file)
index 0000000..61bf980
Binary files /dev/null and b/assets/items/coin3.png differ
diff --git a/assets/style/classic/bg/moon.png b/assets/style/classic/bg/moon.png
new file mode 100644 (file)
index 0000000..d9a5ab7
Binary files /dev/null and b/assets/style/classic/bg/moon.png differ
index 02382d6ff29d339cf6386284f9ef62ac05c2e4c9..eddab3e795c9816d8593fe3e110bf1b82bd27864 100644 (file)
@@ -1,5 +1,9 @@
 <?xml version="1.0"?>
 
+<currency name="Abe Lincoln" value="1" sprite="assets/items/coin1.png"/>
+<currency name="George Washington" value="25" sprite="assets/items/coin2.png"/>
+<currency name="Barack Hussein Obama" value="100" sprite="assets/items/coin3.png"/>
+
 <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" />
index 07146505145d22fbd7c1871058478875a90c4391..b39923b6b4a9922f9c7583fa7ee4809a86477e7b 100644 (file)
@@ -52,38 +52,20 @@ enum BUILD_SUB{
        STALL_TRADER = 71
 };
 
-class BuySell{
+class Trade{
 public:
-       int member;
-       // 0 = Buy/Sell
-       // 1 = Trade
-       union{
-               struct{
-                       std::string item;
-                       std::string itemt;
-               }trade;
-               struct{
-                       int type;
-                       // 0 = buy
-                       // 1 = sell
-                       std::string item;
-                       int price;
-               }cost;
-       };
-       BuySell(int typ, std::string itm, int prc){
-               this->cost.type = typ;
-               this->cost.item = itm;
-               this->cost.price = prc;
-               this->member = 0;
-       }
-       BuySell(std::string itm, std::string itmt){
-               this->trade.item = itm;
-               this->trade.itemt = itmt;
-               this->member = 1;
+       std::string item[2];
+       int quantity[2];
+       Trade(int qo, const char* o, int qt, const char* t){
+               item[0] = o;
+               item[1] = t;
+
+               quantity[0] = qo;
+               quantity[1] = qt;
+
+               std::cout << "Trading: " << quantity[0] << " " << item[0] << " for " << quantity[1] << " " << item[1] << std::endl;
        }
-       ~BuySell(){}
-       BuySell(const BuySell&){}
-       BuySell(){}
+       Trade(){}
 };
 
 class World;
@@ -233,7 +215,8 @@ public:
 
 class Merchant : public NPC{
 public:
-       std::vector<BuySell>bsinv;
+       std::vector<Trade>trade;
+
        void interact();
 
        Merchant();
index cf6e4807004abc15a816d94723a5f9f1885f4b67..69cf073c40db9ddeaaa96ecae95533934125e821 100644 (file)
@@ -62,7 +62,7 @@ void initInventorySprites(void);
 void destroyInventory(void);
 
 const char *getItemTexturePath(std::string name);
-Texturec *getItemTexture(std::string name);
+GLuint getItemTexture(std::string name);
 float getItemWidth(std::string name);
 float getItemHeight(std::string name);
 
index 667a58159f43b65fbe9dc44d541fb1f631e826a7..ed9fb944e6fff4ee1b36da23d304fe24078ebb3d 100644 (file)
@@ -146,7 +146,7 @@ namespace ui {
        */
        
        void dialogBox(const char *name,const char *opt,bool passive,const char *text,...);
-       void merchantBox(const char *name, std::vector<BuySell> *items, const char *opt,bool passive,const char *text,...);
+       void merchantBox(const char *name,Trade trade,const char *opt,bool passive,const char *text,...);
        void merchantBox();
        void waitForDialog(void);
        
index 8abc727a2a6e3bfa992e9e863c8d5edaf6aaf52b..cd534cdcc332a61fb2d8e4af574ca325c932e05b 100644 (file)
@@ -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;
        }
index cd8bb71a5b0c77b879b37d6b4697e0f6df957469..d75a1bfce1627a0aa5aa205492b6ae43709c4efc 100644 (file)
@@ -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){
index 2c9a230d6386b44d59af647c42d56cdf1a34f6a6..81098fc8269cc4b21bd5b293e2195f427873a821 100644 (file)
@@ -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:
index e4ce1fd21f67bfeef175bdf75866d2e0619b19ce..8283e8cbeb12515f60dde02360dbd36f683dcc5c 100644 (file)
@@ -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");
 
index 370cc03dd0df997956a18f4b388bb6aaa89e62ab..2fa7512cfeedc55dc1c982d90a4b4411972e2919 100644 (file)
        
        <npc name="Ralph" hasDialog="true" />
        <npc name="Johnny" hasDialog="false" />
-       <!-- <structure type="5" inside="playerSpawnHill1_Building1.xml" /> -->
        <village name="the Cranmore Tubing Park">
                <structure type="0" x="-300" inside="playerSpawnHill1_Building1.xml"/>
                <structure type="5" x="-500" inside="playerSpawnHill1_Building1.xml"/>
                <stall type="market" texture="assets/style/classic/stall.png">
                        <buy item="Dank MayMay" cost="420"/>
                        <sell item="Dank MayMay" cost="666"/>
-                       <trade item="Dank MayMay" item1="Sword"/>
+                       <trade quantity="420" item="Dank MayMay" quantity1="1" item1="Wood Sword"/>
+                       <trade quantity="666" item="Wood Sword" quantity1="420" item1="Dank MayMay"/>
                </stall>
        </village>