From: drumsetmonkey Date: Tue, 23 Feb 2016 12:29:25 +0000 (-0500) Subject: Villages! X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=f67648a124655305c3e8947fe312b97ccf74e2fd;p=clyne%2Fgamedev.git Villages! --- f67648a124655305c3e8947fe312b97ccf74e2fd diff --cc assets/style/classic/bg/bgWoodTile.png index 0000000,0000000..5b631bf new file mode 100644 Binary files differ diff --cc assets/style/classic/bg/forestTileFar.png index 0000000,0000000..241e479 new file mode 100644 Binary files differ diff --cc assets/style/rustic/bg/bgWoodTile.png index 0000000,0000000..5b631bf new file mode 100644 Binary files differ diff --cc assets/style/rustic/bg/forestTileFar.png index 0000000,0000000..241e479 new file mode 100644 Binary files differ diff --cc include/common.h index f141afd,34260c9..a99e352 --- a/include/common.h +++ b/include/common.h @@@ -16,7 -16,6 +16,8 @@@ #include #include #include +#include ++#include #define GLEW_STATIC #include diff --cc include/ui.h index 8d479a4,ccc16af..a3084eb --- a/include/ui.h +++ b/include/ui.h @@@ -50,6 -50,6 +50,12 @@@ public std::vectoritems; Menu *child; Menu *parent; ++ ~Menu(){ ++ child = NULL; ++ parent = NULL; ++ delete child; ++ delete parent; ++ } void gotoChild(); void gotoParent(); @@@ -147,6 -146,6 +153,7 @@@ namespace ui */ void importantText(const char *text,...); ++ void passiveImportantText(int duration,const char *text,...); /* * Draw various UI elements (dialogBox, player health) diff --cc include/world.h index edf7ebb,48ab409..f9e952e --- a/include/world.h +++ b/include/world.h @@@ -81,23 -81,6 +81,26 @@@ typedef struct line_t unsigned char color; /**< Lightness of dirt (brown) */ } line_t; +/* + * Handle all logic that has to do with villages + */ + + +struct Village{ + std::string name; ++ vec2 start; ++ vec2 end; ++ bool in; + - std::vector> entity; - std::vector> build; - std::vector> npc; - ++ std::vector build; + Village(const char *meme){ + name = meme; ++ end.x = -0xffffffff; ++ start.x = 0xffffffff; ++ in = false; + } +}; + /** * The world class. This class does everything a world should do. */ diff --cc main.cpp index eb53c99,805fa00..ecff5c6 --- a/main.cpp +++ b/main.cpp @@@ -569,7 -573,7 +574,8 @@@ void render() glMatrixMode(GL_PROJECTION); 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((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); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); diff --cc src/entities.cpp index e020f8b,71a0890..922a07c --- a/src/entities.cpp +++ b/src/entities.cpp @@@ -62,7 -62,7 +62,7 @@@ void Entity::spawn(float x, float y){ / right = true; left = false; near = false; -- canMove = true; ++ //canMove = true; ground = false; hit = false; @@@ -88,6 -88,6 +88,8 @@@ Player::Player(){ //sets all of the pla subtype = 0; health = maxHealth = 100; speed = 1; ++ canMove = true; ++ tex = new Texturec(9, "assets/player/playerk.png", "assets/player/playerk1.png", "assets/player/playerk2.png", @@@ -115,6 -115,6 +117,7 @@@ NPC::NPC(){ //sets all of the NPC speci health = maxHealth = 100; maxHealth = health = 100; ++ canMove = true; tex = new Texturec(1,"assets/NPC.png"); inv = new Inventory(NPC_INV_SIZE); @@@ -141,6 -141,6 +144,7 @@@ Structures::Structures(){ //sets the st name = NULL; inv = NULL; ++ canMove = false; } Structures::~Structures(){ delete tex; @@@ -155,6 -155,6 +159,7 @@@ Mob::Mob(int sub) aggressive = false; maxHealth = health = 50; ++ canMove = true; switch((subtype = sub)){ case MS_RABBIT: @@@ -198,6 -198,6 +203,7 @@@ Object::Object() near = false; width = 0; height = 0; ++ canMove = false; maxHealth = health = 1; @@@ -267,7 -267,7 +273,7 @@@ void Entity::draw(void){ //draws the e switch(type){ case PLAYERT: static int texState = 0; -- if(speed && !(loops % (int)(2.0f/(float)speed))){ ++ if(speed && !(loops % ((2.0f/speed) < 1 ? 1 : (int)((float)2.0f/(float)speed)))){ if(++texState==9)texState=1; glActiveTexture(GL_TEXTURE0); tex->bind(texState); diff --cc src/ui.cpp index 43706e7,2d00453..6e616a7 --- a/src/ui.cpp +++ b/src/ui.cpp @@@ -113,8 -114,6 +113,9 @@@ namespace ui bool debug=false; bool posFlag=false; + bool dialogPassive = false; ++ int dialogPassiveTime = 0; + /* * Dialog stuff that needs to be 'public'. @@@ -545,6 -544,6 +546,24 @@@ dialogImportant = true; //toggleBlack(); } ++ void passiveImportantText(int duration, const char *text,...){ ++ va_list textArgs; ++ ++ //if(!player->ground)return; ++ ++ memset(dialogBoxText,0,512); ++ ++ va_start(textArgs,text); ++ vsnprintf(dialogBoxText,512,text,textArgs); ++ va_end(textArgs); ++ ++ dialogBoxExists = true; ++ dialogImportant = true; ++ dialogPassive = true; ++ dialogPassiveTime = duration; ++ } ++ ++ void draw(void){ unsigned char i; float x,y,tmp; @@@ -556,10 -555,9 +575,18 @@@ if(dialogImportant){ setFontColor(255,255,255); - if(fadeIntensity == 255){ ++ if(dialogPassive){ ++ dialogPassiveTime -= deltaTime; ++ if(dialogPassiveTime < 0){ ++ dialogPassive = false; ++ dialogImportant = false; ++ dialogBoxExists = false; ++ } ++ } + if(fadeIntensity == 255 || dialogPassive){ setFontSize(24); putStringCentered(offset.x,offset.y,rtext); + setFontSize(16); } }else{ @@@ -646,6 -644,6 +673,9 @@@ } void quitGame(){ ++ dialogBoxExists = false; ++ currentMenu = NULL; ++ delete[] currentMenu; gameRunning = false; updateConfig(); saveConfig(); diff --cc src/world.cpp index d039bca,51efaf2..6e72328 --- a/src/world.cpp +++ b/src/world.cpp @@@ -82,18 -95,18 +82,18 @@@ void World::setStyle(const char* pre) for(uint i = 0; i < arrAmt(buildPaths);i++){ sTexLoc.push_back(prefix); sTexLoc.back() += buildPaths[i]; -- std::cout << sTexLoc.back() << std::endl; ++ //std::cout << sTexLoc.back() << std::endl; } prefix += "bg/"; for(uint i = 0; i < arrAmt(bgPaths[0]);i++){ bgFiles.push_back(prefix); bgFiles.back() += bgPaths[0][i]; -- std::cout << bgFiles.back() << std::endl; ++ //std::cout << bgFiles.back() << std::endl; } for(uint i = 0; i < arrAmt(bgPaths[1]);i++){ bgFilesIndoors.push_back(prefix); bgFilesIndoors.back() += bgPaths[1][i]; -- std::cout << bgFilesIndoors.back() << std::endl; ++ //std::cout << bgFilesIndoors.back() << std::endl; } } @@@ -940,17 -952,13 +937,13 @@@ void World::singleDetect(Entity *e) } void World::detect(Player *p){ - //static std::thread villageThread; -- World *hey = this; /* * Handle the player. */ -- singleDetect(p); - //villageLogic(this); - //villageThread = std::thread(villageLogic, this); - ++ //auto pl = std::async(&World::singleDetect,this,p); ++ std::thread(&World::singleDetect,this, p).detach(); /* * Handle all remaining entities in this world. @@@ -958,8 -966,8 +951,9 @@@ //LOOOOP: static int what = 0; -- for(auto &e : hey->entity) -- hey->singleDetect(e); ++ for(auto &e : entity) ++ std::thread(&World::singleDetect,this,e).detach(); ++ //hey->singleDetect(e); for(auto &part : particles){ int l; unsigned int i; @@@ -977,39 -985,11 +971,50 @@@ } what++; }what=0; + for(auto &b : build){ + switch(b->bsubtype){ + case FOUNTAIN: + for(int r = 0; r < (rand()%25)+10;r++){ + addParticle( rand()%HLINE*3 + b->loc.x + b->width/2, + b->loc.y + b->height, + HLINE*1.25, + HLINE*1.25, + rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01, + ((4+rand()%6)*.05), + {0,0,255}, + 2500); + + particles.back()->fountain = true; + } + break; + case FIRE_PIT: + for(int r = 0; r < (rand()%20)+10;r++){ + addParticle(rand()%(int)(b->width/2) + b->loc.x+b->width/4, b->loc.y+3*HLINE, HLINE, HLINE, rand()%2 == 0?-(rand()%3)*.01:(rand()%3)*.01,((4+rand()%6)*.005), {255,0,0}, 400); + particles.back()->gravity = false; + particles.back()->behind = true; + } + break; + default: break; + } + } + ++ for(auto &v : village){ ++ if(p->loc.x > v.start.x && p->loc.x < v.end.x){ ++ if(!v.in){ ++ ui::passiveImportantText(5000,"Welcome to %s",v.name.c_str()); ++ v.in = true; ++ } ++ }else{ ++ v.in = false; ++ } ++ } ++ /*if(hey->infront){ hey = hey->infront; goto LOOOOP; }*/ - //villageThread.join(); } ++ void World::addStructure(BUILD_SUB sub, float x,float y, char *tex, const char *inside){ build.push_back(new Structures()); build.back()->inWorld = this; @@@ -1494,12 -1474,20 +1499,21 @@@ char *currentXML = NULL extern World *currentWorld; World *loadWorldFromXML(const char *path){ + if(currentXML){ + currentWorld->save(); + delete[] currentXML; + } + + return loadWorldFromXMLNoSave(path); + } + + World *loadWorldFromXMLNoSave(const char *path){ XMLDocument xml; XMLElement *wxml; + XMLElement *vil; World *tmp; -- float spawnx; ++ float spawnx, randx; bool dialog,Indoor; const char *ptr,*name; @@@ -1600,26 -1578,9 +1604,44 @@@ tmp->addMob(MS_TRIGGER,wxml->FloatAttribute("x"),0,commonTriggerFunc); tmp->mob.back()->heyid = wxml->Attribute("id"); } - + wxml = wxml->NextSiblingElement(); } + ++ if(vil){ ++ tmp->village.push_back(vil->Attribute("name")); ++ ++ vil = vil->FirstChildElement(); ++ } ++ + while(vil){ + name = vil->Name(); ++ randx = getRand() % tmp->getTheWidth() - (tmp->getTheWidth() / 2.0f); ++ ++ /** ++ * READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE ++ */ + if(!strcmp(name,"structure")){ + ptr = vil->Attribute("inside"); + tmp->addStructure((BUILD_SUB)vil->UnsignedAttribute("type"), - vil->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR ? - getRand() % tmp->getTheWidth() / 2.0f : - spawnx, ++ vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ? ++ randx : spawnx, + 100, + (char*)vil->Attribute("texture"), + ptr); + - //tmp->village.back().build.push_back(tmp->build.back()); ++ tmp->village.back().build.push_back(tmp->build.back()); ++ } ++ if(tmp->village.back().build.back()->loc.x < tmp->village.back().start.x){ ++ tmp->village.back().start.x = tmp->village.back().build.back()->loc.x; + } ++ if(tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width > tmp->village.back().end.x){ ++ tmp->village.back().end.x = tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width; ++ } ++ ++ //go to the next element in the village block + vil = vil->NextSiblingElement(); + } std::ifstream dat (((std::string)currentXML + ".dat").c_str()); if(dat.good()){ diff --cc xml/playerSpawnHill1.xml index b0fb163,c5e736b..269b393 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@@ -10,11 -10,7 +10,11 @@@ -- ++ + - - ++ ++ +