]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Faggot
authordrumsetmonkey <abelleisle@roadrunner.com>
Mon, 14 Mar 2016 11:34:08 +0000 (07:34 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Mon, 14 Mar 2016 11:34:08 +0000 (07:34 -0400)
include/entities.h
include/ui.h
include/world.h
src/entities.cpp
src/ui.cpp
src/world.cpp

index ef421f571a5d1125b9e4fba65e2999ac79bf2924..450975f32579fc3a78ad23fb96aeaae1022ae1b8 100644 (file)
@@ -219,6 +219,7 @@ public:
 class Merchant : public NPC{
 public:
        std::vector<Trade>trade;
+       uint currTrade;
 
        void interact();
 
index ed9fb944e6fff4ee1b36da23d304fe24078ebb3d..f933a37c24b91c44c30021dd059f3601c6cbc903 100644 (file)
@@ -106,6 +106,7 @@ namespace ui {
        extern bool posFlag;
        
        extern unsigned char dialogOptChosen;
+       extern unsigned char merchOptChosen;
        extern bool              dialogBoxExists;
        extern bool              dialogImportant;
        extern bool              dialogPassive;
@@ -148,6 +149,7 @@ namespace ui {
        void dialogBox(const char *name,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 closeBox();
        void waitForDialog(void);
        
        /*
index a60eab6332b05d6580b0aab3298feac2dbbefc2f..2290b187d414e776be61948551f8cf24bcee2d28 100644 (file)
@@ -53,6 +53,7 @@ enum class WorldWeather : unsigned char {
 typedef struct {
        vec2 loc;               /**< Light location */
        Color color;    /**< Light color */
+       float radius;
 } Light;
 
 /**
index 8a1042866b0563e7a1bc2981d01ffde3a73701dd..6d0f0529e033653819c38d7c9c6b32bee7da7f44 100644 (file)
@@ -169,6 +169,7 @@ Merchant::Merchant(){       //sets all of the Merchant specific traits on object creat
        canMove = true;
 
        trade.reserve(100);
+       currTrade = 0;
        
        //tex = new Texturec(1,"assets/NPC.png");
        //inv = new Inventory(NPC_INV_SIZE);
@@ -433,50 +434,68 @@ void NPC::clearAIFunc(void){
 }
 
 void NPC::interact(){ //have the npc's interact back to the player
-       int (*func)(NPC *);
-       loc.y += 5;
-       
-       canMove=false;
-       left = (player->loc.x < loc.x);
-       right = !left;
-       
-       if(aiFunc.size()){
-               func=aiFunc.front();
+       std::thread([this]{
+               int (*func)(NPC *);
+               loc.y += 5;
+               
+               canMove=false;
+               left = (player->loc.x < loc.x);
+               right = !left;
                
-               if(!func(this)){
-                       if(aiFunc.size())aiFunc.erase(aiFunc.begin());
+               if(aiFunc.size()){
+                       func=aiFunc.front();
+                       
+                       if(!func(this)){
+                               if(aiFunc.size())aiFunc.erase(aiFunc.begin());
+                       }
+               }else{
+                       ui::dialogBox(name,NULL,false,randomDialog[randDialog]);
                }
-       }else{
-               ui::dialogBox(name,NULL,false,randomDialog[randDialog]);
-       }
-       ui::waitForDialog();
-       canMove=true;
+               ui::waitForDialog();
+               canMove=true;
+       }).detach();
 }
 
 void Merchant::interact(){
-       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;
-       }
+       std::thread([this]{
+               ui::merchantBox(name, trade[currTrade], ":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[currTrade].item[1],trade[currTrade].quantity[1])))
+                               player->inv->addItem(trade[currTrade].item[0],trade[currTrade].quantity[0]);
+               }else if(ui::dialogOptChosen == 2){
+                       std::cout << "See ye!" << std::endl;
+               }else if(ui::merchOptChosen == 1){
+                       if(currTrade != 0){
+                               currTrade--;
+                               std::cout << "Last trade" << std::endl;
+                               interact();
+                       }
+               }else if(ui::merchOptChosen == 2){
+                       if(currTrade < trade.size()){
+                               currTrade++;
+                               std::cout << "Next trade" << std::endl;
+                               interact();
+                       }
+               }
+       }).detach();
 }
 
 void Object::interact(void){
-       if(questObject && alive){
-               ui::dialogBox( player->name, ":Yes:No", false, pickupDialog.c_str());
-               ui::waitForDialog();
-               if(ui::dialogOptChosen == 1){
-                       player->inv->addItem( iname, 1 );
+       std::thread([this]{
+               if(questObject && alive){
+                       ui::dialogBox( player->name, ":Yes:No", false, pickupDialog.c_str());
+                       ui::waitForDialog();
+                       if(ui::dialogOptChosen == 1){
+                               player->inv->addItem( iname, 1 );
+                               alive = false;
+                       }
+               }else{
                        alive = false;
+                       player->inv->addItem(iname, 1);
                }
-       }else{
-               alive = false;
-               player->inv->addItem(iname, 1);
-       }
+       }).detach();
 }
 
 void Entity::
@@ -601,7 +620,8 @@ void Mob::wander(int timeRun){
        case MS_TRIGGER:
                if(player->loc.x + player->width / 2 > loc.x             &&
                   player->loc.x + player->width / 2 < loc.x + width )
-                       hey(this);
+                       std::thread([this]{hey(this);}).detach();
+                       //hey(this);
                break;
        case MS_PAGE:
                if(player->loc.x > loc.x - 100           &&
index eb25e2e7e47125ca5cf69467875c0e6cd7e7c131..ee29641a74b7a34fdde7d95e89ca9d8d8bb7a3c9 100644 (file)
@@ -191,6 +191,7 @@ namespace ui {
        */
        
        void setFontSize(unsigned int size){
+               mtx.lock();
                unsigned int i,j;
                unsigned char *buf;
                
@@ -253,6 +254,7 @@ namespace ui {
                        
                        delete[] buf;   //free(buf);
                }
+               mtx.unlock();
        }
        
        /*
@@ -569,6 +571,7 @@ namespace ui {
                };
 
                dialogOptChosen = 0;
+               merchOptChosen = 0;
                memset(&dialogOptLoc, 0, sizeof(float) * 12);
                
                // handle options if desired
@@ -607,8 +610,9 @@ namespace ui {
        
        void waitForDialog(void){
                do{
-                       mainLoop();
-               }while(ui::dialogBoxExists);
+                       //std::thread(dialogAdvance);
+                       //mainLoop();
+               }while(dialogBoxExists);
        }
        void waitForCover(void){
                do{
@@ -692,7 +696,7 @@ namespace ui {
                                        glVertex2f(x+1+(SCREEN_WIDTH/3),y+1);
                                        glVertex2f(x+1+(SCREEN_WIDTH/3),y-1-SCREEN_HEIGHT*.6);
                                        glVertex2f(x-1,y-1-SCREEN_HEIGHT*.6);
-                                       glVertex2f(x,y+1);
+                                       glVertex2f(x-1,y+1);
                                glEnd();
                        
                                glColor3ub(0,0,0);
@@ -787,11 +791,11 @@ namespace ui {
                                glColor3ub(255, 255, 255);
 
                                glBegin(GL_LINE_STRIP);
-                                       glVertex2f(x-1                                          ,y+1);
-                                       glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y+1);
-                                       glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4);
-                                       glVertex2f(x-1                                          ,y-1-SCREEN_HEIGHT/4);
-                                       glVertex2f(x                                            ,y+1);
+                                       glVertex2i(x-1                                          ,y+1);
+                                       glVertex2i(x+1+SCREEN_WIDTH-HLINE*16,y+1);
+                                       glVertex2i(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4);
+                                       glVertex2i(x-1                                          ,y-1-SCREEN_HEIGHT/4);
+                                       glVertex2i(x-1                                          ,y+1);
                                glEnd();
                        
                                glColor3ub(0,0,0);
@@ -1203,27 +1207,40 @@ namespace ui {
                        typeOutDone = true;
                        return;
                }
-
                for(i=0;i<dialogOptCount;i++){
                        if(mouse.x > dialogOptLoc[i][0] &&
                           mouse.x < dialogOptLoc[i][2] &&
                           mouse.y > dialogOptLoc[i][1] &&
                           mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
                                dialogOptChosen = i + 1;
-                               goto DONE;
+                               goto EXIT;
+                       }
+               }
+               if(dialogMerchant){
+                       for(i=0;i<2;i++){
+                               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){ // fontSize
+                                               merchOptChosen = i + 1;
+                                               goto EXIT;
+                               }
                        }
                }
-DONE:
-
                
+
+               EXIT:
+               //if(!dialogMerchant)closeBox();
+               dialogBoxExists = false;
+               dialogMerchant = false;
+
+               //DONE:
+
                // handle important text
                if(dialogImportant){
                        dialogImportant = false;
                        setFontSize(16);
                }
-
-               if(dialogMerchant) dialogMerchant = false;
-               dialogBoxExists = false;
        }
 
        void handleEvents(void){
index 5ce0b2db073f1bc66546829a2c6e595eca375ab0..8af9e6ad9068a866db3e9239dda410d9a6d5fad6 100644 (file)
@@ -1342,7 +1342,8 @@ loadWorldFromXMLNoSave( std::string path ) {
        float spawnx, randx;
        bool dialog,Indoor;
        
-       const char *ptr,*name;
+       const char *ptr;
+       std::string name;
                
        currentXML = (std::string)"xml/" + path;
 
@@ -1364,18 +1365,18 @@ loadWorldFromXMLNoSave( std::string path ) {
        while(wxml){
                name = wxml->Name();
                
-               if(!strcmp(name,"link")){
+               if(name == "link"){
                        if((ptr = wxml->Attribute("left")))
                                tmp->setToLeft(ptr);
                        else if((ptr = wxml->Attribute("right")))
                                tmp->setToRight(ptr);
                        else
                                abort();
-               }else if(!strcmp(name,"style")){
+               }else if(name == "style"){
                        tmp->setStyle(wxml->StrAttribute("folder"));
                        tmp->setBackground((WorldBGType)wxml->UnsignedAttribute("background"));
                        tmp->setBGM(wxml->StrAttribute("bgm"));
-               }else if(!strcmp(name,"generation")){
+               }else if(name == "generation"){
                        if(!strcmp(wxml->Attribute("type"),"Random")){
                                if(Indoor)
                                        ((IndoorWorld *)tmp)->generate(wxml->UnsignedAttribute("width"));
@@ -1385,7 +1386,7 @@ loadWorldFromXMLNoSave( std::string path ) {
                                }
                        }else if(Indoor)
                                abort();
-               }else if(!strcmp(name,"mob")){
+               }else if(name == "mob"){
                        unsigned int type;
                        type = wxml->UnsignedAttribute("type");
                        if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
@@ -1395,7 +1396,7 @@ loadWorldFromXMLNoSave( std::string path ) {
                        if(wxml->QueryBoolAttribute("aggressive",&dialog) == XML_NO_ERROR)
                                tmp->mob.back()->aggressive = dialog;
                        
-               }else if(!strcmp(name,"npc")){
+               }else if(name == "npc"){
                        const char *npcname;
 
                        if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
@@ -1415,7 +1416,7 @@ loadWorldFromXMLNoSave( std::string path ) {
                                tmp->npc.back()->addAIFunc(commonAIFunc,false);
                        else tmp->npc.back()->dialogIndex = 9999;
                        
-               }else if(!strcmp(name,"structure")){
+               }else if(name == "structure"){
                        tmp->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"),
                                                           wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR ? 
                                                                                getRand() % tmp->getTheWidth() / 2.0f : 
@@ -1423,7 +1424,7 @@ loadWorldFromXMLNoSave( std::string path ) {
                                                           100,
                                                           wxml->StrAttribute("texture"),
                                                           wxml->StrAttribute("inside"));
-               }else if(!strcmp(name,"trigger")){
+               }else if(name == "trigger"){
                        tmp->addMob(MS_TRIGGER,wxml->FloatAttribute("x"),0,commonTriggerFunc);
                        tmp->mob.back()->heyid = wxml->Attribute("id");
                }
@@ -1449,13 +1450,13 @@ loadWorldFromXMLNoSave( std::string path ) {
                 *      READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE
                 */
                 
-               if(!strcmp(name,"structure")){
+               if(name == "structure"){
                        tmp->addStructure((BUILD_SUB)vil->UnsignedAttribute("type"),
                                                           vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ? randx : spawnx,
                                                           100,
                                                           vil->StrAttribute("texture"),
                                                           vil->StrAttribute("inside"));
-               }else if(!strcmp(name, "stall")){
+               }else if(name ==  "stall"){
                        if(!strcmp(vil->Attribute("type"),"market")){
                                std::cout << "Market" << std::endl;
                                tmp->addStructure((BUILD_SUB)70,
@@ -1467,8 +1468,6 @@ loadWorldFromXMLNoSave( std::string path ) {
                                tmp->addMerchant(0,100);
                                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")){
@@ -1477,7 +1476,9 @@ loadWorldFromXMLNoSave( std::string path ) {
                                                                                                                                vil->FirstChildElement("trade")->Attribute("item"),
                                                                                                                                vil->FirstChildElement("trade")->IntAttribute("quantity1"),
                                                                                                                                vil->FirstChildElement("trade")->Attribute("item1")));
+                                       tmp->merchant.back()->trade.push_back(Trade(1,"Wood Sword", 420, "Dank MayMay"));
                                }
+                               std::cout << "new trade" << std::endl;
                                strcpy(tmp->merchant.back()->name,"meme");
 
                        }else if(!strcmp(vil->Attribute("type"),"trader")){