]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
pages, quests
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 21 Dec 2015 13:46:35 +0000 (08:46 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 21 Dec 2015 13:46:35 +0000 (08:46 -0500)
Changelog
assets/items/ITEM_PAGE.png
include/common.h
include/world.h
main.cpp
src/common.cpp
src/entities.cpp
src/gameplay.cpp
src/ui.cpp
src/world.cpp
xcf/page.xcf

index 44ff8a4664fda38bd89c12a9e41ae289246d876f..c0d2b9e55ac2f8f9bb1d21fcc75a31932aa23d85 100644 (file)
--- a/Changelog
+++ b/Changelog
        - 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)
index ac132c63bdf361b3704ca7b6887e0d20a2f63373..4602afec4bad3d6be9a94883e6be3607ae898c82 100644 (file)
Binary files a/assets/items/ITEM_PAGE.png and b/assets/items/ITEM_PAGE.png differ
index 08ec73f625cf758d2a3efa1577d22c08680b881d..038bf42243f34785f0ce4b0ad0bf8d19dcb44d3c 100644 (file)
@@ -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.
index 4b3a8918c7200fe1f83b8041beb1127d94825bbd..98ca54a562aac38932f7e3c14cdf6459891fab84 100644 (file)
@@ -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);
        
index e5aba8836f733fae9d925f7ca089699484e9aeed..e6ff2eb240a5a83e221203ef5ae2b0386f0443c9 100644 (file)
--- 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 <cstdio> // fopen
+#include <fstream>
+#include <istream>
 #include <thread>
 
 #include <common.h>
@@ -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);
index 7449a35ddccc3cdb153472671bf72f07c1bcad1e..dbcef0be5476dfd1cf4653dd67d7310bcb7862d2 100644 (file)
@@ -1,4 +1,5 @@
 #include <common.h>
+#include <cstring>
 #include <cstdio>
 #include <chrono>
 
@@ -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);
index 23a4ae6a201d466110e81584a10fce1425ca6647..38490406f661afc7877679e007c30a6974369f5a 100644 (file)
@@ -1,9 +1,10 @@
 #include <entities.h>
 #include <ui.h>
 
+#include <istream>
 //#include <unistd.h>
 
-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;i<tempNum;i++){
-               fgets(bufs,16,(FILE*)names);
-       }
+       for(unsigned int i=0;i<tempNum;i++)
+               names->getline(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;
index 16709291c46b1d5280b09fc1f7e4772eb7bd8eca..7dbe98ebc9e08c4820be3d645261f7a2633e8911 100644 (file)
@@ -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);
index 6069ef9e88e5db81b9bdb0557971a7d911de5ace..f73f48abfbb0641944160949928fcc2ec47bbc4a 100644 (file)
@@ -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<dialogOptCount;i++){
                                        setFontColor(255,255,255);
-                                       dialogOptLoc[i][1]=y-SCREEN_HEIGHT/4+(fontSize+HLINE)*(i+1);
-                                       dialogOptLoc[i][2]=
-                                       putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
-                                       dialogOptLoc[i][0]=offset.x-dialogOptLoc[i][2]/2;
+                                       tmp = putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
+                                       dialogOptLoc[i][2] = offset.x + tmp;
+                                       dialogOptLoc[i][0] = offset.x - tmp;
+                                       dialogOptLoc[i][1] = y - SCREEN_HEIGHT / 4 + (fontSize + HLINE) * (i + 1);
                                        if(mouse.x > 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);
index 7f9b1c0117855559877105abeda6f2c0b4eeffd5..5663086d868d64f500e8b77d2243f422570c0292 100644 (file)
@@ -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.x<x_start+HLINE*15){
                p->loc.x=toLeft->x_start+getWidth(toLeft)-HLINE*10;
index bf39c184b629e57eff4a95ca9b37e8c76c68dadc..72a34cfa10b89ac5b7152ffa37334894cdbce00f 100644 (file)
Binary files a/xcf/page.xcf and b/xcf/page.xcf differ