From 4df411931dd63f22258be76911e0648c3cdc3936 Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Fri, 26 Feb 2016 08:28:48 -0500 Subject: Merchants kinda work... --- src/entities.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'src/entities.cpp') diff --git a/src/entities.cpp b/src/entities.cpp index 6c2da81..afcc9ad 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -3,7 +3,7 @@ #include -#define RAND_DIALOG_COUNT 13 +#define RAND_DIALOG_COUNT 14 extern std::istream *names; extern unsigned int loops; @@ -125,6 +125,7 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation randDialog = rand() % RAND_DIALOG_COUNT - 1; dialogIndex = 0; } + NPC::~NPC(){ while(!aiFunc.empty()){ aiFunc.pop_back(); @@ -135,6 +136,36 @@ NPC::~NPC(){ delete[] name; } +Merchant::Merchant(){ //sets all of the Merchant specific traits on object creation + width = HLINE * 10; + height = HLINE * 16; + + type = MERCHT; //sets type to merchant + subtype = 0; + + health = maxHealth = 100; + + maxHealth = health = 100; + canMove = true; + + //tex = new Texturec(1,"assets/NPC.png"); + //inv = new Inventory(NPC_INV_SIZE); + inv = NULL; + + //randDialog = rand() % RAND_DIALOG_COUNT - 1; + dialogIndex = 0; +} + +Merchant::~Merchant(){ + while(!aiFunc.empty()){ + aiFunc.pop_back(); + } + + delete inv; + delete tex; + delete[] name; +} + Structures::Structures(){ //sets the structure type health = maxHealth = 1; @@ -143,7 +174,7 @@ Structures::Structures(){ //sets the structure type name = NULL; - inv = NULL; + //inv = NULL; canMove = false; } Structures::~Structures(){ @@ -401,7 +432,8 @@ const char *randomDialog[RAND_DIALOG_COUNT] = { "I want to have the wallpaper in our house changed. It doesn\'t really fit the environment.", "Frig.", "The sine of theta equals the opposite over the hypotenuese.", - "Did you know the developers spelt brazier as brazzier." + "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." }; void NPC::interact(){ //have the npc's interact back to the player @@ -425,6 +457,10 @@ void NPC::interact(){ //have the npc's interact back to the player canMove=true; } +void Merchant::interact(){ + ui::merchantBox(name, ":Accept:Good Bye", false, "Welcome to smithy\'s. Buy your sausages here you freaking mean lording screw-face"); +} + void Object::interact(void){ if(questObject && alive){ ui::dialogBox(player->name,":Yes:No",false,pickupDialog); @@ -468,11 +504,18 @@ unsigned int Structures::spawn(BUILD_SUB sub, float x, float y){ //unsigned int tempN = (getRand() % 5 + 2); switch(sub){ + case STALL_MARKET: + tex = new Texturec(1, textureLoc ? textureLoc : inWorld->sTexLoc[sub].c_str()); + dim = Texture::imageDim(textureLoc ? textureLoc : inWorld->sTexLoc[sub].c_str()); + width = dim.x; + height = dim.y; + break; default: tex = new Texturec(1, textureLoc ? textureLoc : inWorld->sTexLoc[sub].c_str()); dim = Texture::imageDim(textureLoc ? textureLoc : inWorld->sTexLoc[sub].c_str()); width = dim.x; height = dim.y; + inv = NULL; break; } return 0; -- cgit v1.2.3 From 6241707a788269e09adb957c659397750d19fda3 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 29 Feb 2016 08:31:49 -0500 Subject: world rewrite -- fixed all world stuffs --- include/world.h | 4 +- main.cpp | 11 ++--- src/entities.cpp | 2 +- src/gameplay.cpp | 6 +-- src/world.cpp | 104 +++++++++++++++++++++++------------------------ xml/playerSpawnHill1.xml | 2 +- 6 files changed, 64 insertions(+), 65 deletions(-) (limited to 'src/entities.cpp') diff --git a/include/world.h b/include/world.h index f60c181..05b2a10 100644 --- a/include/world.h +++ b/include/world.h @@ -63,7 +63,7 @@ typedef struct { typedef struct { bool grassUnpressed; - int grassHeight[2]; + float grassHeight[2]; float groundHeight; unsigned char groundColor; } WorldData; @@ -481,7 +481,7 @@ public: }; extern int worldShade; -extern char *currentXML; +extern std::string currentXML; World *loadWorldFromXML(const char *path); World *loadWorldFromXMLNoSave(const char *path); diff --git a/main.cpp b/main.cpp index abea578..885c610 100644 --- a/main.cpp +++ b/main.cpp @@ -486,13 +486,14 @@ void mainLoop(void){ * Update debug variables if necessary */ - if(++debugDiv==20) + if ( ++debugDiv == 20 ) { debugDiv=0; - if(deltaTime) - fps=1000/deltaTime; - else if(!(debugDiv%10)) - debugY = player->loc.y; + if ( deltaTime ) + fps = 1000 / deltaTime; + else if(!(debugDiv%10)) + debugY = player->loc.y; + } MENU: render(); } diff --git a/src/entities.cpp b/src/entities.cpp index 6c2da81..98bba8b 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -564,7 +564,7 @@ void Player::save(void){ for(auto &i : inv->items) data.append(std::to_string((int)i.count) + "\n" + std::to_string((int)i.id) + "\n"); - data.append((std::string)(currentXML+4) + "\n"); + data.append((std::string)(currentXML.c_str() + 4) + "\n"); data.append("dOnE\0"); out.write(data.c_str(),data.size()); diff --git a/src/gameplay.cpp b/src/gameplay.cpp index d983804..95b95d6 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -43,7 +43,7 @@ int commonAIFunc(NPC *speaker){ * Load the current world's XML file into memory for reading. */ - xml.LoadFile(currentXML); + xml.LoadFile(currentXML.c_str()); exml = xml.FirstChildElement("Dialog"); /* @@ -222,7 +222,7 @@ void commonTriggerFunc(Mob *callee){ if(!lock){ lock = true; - xml.LoadFile(currentXML); + xml.LoadFile(currentXML.c_str()); exml = xml.FirstChildElement("Trigger"); while(strcmp(exml->Attribute("id"),callee->heyid.c_str())) @@ -321,7 +321,7 @@ extern std::vector AIpreaddr; void destroyEverything(void){ currentWorld->save(); delete currentWorld; - delete[] currentXML; + //delete[] currentXML; while(!AIpreload.empty()) AIpreload.pop_back(); diff --git a/src/world.cpp b/src/world.cpp index 57b5ff5..76dccb8 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -246,7 +246,7 @@ generate( unsigned int width ) // give every GROUND_HILLINESSth entry a groundHeight value for(unsigned int i = GROUND_HILLINESS; i < worldData.size(); i += GROUND_HILLINESS, wditer += GROUND_HILLINESS) - worldData[i].groundHeight = (*wditer).groundHeight + (randGet() % 12 - 6); + worldData[i].groundHeight = (*wditer).groundHeight + (randGet() % 8 - 4); // create slopes from the points that were just defined, populate the rest of the WorldData structure @@ -261,9 +261,14 @@ generate( unsigned int width ) (*wditer).grassHeight[0] = (randGet() % 16) / 3 + 2; (*wditer).grassHeight[1] = (randGet() % 16) / 3 + 2; - // dirty fix for bug -- please fix the bug - if( (*wditer).groundHeight <= 0 ) - (*wditer).groundHeight = (*(wditer - 1)).groundHeight; + // bound checks + if ( (*wditer).groundHeight < GROUND_HEIGHT_MINIMUM ) + (*wditer).groundHeight = GROUND_HEIGHT_MINIMUM; + else if ( (*wditer).groundHeight > GROUND_HEIGHT_MAXIMUM ) + (*wditer).groundHeight = GROUND_HEIGHT_MAXIMUM; + + if( (*wditer).groundHeight <= 0 ) + (*wditer).groundHeight = GROUND_HEIGHT_MINIMUM; } // define x-coordinate of world's leftmost 'line' @@ -303,26 +308,26 @@ update( Player *p, unsigned int delta ) } // iterate through particles - for ( std::vector::iterator pi = particles.begin(); pi != particles.end(); pi++ ) { - if ( (*pi)->kill(delta) ) { - //delete[] (*pi); - particles.erase(pi); - } else if ( (*pi)->canMove ) { - (*pi)->loc.x += (*pi)->velx * delta; - (*pi)->loc.y += (*pi)->vely * delta; - - for ( auto &b : build ) { - if ( b->subtype == FOUNTAIN ) { - if ( (*pi)->loc.x >= b->loc.x && (*pi)->loc.x <= b->loc.x + b->width ) { - if ( (*pi)->loc.y <= b->loc.y + b->height * 0.25f ) { - //delete[] (*pi); - particles.erase(pi); - } - } - } - } - } - } + for(unsigned int i=0;ikill(deltaTime)){ + delete particles[i]; + particles.erase(particles.begin()+i); + }else if(particles[i]->canMove){ + particles[i]->loc.y += particles[i]->vely * deltaTime; + particles[i]->loc.x += particles[i]->velx * deltaTime; + + for(auto &b : build){ + if(b->bsubtype==FOUNTAIN){ + if(particles[i]->loc.x >= b->loc.x && particles[i]->loc.x <= b->loc.x + b->width){ + if(particles[i]->loc.y <= b->loc.y + b->height * .25){ + delete particles[i]; + particles.erase(particles.begin()+i); + } + } + } + } + } + } // handle music fades if ( ui::dialogImportant ) @@ -394,7 +399,7 @@ draw( Player *p ) int i, iStart, iEnd; // shade value for draws -- may be unnecessary - int shadeBackground = worldShade; + int shadeBackground = 0; // player's offset in worldData[] int pOffset; @@ -532,8 +537,8 @@ draw( Player *p ) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glUseProgram( shaderProgram ); - glUniform1i( glGetUniformLocation( shaderProgram, "sampler"), 0); - glUniform1f( glGetUniformLocation( shaderProgram, "amb" ), 0.5f ); + glUniform1i( glGetUniformLocation( shaderProgram, "sampler"), 0 ); + glUniform1f( glGetUniformLocation( shaderProgram, "amb" ), 1 ); if ( p->light ) { pointArray[light.size() + 1][0] = (float)( p->loc.x + SCREEN_WIDTH / 2 ); @@ -561,8 +566,8 @@ draw( Player *p ) glTexCoord2i(0 ,1);glVertex2i(pOffset - (SCREEN_WIDTH / 1.5),GROUND_HEIGHT_MINIMUM);*/ for ( i = iStart; i < iEnd; i++ ) { - if ( !worldData[i].groundHeight ) { - worldData[i].groundHeight = GROUND_HEIGHT_MINIMUM; + if ( worldData[i].groundHeight <= 0 ) { + worldData[i].groundHeight = GROUND_HEIGHT_MINIMUM - 1; glColor4ub( 0, 0, 0, 255 ); } else safeSetColorA( 150, 150, 150, 255 ); @@ -573,7 +578,7 @@ draw( Player *p ) glTexCoord2i( 1, (int)(worldData[i].groundHeight / 64) + worldData[i].groundColor ); glVertex2i(worldStart + i * HLINE + HLINE, 0 ); glTexCoord2i( 0, (int)(worldData[i].groundHeight / 64) + worldData[i].groundColor ); glVertex2i(worldStart + i * HLINE , 0 ); - if ( worldData[i].groundHeight == GROUND_HEIGHT_MINIMUM ) + if ( worldData[i].groundHeight == GROUND_HEIGHT_MINIMUM - 1 ) worldData[i].groundHeight = 0; } @@ -1004,16 +1009,17 @@ World *World::goWorldRight(Player *p){ return this; } -std::vectorinside; -World *World::goInsideStructure(Player *p){ +std::vector inside; +World *World:: +goInsideStructure( Player *p ) +{ World *tmp; char *current; if(inside.empty()){ for(auto &b : build){ if(p->loc.x > b->loc.x && p->loc.x + p->width < b->loc.x + b->width ){ - inside.push_back(new char[1 + strlen(currentXML)]); - strcpy(inside.back(),(char *)(currentXML+4)); + inside.push_back((std::string)(currentXML.c_str() + 4)); tmp = loadWorldFromXML(b->inside); @@ -1025,12 +1031,11 @@ World *World::goInsideStructure(Player *p){ } } }else{ - strcpy((current = new char[strlen((char *)(currentXML + 4)) + 1]),(char *)(currentXML + 4)); - tmp = loadWorldFromXML(inside.back()); + strcpy((current = new char[strlen((const char *)(currentXML.c_str() + 4)) + 1]),(const char *)(currentXML.c_str() + 4)); + tmp = loadWorldFromXML(inside.back().c_str()); for(auto &b : tmp->build){ if(!strcmp(current,b->inside)){ p->loc.x = b->loc.x + (b->width / 2); - delete[] inside.back(); inside.pop_back(); ui::toggleBlackFast(); @@ -1301,16 +1306,14 @@ World *Arena::exitArena(Player *p){ #include using namespace tinyxml2; -char *currentXML = NULL; +std::string currentXML = "\0"; extern World *currentWorld; World *loadWorldFromXML(const char *path){ - if(currentXML){ + if ( currentXML != "\0" ) currentWorld->save(); - delete[] currentXML; - } - + return loadWorldFromXMLNoSave(path); } @@ -1324,25 +1327,20 @@ World *loadWorldFromXMLNoSave(const char *path){ bool dialog,Indoor; const char *ptr,*name; - - unsigned int size = 5 + strlen(path); + + currentXML = (std::string)"xml/" + path; - if(currentXML) - delete[] currentXML; - memset((currentXML = new char[size]),0,size); - strcpy(currentXML,"xml/"); - strcat(currentXML,path); - - xml.LoadFile(currentXML); + xml.LoadFile(currentXML.c_str()); wxml = xml.FirstChildElement("World"); - vil = xml.FirstChildElement("World")->FirstChildElement("village"); - + if(wxml){ wxml = wxml->FirstChildElement(); + vil = xml.FirstChildElement("World")->FirstChildElement("village"); Indoor = false; tmp = new World(); }else if((wxml = xml.FirstChildElement("IndoorWorld"))){ wxml = wxml->FirstChildElement(); + vil = NULL; Indoor = true; tmp = new IndoorWorld(); } diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index 269b393..ee2c46a 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -1,7 +1,7 @@