From 9757c1c7e8704080c4e20cde442baf06960e98e7 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 1 Oct 2015 08:24:30 -0400 Subject: world stuff in sep. file --- src/Quest.cpp | 12 +++++++++- src/entities.cpp | 1 - src/gameplay.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 46 +++++++------------------------------- 4 files changed, 86 insertions(+), 40 deletions(-) create mode 100644 src/gameplay.cpp (limited to 'src') diff --git a/src/Quest.cpp b/src/Quest.cpp index c9175b1..28aade2 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -49,7 +49,7 @@ int QuestHandler::drop(const char *t){ int QuestHandler::finish(const char *t){ unsigned char i; unsigned int r; - for(;ititle,t)){ r=current[i]->reward; current.erase(current.begin()+i); @@ -58,3 +58,13 @@ int QuestHandler::finish(const char *t){ } return -1; } + +bool QuestHandler::hasQuest(const char *t){ + unsigned int i; + for(i=0;ititle,t)){ + return true; + } + } + return false; +} diff --git a/src/entities.cpp b/src/entities.cpp index 8ccd5e1..9f5d776 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -66,7 +66,6 @@ void Entity::getName(){ strcpy(name,bufs); } free(bufs); - //delete(bufs); } Player::Player(){ //sets all of the player specific traits on object creation diff --git a/src/gameplay.cpp b/src/gameplay.cpp new file mode 100644 index 0000000..b32c75a --- /dev/null +++ b/src/gameplay.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include + +extern World *currentWorld; +extern std::vectorentity; +extern std::vectornpc; +extern std::vectorbuild; +extern Player *player; + +int giveTestQuest(NPC *speaker){ + ui::dialogBox("Here, have a quest!"); + player->qh.assign("Test"); + return 0; +} + +int compTestQuest(NPC *speaker){ + if(player->qh.hasQuest("Test")){ + ui::dialogBox("Ooo, that's a nice quest you got there. Lemme finish that for you ;)."); + player->qh.finish("test"); + return 0; + }else{ + ui::dialogBox("You need to get a quest from entity[1] first."); + return 1; + } +} + +void initEverything(void){ + unsigned int i; + + World *test=new World(); + test->generate(SCREEN_WIDTH/2); + test->addLayer(400); + test->addLayer(100); + test->addPlatform(150,100,100,10); + test->addHole(100,150); + currentWorld=test; + + // Make the player + player=new Player(); + player->spawn(0,100); + + // Make structures + entity.push_back(new Entity()); + build.push_back(new Structures()); + entity[0]=build[0]; + + build[0]->spawn(STRUCTURET,0,10); + IndoorWorld *iw=new IndoorWorld(); + iw->generate(200); + build[0]->inside=iw; + + for(i=0;iinWorld=test; + switch(i){ + case 1: + NPCp(entity[i])->addAIFunc(giveTestQuest); + break; + case 2: + NPCp(entity[i])->addAIFunc(compTestQuest); + break; + default: + break; + } + } +} diff --git a/src/main.cpp b/src/main.cpp index c1b22af..d454f0b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,15 +28,11 @@ std::vectorbuild; int mx, my; FILE* names; +extern void initEverything(void); + void logic(); void render(); -int entityInteractTest(NPC *speaker){ - ui::dialogBox("Here, have a quest!"); - player->qh.assign("Test"); - return 1; -} - unsigned int millis(void){ std::chrono::system_clock::time_point now=std::chrono::system_clock::now(); return std::chrono::duration_cast(now.time_since_epoch()).count(); @@ -84,49 +80,23 @@ int main(int argc, char *argv[]){ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); SDL_ShowCursor(SDL_DISABLE); - - /************************** - **** GAMELOOP **** - **************************/ //************************************************************************// // WORLD GENERATION STUFF // //************************************************************************// names = fopen("assets/names_en-us", "r+"); - // Make a world - World *test=new World(); - test->generate(SCREEN_WIDTH/2); - test->addLayer(400); - test->addLayer(100); - test->addPlatform(150,100,100,10); - test->addHole(100,150); - currentWorld=test; - - IndoorWorld *iw=new IndoorWorld(); - iw->generate(200); - - // Make the player - player=new Player(); - player->spawn(0,100); - // Make structures - entity.push_back(new Entity()); - build.push_back(new Structures()); - entity[0]=build[0]; - - static unsigned int i; - build[0]->spawn(STRUCTURET,0,10); - build[0]->inside=iw; - for(i=0;iinWorld=test; - } - - NPCp(entity[1])->addAIFunc(entityInteractTest); + initEverything(); //************************************************************************// // END WORLD GENERATION STUFF // //************************************************************************// + + /************************** + **** GAMELOOP **** + **************************/ + currentTime=millis(); while(gameRunning){ prevTime = currentTime; -- cgit v1.2.3