From 82c178d797b9a23c31d7dad1cc8cac29d27c6eb1 Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Mon, 28 Mar 2016 08:26:06 -0400 Subject: [PATCH] Merchants have to stay inside the stalls --- assets/style/classic/stall.png | Bin 778 -> 739 bytes assets/style/classic/stallFruit.png | Bin 641 -> 635 bytes config/settings.xml.example | 3 +-- include/entities.h | 30 ++++++++++++++++------------ main.cpp | 16 +++++++-------- src/entities.cpp | 29 +++++++++++++++++++++++++-- src/world.cpp | 5 ++--- xml/playerSpawnHill1.xml | 2 +- 8 files changed, 56 insertions(+), 29 deletions(-) diff --git a/assets/style/classic/stall.png b/assets/style/classic/stall.png index 1ac9844addb947366f55d685036e07a18d1a9256..f1718b2e222ca48fa767abde1765127cc850e90a 100644 GIT binary patch delta 730 zcmeBTd(3Lw8Q|y6%O%Cdz`(%k>ERLtq>F$!go6!8#%Uyn0V%d5Z+91l{~)+v@AAnL z6~*fr*h@TpUD+Qn%W#`0PkQdRk%57!z|+Msq~g}wIg0*=9VFWBH?uNIi19cIi)iSu z9lz3~A|WIsvY(ALvZ>M2=;#EM2$4SdhUhls#ugF7zLeM7;_{d3UVmPgn!Eq;z3Qs# zVrf(6c}!qeJA1D9OZeBIeihBGJ1r*9o?rPoh3R`e`|-b(bN9Udd9Cmahca`c0;kX^ zJNHdmf7@>+rZlWv7By9DYu1@Hd6Bmav+vI5F*Fj$+NUO#>Tq+z+w*_89>$p;I&q-q z%j}q9xyFM*@@BWbbG1&i5nyOy0YV-r<@?`zgu~+3eea+Au6xhx^ecU5ZcQ$(Pe^fa z`^VRmshoJGUi!7iq;qBFs-DmL^)I`p*njLTzx8WY*}P7-FPG=0w|#Tr{JVhjZ+gwE z&S5P|gWA^^SomM}t^}oG-{+W&Omh>#^och#Id1Yo3qqiNt#{Zuc z#zdY^K6Y-d>J# z;zN0kdi3Z_`?}uR^U}G4tty#6>pUlwe7?BuNlfQNiO4f|GJJiEN=s7%CtazoKJIbA zBY%zO+SS`G|MT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x$iNl*WvBICv0x$R&U7A(YYt6vqAgFI)Ti&QQN%NB#B#`w!DtR?IOm%w@X*_ e6|dVk - + - diff --git a/include/entities.h b/include/entities.h index 3b13ce3..1250708 100644 --- a/include/entities.h +++ b/include/entities.h @@ -202,6 +202,20 @@ public: void sspawn(float x,float y); }; +class Structures : public Entity{ +public: + BUILD_SUB bsubtype; + World *inWorld; + std::string inside; + std::string textureLoc; + + Structures(); + ~Structures(); + + unsigned int spawn(BUILD_SUB, float, float); +}; + + class NPC : public Entity { public: std::vectoraiFunc; @@ -214,7 +228,7 @@ public: void addAIFunc(int (*func)(NPC *),bool preload); void clearAIFunc(void); virtual void interact(); - void wander(int); + virtual void wander(int); }; class Merchant : public NPC{ @@ -223,22 +237,12 @@ public: uint currTrade; void interact(); + Structures *inside; Merchant(); ~Merchant(); -}; - -class Structures : public Entity{ -public: - BUILD_SUB bsubtype; - World *inWorld; - std::string inside; - std::string textureLoc; - Structures(); - ~Structures(); - - unsigned int spawn(BUILD_SUB, float, float); + void wander(int); }; class Mob : public Entity{ diff --git a/main.cpp b/main.cpp index 0be7256..f4a0005 100644 --- a/main.cpp +++ b/main.cpp @@ -325,7 +325,7 @@ int main(int argc, char *argv[]){ */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - //SDL_GL_SetSwapInterval(0); + SDL_GL_SetSwapInterval(0); glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); @@ -461,16 +461,18 @@ void mainLoop(void){ if(!currentTime) // Initialize currentTime if it hasn't been currentTime=millis(); + if(!prevTime){ + prevTime=currentTime; + } /* * Update timing values. This is crucial to calling logic and updating the window (basically * the entire game). */ - prevTime = currentTime; currentTime = millis(); deltaTime = currentTime - prevTime; - + prevTime = currentTime; if(currentMenu)goto MENU; @@ -487,7 +489,6 @@ void mainLoop(void){ currentWorld->bgmPlay(prev); ui::dialogBoxExists = false; } - if(prevPrevTime + MSEC_PER_TICK <= currentTime){ //pool.Enqueue(logic); logic(); @@ -588,7 +589,7 @@ void render(){ 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); - glOrtho(floor(offset.x-SCREEN_WIDTH/2),floor(offset.x+SCREEN_WIDTH/2),floor(offset.y-SCREEN_HEIGHT/2),floor(offset.y+SCREEN_HEIGHT/2),-1,1); + glOrtho(floor(offset.x-SCREEN_WIDTH/2),floor(offset.x+SCREEN_WIDTH/2),floor(offset.y-SCREEN_HEIGHT/2),floor(offset.y+SCREEN_HEIGHT/2),20,-20); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); @@ -604,8 +605,8 @@ void render(){ * GL_COLOR_BUFFER_BIT allows the matrices to have color on them */ - glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT ); - glClear(GL_COLOR_BUFFER_BIT); + glPushAttrib( GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /************************** **** RENDER STUFF HERE **** @@ -636,7 +637,6 @@ void render(){ if(ui::mouse.x > player->loc.x && ui::mouse.y < player->loc.y+player->height/2 && handAngle <= 0) handAngle = 360 + handAngle; - /* * Draw the player's inventory. */ diff --git a/src/entities.cpp b/src/entities.cpp index e97464e..5a92c48 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -31,7 +31,7 @@ const char *randomDialog[RAND_DIALOG_COUNT] = { "Frig.", "The sine of theta equals the opposite over the hypotenuese.", "Did you know the developers spelt brazier as brazzier.", - "My dad once said to me, \"Boy, you are in a game.\" I never knew what he meant by that." + "What's a bagel? I don't know because I'm mormon" }; void initEntity(){ @@ -171,6 +171,8 @@ Merchant::Merchant(){ //sets all of the Merchant specific traits on object creat trade.reserve(100); currTrade = 0; + inside = nullptr; + //tex = new Texturec(1,"assets/NPC.png"); //inv = new Inventory(NPC_INV_SIZE); //inv = new Inventory(1); @@ -183,7 +185,7 @@ Merchant::~Merchant(){ /*while(!aiFunc.empty()){ aiFunc.pop_back(); }*/ - + delete inside; //delete inv; //delete tex; //delete[] name; @@ -459,6 +461,29 @@ void NPC::interact(){ //have the npc's interact back to the player }).detach(); } +void Merchant::wander(int timeRun){ + static int direction; + if ( ticksToUse == 0 ) { + ticksToUse = timeRun; + + vel.x = .008 * HLINE; + direction = (getRand() % 3 - 1); + + if ( direction == 0 ) + ticksToUse *= 2; + + vel.x *= direction; + } + + if( vel.x < 0) + currentWorld->goWorldLeft( this ); + if(inside != nullptr){ + if(loc.x <= inside->loc.x)loc.x = inside->loc.x; + if(loc.x + width >= inside->loc.x + inside->width)loc.x = inside->loc.x + inside->width - width; + } + ticksToUse--; +} + void Merchant::interact(){ 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"); diff --git a/src/world.cpp b/src/world.cpp index cdd945b..d8fd2d3 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -401,9 +401,7 @@ bgmPlay( World *prev ) const * screen. */ -void World:: -draw( Player *p ) -{ +void World::draw(Player *p){ // iterators int i, iStart, iEnd; @@ -1631,6 +1629,7 @@ loadWorldFromXMLNoSave( std::string path ) { vil->StrAttribute("texture"), vil->StrAttribute("inside")); tmp->addMerchant(0,100); + tmp->merchant.back()->inside = tmp->build.back(); if(vil->FirstChildElement("buy")){ std::cout << "Buy" << std::endl; }if(vil->FirstChildElement("sell")){ diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index 86ee397..d3b5db4 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -16,7 +16,7 @@ - + -- 2.39.5