aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-10-01 08:24:30 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-10-01 08:24:30 -0400
commit9757c1c7e8704080c4e20cde442baf06960e98e7 (patch)
treee63438c079b9a934d4158375525f146b1b2904b3 /src
parentb06afc53ce5fa36544218b524f963725bf180fc1 (diff)
world stuff in sep. file
Diffstat (limited to 'src')
-rw-r--r--src/Quest.cpp12
-rw-r--r--src/entities.cpp1
-rw-r--r--src/gameplay.cpp67
-rw-r--r--src/main.cpp46
4 files changed, 86 insertions, 40 deletions
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(;i<current.size();i++){
+ for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,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;i<current.size();i++){
+ if(!strcmp(current[i]->title,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 <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;
+ }
+ }
+}
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::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;