]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world stuff in sep. file
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 1 Oct 2015 12:24:30 +0000 (08:24 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 1 Oct 2015 12:24:30 +0000 (08:24 -0400)
include/Quest.h
src/Quest.cpp
src/entities.cpp
src/gameplay.cpp [new file with mode: 0644]
src/main.cpp

index 076b8005f371676cac8a7fd1b7cfcde9b7f4fda9..c4b878046c11028883d519de2040bfe81e4f4359 100644 (file)
@@ -21,6 +21,7 @@ public:
        int assign(const char *t);\r
        int drop(const char *t);\r
        int finish(const char *t);\r
+       bool hasQuest(const char *t);\r
 };\r
 \r
 #endif // QUEST_H\r
index c9175b1cd93045f854a511ece58f87cd49f7125a..28aade2215702163bb2af5fe5489608e70d3306e 100644 (file)
@@ -49,7 +49,7 @@ int QuestHandler::drop(const char *t){
 int QuestHandler::finish(const char *t){\r
        unsigned char i;\r
        unsigned int r;\r
-       for(;i<current.size();i++){\r
+       for(i=0;i<current.size();i++){\r
                if(!strcmp(current[i]->title,t)){\r
                        r=current[i]->reward;\r
                        current.erase(current.begin()+i);\r
@@ -58,3 +58,13 @@ int QuestHandler::finish(const char *t){
        }\r
        return -1;\r
 }\r
+\r
+bool QuestHandler::hasQuest(const char *t){\r
+       unsigned int i;\r
+       for(i=0;i<current.size();i++){\r
+               if(!strcmp(current[i]->title,t)){\r
+                       return true;\r
+               }\r
+       }\r
+       return false;\r
+}\r
index 8ccd5e1ce87833692b009dc8923298f24a71df3c..9f5d776dba05f723e8397ba22a0929b7fc4fdb68 100644 (file)
@@ -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 (file)
index 0000000..b32c75a
--- /dev/null
@@ -0,0 +1,67 @@
+#include <common.h>
+#include <world.h>
+#include <ui.h>
+#include <entities.h>
+
+extern World *currentWorld;
+extern std::vector<Entity*>entity;
+extern std::vector<NPC>npc;
+extern std::vector<Structures *>build;
+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;i<entity.size()+1;i++){
+               entity[i]->inWorld=test;
+               switch(i){
+               case 1:
+                       NPCp(entity[i])->addAIFunc(giveTestQuest);
+                       break;
+               case 2:
+                       NPCp(entity[i])->addAIFunc(compTestQuest);
+                       break;
+               default:
+                       break;
+               }
+       }
+}
index c1b22afe67b236b6b684e8dc91b72cb2e1af2e1a..d454f0bbb75cb8d2d77b02280adf2fb558965fa0 100644 (file)
@@ -28,15 +28,11 @@ std::vector<Structures *>build;
 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<std::chrono::milliseconds>(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;i<entity.size()+1;i++){
-               entity[i]->inWorld=test;
-       }
-       
-       NPCp(entity[1])->addAIFunc(entityInteractTest);
+       initEverything();
        
        //************************************************************************//
        //      END WORLD GENERATION STUFF                                                                                        //
        //************************************************************************//
+       
+       /**************************
+       ****     GAMELOOP      ****
+       **************************/
+       
        currentTime=millis();
        while(gameRunning){
                prevTime = currentTime;