From 272a152b54a198a84f122ab8bedb1019708b7008 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 21 Dec 2015 08:46:35 -0500 Subject: [PATCH] pages, quests --- Changelog | 8 +++++++ assets/items/ITEM_PAGE.png | Bin 331 -> 349 bytes include/common.h | 17 ++++++++++++++ include/world.h | 6 +++++ main.cpp | 12 ++++++---- src/common.cpp | 17 ++++++++++++++ src/entities.cpp | 44 +++++++++++++++++-------------------- src/gameplay.cpp | 37 +++++++++++++++++-------------- src/ui.cpp | 15 +++++++------ src/world.cpp | 8 +++++++ xcf/page.xcf | Bin 1059 -> 1059 bytes 11 files changed, 112 insertions(+), 52 deletions(-) diff --git a/Changelog b/Changelog index 44ff8a4..c0d2b9e 100644 --- a/Changelog +++ b/Changelog @@ -452,3 +452,11 @@ - began working on pages, made sprite and handler - GLSL shaders are better - redid theme_jazz + +12/21/2015: +=========== + + - fixed dialog options issues, finished basic pages + - added World::getAvailableNPC() for easy quest assigner assigning + - added the Condition class, so that events and actions can be remembered by NPCs + - added functionality for multiple lights (GLSL) diff --git a/assets/items/ITEM_PAGE.png b/assets/items/ITEM_PAGE.png index ac132c63bdf361b3704ca7b6887e0d20a2f63373..4602afec4bad3d6be9a94883e6be3607ae898c82 100644 GIT binary patch delta 248 zcmV|2o((oE8#Y-?U6|_e_aa0AP|IS zN^Y=^g&d)f`yWEcJv_tqr8T-$qbLMQ=E?kiGwZrkRa~J5F47IY!T$$dX8(|6Sl4C* zXAO`T2tdym$xV{U8>-4iVDg>!KCDF~3tudBcP?whnuwppAS>@ZL_`7bCvgsH_1d=N zdUp=bb#2}X5lPJRTc#ScQf8u-wgx8v?SYOO`0V+SxHomlM2i6tIl3)wmKg?4PlIi9 yd!$B8luW5As{>@T3c2*5xmqTdtwN7VL+B0h_i;k?LIKPG0000JhW~%@27O%O5texWLy&lno}qi$5Lg9_Bqob}LPfr>P)aky74g7Daf5I0 z|AD8`3zCfET94qU29g2+Sc{RpB$>@HGj;;A|5P=OMZ|?qC3FqJ6)7dsZz-q@RfUKc z0RCj`LCbh8OZL2mfag4SABBiy^89X74O&u@sAXG&6M!9oo)!3<`Ihm~toI~(1Vm)3 zwzODA2sCd)S?1-HIxFHynHif6#1rWi^Rkb{b+&W0#P*ud8-urTLJ@apGXMYp07*qo IM6N<$f;|3g#Q*>R diff --git a/include/common.h b/include/common.h index 08ec73f..038bf42 100644 --- a/include/common.h +++ b/include/common.h @@ -141,6 +141,23 @@ extern vec2 offset; */ extern unsigned int loops; +/** + * This class contains a string for identification and a value. It can be used to + * save certain events for and decisions so that they can be recalled later. + */ + +class Condition { +private: + char *id; + void *value; +public: + Condition(const char *_id,void *val); + ~Condition(); + + bool sameID(const char *s); + void *getValue(void); +}; + /** * Prints a formatted debug message to the console, along with the callee's file and line * number. diff --git a/include/world.h b/include/world.h index 4b3a891..98ca54a 100644 --- a/include/world.h +++ b/include/world.h @@ -173,6 +173,12 @@ public: void addNPC(float x,float y); void addObject(ITEM_ID, bool, const char *, float, float); void addParticle(float, float, float, float, float, float, Color color, int); + + NPC *getAvailableNPC(void); + + /* + * Update coordinates of all entities. + */ void update(Player *p,unsigned int delta); diff --git a/main.cpp b/main.cpp index e5aba88..e6ff2eb 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,8 @@ The main game loop contains all of the global variables the game uses, and it runs the main game loop, the render loop, and the logic loop that control all of the entities. */ -#include // fopen +#include +#include #include #include @@ -123,7 +124,7 @@ Mix_Chunk *crickets; * referenced in src/entities.cpp for getting random names. */ -FILE *names; +std::istream *names; /* * loops is used for texture animation. It is believed to be passed to entity @@ -387,7 +388,10 @@ int main(/*int argc, char *argv[]*/){ * */ - names = fopen("assets/names_en-us", "r+"); + static std::filebuf fb; + fb.open("assets/names_en-us",std::ios::in); + names = new std::istream(&fb); + crickets=Mix_LoadWAV("assets/sounds/crickets.wav"); //Mix_Volume(2,25); @@ -427,7 +431,7 @@ int main(/*int argc, char *argv[]*/){ Mix_HaltMusic(); - fclose(names); + fb.close(); SDL_GL_DeleteContext(mainGLContext); SDL_DestroyWindow(window); diff --git a/src/common.cpp b/src/common.cpp index 7449a35..dbcef0b 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -11,6 +12,22 @@ unsigned int millis(void){ #endif // __WIN32__ +Condition::Condition(const char *_id,void *val){ + id = new char[strlen(_id)+1]; + strcpy(id,_id); + value = val; +} +Condition::~Condition(){ + delete[] id; +} + +bool Condition::sameID(const char *s){ + return !strcmp(id,s); +} +void *Condition::getValue(void){ + return value; +} + void DEBUG_prints(const char* file, int line, const char *s,...){ va_list args; printf("%s:%d: ",file,line); diff --git a/src/entities.cpp b/src/entities.cpp index 23a4ae6..3849040 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -1,9 +1,10 @@ #include #include +#include //#include -extern FILE* names; +extern std::istream *names; extern unsigned int loops; extern World *currentWorld; @@ -12,39 +13,30 @@ extern Player *player; extern const char *itemName; -extern - void getRandomName(Entity *e){ - int tempNum,max=0; + unsigned int tempNum,max=0; char *bufs; - rewind(names); + names->seekg(0,names->beg); - bufs = new char[16]; //(char *)malloc(16); + bufs = new char[32]; - for(;!feof(names);max++){ - fgets(bufs,16,(FILE*)names); - } + for(;!names->eof();max++) + names->getline(bufs,32); tempNum = rand() % max; - rewind(names); + names->seekg(0,names->beg); - for(int i=0;igetline(bufs,32); - switch(fgetc(names)){ + switch(bufs[0]){ + default : case 'm': e->gender = MALE; break; case 'f': e->gender = FEMALE;break; - default : break; } - if((fgets(bufs,16,(FILE*)names)) != NULL){ - bufs[strlen(bufs)] = '\0'; - strcpy(e->name,bufs); - if(e->name[strlen(e->name)-1] == '\n') - e->name[strlen(e->name)-1] = '\0'; - } + strcpy(e->name,bufs+1); delete[] bufs; } @@ -73,7 +65,7 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o } } - name = new char[16]; + name = new char[32]; getRandomName(this); } @@ -480,8 +472,12 @@ void Mob::wander(int timeRun){ } break; case MS_PAGE: - if(ui::mouse.x > loc.x && - ui::mouse.x < loc.x + width && + if(player->loc.x > loc.x - 100 && + player->loc.x < loc.x + 100 && + ui::mouse.x > loc.x && + ui::mouse.x < loc.x + width && + ui::mouse.y > loc.y - width / 2 && + ui::mouse.y < loc.y + width * 1.5 && SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){ if(speed != 666){ speed = 666; diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 1670929..7dbe98e 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -28,6 +28,10 @@ void story(Mob *callee){ callee->alive = false; } +/* + * Gens + */ + float gen_worldSpawnHill1(float x){ return (float)(pow(2,(-x+200)/5) + GEN_MIN); } @@ -42,7 +46,6 @@ float gen_worldSpawnHill3(float x){ */ void worldSpawnHill1_hillBlock(Mob *callee){ - std::cout<<"oi"; player->vel.x = 0; player->loc.x = callee->loc.x + callee->width; ui::dialogBox(player->name,NULL,false,"This hill seems to steep to climb up..."); @@ -52,7 +55,7 @@ void worldSpawnHill1_hillBlock(Mob *callee){ static Arena *a; void worldSpawnHill2_infoSprint(Mob *callee){ - ui::dialogBox(player->name,":Nah:Sure",false,"This page would like to take you somewhere."); + ui::dialogBox(player->name,":Sure:Nah",false,"This page would like to take you somewhere."); ui::waitForDialog(); switch(ui::dialogOptChosen){ case 1: @@ -75,19 +78,22 @@ void worldSpawnHill2_infoSprint(Mob *callee){ //ui::dialogBox("B-) ",NULL,true,"Press \'Shift\' to run!"); } -void worldSpawnHill3_itemGet(Mob *callee){ - ui::dialogBox("B-) ",NULL,true,"Right click to pick up items!"); - callee->alive = false; -} - -void worldSpawnHill3_itemSee(Mob *callee){ - ui::dialogBox("B-) ",NULL,true,"Press \'e\' to open your inventory!"); - callee->alive = false; +int worldSpawnHill2_Quest2(NPC *callee){ + ui::dialogBox(callee->name,NULL,false,"Yo."); + ui::waitForDialog(); + return 0; } -void worldSpawnHill3_leave(Mob *callee){ - ui::dialogBox("B-) ",NULL,true,"Now jump in this hole, and let your journey begin :)"); - callee->alive = false; +int worldSpawnHill2_Quest1(NPC *callee){ + ui::dialogBox(callee->name,":Cool.",false,"Did you know that I\'m the coolest NPC in the world?"); + ui::waitForDialog(); + if(ui::dialogOptChosen == 1){ + ui::dialogBox(callee->name,NULL,false,"Yeah, it is."); + currentWorld->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest2,true); + ui::waitForDialog(); + return 0; + } + return 1; } /* @@ -132,10 +138,6 @@ void initEverything(void){ worldSpawnHill3->generateFunc(1000,gen_worldSpawnHill3); worldSpawnHill3->setBackground(BG_FOREST); worldSpawnHill3->setBGM("assets/music/ozone.wav"); - worldSpawnHill3->addMob(MS_TRIGGER,-500,0,worldSpawnHill3_itemGet); - worldSpawnHill3->addMob(MS_TRIGGER,0,0,worldSpawnHill3_itemSee); - worldSpawnHill3->addObject(TEST_ITEM,false,"",-200,300); - worldSpawnHill3->addMob(MS_TRIGGER,650,0,worldSpawnHill3_leave); worldSpawnHill3->addHole(800,1000); worldSpawnHill1->toRight = worldSpawnHill2; @@ -162,6 +164,7 @@ void initEverything(void){ worldSpawnHill2_Building1->setBGM("assets/music/theme_jazz.wav"); worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill2_Building1); + worldSpawnHill2->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest1,false); player = new Player(); player->spawn(200,100); diff --git a/src/ui.cpp b/src/ui.cpp index 6069ef9..f73f48a 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -300,7 +300,8 @@ namespace ui { } }while(s[++i]); - return putString(x-width/2,y,s); + putString(x-width/2,y,s); + return width; } /* @@ -487,7 +488,7 @@ namespace ui { } void draw(void){ unsigned char i; - float x,y; + float x,y,tmp; char *rtext; if(dialogBoxExists){ @@ -524,12 +525,12 @@ namespace ui { for(i=0;i dialogOptLoc[i][0] && - mouse.x < dialogOptLoc[i][0] + dialogOptLoc[i][2] && + mouse.x < dialogOptLoc[i][2] && mouse.y > dialogOptLoc[i][1] && mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize setFontColor(255,255,0); diff --git a/src/world.cpp b/src/world.cpp index 7f9b1c0..5663086 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -980,6 +980,14 @@ void World::addLayer(unsigned int width){ behind->bgTex=bgTex; } +NPC *World::getAvailableNPC(void){ + for(auto &n : npc){ + if(n->aiFunc.empty()) + return n; + } + return (NPC *)NULL; +} + World *World::goWorldLeft(Player *p){ if(toLeft&&p->loc.xloc.x=toLeft->x_start+getWidth(toLeft)-HLINE*10; diff --git a/xcf/page.xcf b/xcf/page.xcf index bf39c184b629e57eff4a95ca9b37e8c76c68dadc..72a34cfa10b89ac5b7152ffa37334894cdbce00f 100644 GIT binary patch delta 82 zcmZ3?v6y4SdnQ3<2BAxg4DA1z7Eq8 delta 82 zcmZ3?v6y4SdnQ2^2Ej{=3>^PC7+5a>+5g!mF{gqA&qD>z;})F!hFO=3gF*PeAOrh< GRt5lbGZei5 -- 2.39.5