]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
andy cant code
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 1 Dec 2015 13:38:21 +0000 (08:38 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 1 Dec 2015 13:38:21 +0000 (08:38 -0500)
18 files changed:
Changelog
assets/door.png [new file with mode: 0644]
config/items.h
include/Texture.h
include/common.h
include/entities.h
include/inventory.h
include/ui.h
include/world.h
main.cpp
src/Quest.cpp
src/Texture.cpp
src/entities.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp
src/world.cpp
xcf/door.xcf [new file with mode: 0644]

index c9c94d866ebe4ea5247014f31e6fe92efc25a847..c09d63a79cc10a6381a4c5135e5fa739729356d3 100644 (file)
--- a/Changelog
+++ b/Changelog
        - Converted all m/calloc/free calls to new/delete
        - fixed hardcoded string issues
        - improved inventory animation
+       - began writing songs for game soundtrack
+
+       ~ About 4280 lines of code + documentation written ( +7ish pages of story on gdoc)
diff --git a/assets/door.png b/assets/door.png
new file mode 100644 (file)
index 0000000..2a8b0dd
Binary files /dev/null and b/assets/door.png differ
index 62db07172336b144e1668ade7ba0bd0c6c801630..fc0ca96a7fe7f59650a78869265badce632c8ea0 100644 (file)
@@ -1,6 +1,6 @@
 
 ID DEBUG_ITEM
-       NAME "Debug\0"
+       NAME "Debug"
        TYPE TOOL 
        WIDTH 1 
        HEIGHT 1 
@@ -9,7 +9,7 @@ ID DEBUG_ITEM
        ENI
 
 ID TEST_ITEM   
-       NAME "Dank MayMay\0
+       NAME "Dank MayMay" 
        TYPE TOOL 
        WIDTH HLINE 
        HEIGHT HLINE 
@@ -18,7 +18,7 @@ ID TEST_ITEM
        ENI
 
 ID PLAYER_BAG  
-       NAME "Your Bag\0
+       NAME "Your Bag" 
        TYPE EQUIP 
        WIDTH HLINE*5 
        HEIGHT HLINE*5 
@@ -27,7 +27,7 @@ ID PLAYER_BAG
        ENI
 
 ID FLASHLIGHT  
-       NAME "Flashlight\0
+       NAME "Flashlight" 
        TYPE TOOL 
        WIDTH HLINE*2 
        HEIGHT HLINE*4 
@@ -36,7 +36,7 @@ ID FLASHLIGHT
        ENI
 
 ID SWORD_WOOD  
-       NAME "Wood Sword\0
+       NAME "Wood Sword" 
        TYPE SWORD 
        WIDTH HLINE*4 
        HEIGHT HLINE*10 
index c590f6a930b4382e39f65aa40f14b4cb1f836aba..1a32aae9d714740938529abac0ffecf799a98271 100644 (file)
@@ -13,13 +13,15 @@ class Texturec{
 private:
        unsigned int texState;
 public:
+       GLuint *image;
+       
        Texturec(uint amt, ...);
+       ~Texturec();
+       
        void bindNext();
        void bindPrev();
        void bind(unsigned int);
        void walk();
-
-       GLuint *image;
 };
 
 #endif //TEXTURE_H
index 0ddb5e4b404843ad2aa837b12896eafc3a1336e5..52daf4bf6340641cfcd615131e21f7c15b7ba146 100644 (file)
@@ -61,8 +61,8 @@ typedef struct {
 
 #define GAME_NAME              "Independent Study v.0.4 alpha"
 
-#define SCREEN_WIDTH   800
-#define SCREEN_HEIGHT  600
+#define SCREEN_WIDTH   1280
+#define SCREEN_HEIGHT  720
 
 //#define FULLSCREEN
 
@@ -116,6 +116,8 @@ extern vec2 offset;
 
 extern float handAngle;
 
+extern unsigned int loops;
+
 /*
  *     Prints a formatted debug message to the console, along with the callee's file and line
  *     number.
index b9881ea202a709d6fd9dad5f243cab65f7943681..c593710bab958733014cd726c25239a1e78108c2 100644 (file)
@@ -38,56 +38,74 @@ class Entity{
 public:
        Inventory *inv;
 
-       float width;    //width and height of the player
+       /*
+        *      Movement variables
+       */
+
+       vec2 loc;
+       vec2 vel;
+       
+       float width;
        float height;
-       float speed;    //speed of the play
+       
+       float speed;    // A speed factor for X movement
+
+       /*
+        *      Movement flags
+       */
+
+       bool near;                              // Causes name to display
+       bool canMove;                   // Enables movement
+       bool right,left;                // Direction faced by Entity
+       bool alive;
+       unsigned char ground;   // Shows how the Entity is grounded (if it is)
+
+       /*
+        *      Health variables
+       */
 
        float health;
        float maxHealth;
 
-       int subtype;
-       _TYPE type;
-                       //example:
-                       //type  1(NPC)
-                       //              |(subtype)
-                       //              |->  0 Base NPC
-                       //              |->  1 Merchant
+       /*
+        *      Identification variables
+       */
 
-       vec2 loc; //location and velocity of the entity
-       vec2 vel;
-
-       bool near;
-       bool right,left, canMove; //movement variables
-       bool alive;                               //the flag for whether or not the entity is alive
-       unsigned char ground;     //variable for testing what ground the entity is on to apply certain traits
+       _TYPE type;
+       int       subtype;
 
-       charname;
-       GENDER gender;
-       //GLuint texture[3];      //TODO: ADD TEXTURES
-       Texturectex;
+       char   *name;
+       GENDER  gender;
+       
+       Texturec *tex;
 
 
-       void spawn(float, float);
        void draw(void);
+       void spawn(float, float);
+       
+       int ticksToUse;                         // Used by wander()
+       
        virtual void wander(int){}
-       void getName();
        virtual void interact(){}
-       int ticksToUse; //The variable for deciding how long an entity should do a certain task
-private:
 };
 
 class Player : public Entity {
 public:
        QuestHandler qh;
+       bool light = false;
+       
        Player();
+       ~Player();
        void interact();
-       bool light = false;
 };
 
 class NPC : public Entity{
 public:
        std::vector<int (*)(NPC *)>aiFunc;
+       
        NPC();
+       ~NPC();
+       
        void addAIFunc(int (*func)(NPC *),bool preload);
        void interact();
        void wander(int);
@@ -97,7 +115,10 @@ class Structures : public Entity{
 public:
        void *inWorld;
        void *inside;
+       
        Structures();
+       ~Structures();
+       
        unsigned int spawn(_TYPE, float, float);
 };
 
@@ -105,22 +126,28 @@ class Mob : public Entity{
 public:
        double init_y;
        void (*hey)();
+       
        Mob(int);
        Mob(int,unsigned int);
+       ~Mob();
+       
        void wander(int);
 };
 
 class Object : public Entity{
+private:
+       int identifier;
 public:
+       char *pickupDialog;
+       bool questObject = false;
+       
        Object(ITEM_ID id, bool qo, const char *pd);
+       ~Object();
+       
        void interact(void);
-       bool questObject = false;
-       char *pickupDialog;
        std::thread runInteract() {
           return std::thread([=] { interact(); });
     }
-private:
-       int identifier;
 };
 #endif // ENTITIES_H
 
index a9a4bcb46be597b4bdcd481294884ecf16282730..cde8d2a3c869e33670cc6a219718a690c8fb3308 100644 (file)
@@ -49,13 +49,19 @@ public:
        int maxStackSize;
        char* textureLoc;
        Texturec *tex;
+       GLuint text;
        int count;
+
        Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl);
        GLuint rtex(){
                return tex->image[0];
        }
 };
 
+static Item item[5]= {
+       #include "../config/items.h"
+};
+
 struct item_t{
        int count;
        ITEM_ID id;
@@ -67,14 +73,13 @@ private:
        unsigned int size;              // Size of 'item' array
        item_t *inv;
        int os = 0;
-       //struct item_t *item;  // An array of the items contained in this inventory.
 public:
        unsigned int sel;
        bool invOpen = false;
        bool invOpening = false;
 
        Inventory(unsigned int s);      // Creates an inventory of size 's'
-       ~Inventory(void);                       // Free's 'item'
+       ~Inventory(void);                       // Free's allocated memory
        
        int addItem(ITEM_ID id,unsigned char count);    // Add 'count' items with an id of 'id' to the inventory
        int takeItem(ITEM_ID id,unsigned char count);   // Take 'count' items with an id of 'id' from the inventory
index c3c894000d2cf9317d150ec457e435dcb98e05bb..4d30b9b043fa5207de54bbd5415f95e028a4f449 100644 (file)
@@ -59,7 +59,8 @@ namespace ui {
         *      limited until a right click is given, closing the box.
        */
        
-       void dialogBox(const char *name,char *opt,const char *text,...);
+       void dialogBox(const char *name,const char *opt,const char *text,...);
+       void waitForDialog(void);
        
        /*
         *      Draws a larger string in the center of the screen. Drawing is done inside this function.
@@ -76,7 +77,6 @@ namespace ui {
        /*
         *      Handle keyboard/mouse events.
        */
-       
        void handleEvents(void);
        
        /*
index a2414e66fd8dea38c3c2d70322ed27943825ca58..6c0395d056c8eb06e5e2e5184673bef24d4bf7e6 100644 (file)
@@ -62,6 +62,12 @@ protected:
        
        void singleDetect(Entity *e);
        
+       /*
+        *      Deletes all entities in the world.
+       */
+       
+       void deleteEntities(void);
+       
        /*
         *      The size of the line array. This is set once by World->generate().
        */
@@ -205,6 +211,7 @@ private:
        World   *exit;
 public:
        Arena(World *leave,Player *p);
+       ~Arena(void);
        World *exitArena(Player *p);
 };
 
index 5ac85babbff1e10015bbbe27b5d56eb0ee12490a..422a32976ab5692fd31d960bc74f059de3bb6e74 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -256,9 +256,11 @@ int main(int argc, char *argv[]){
 
        if(Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0){
                std::cout << "SDL_mixer could not initialize! Error: " << Mix_GetError() << std::endl;
+               return -1;
        }
 
        // Run Mix_Quit when main returns
+       atexit(Mix_CloseAudio);
        atexit(Mix_Quit);
 
        /*
@@ -439,6 +441,7 @@ int main(int argc, char *argv[]){
        /**************************
        ****     GAMELOOP      ****
        **************************/
+       
        gameRunning=true;
        while(gameRunning){
                mainLoop();
@@ -452,6 +455,11 @@ int main(int argc, char *argv[]){
      *  Close the window and free resources
     */
     
+    Mix_HaltMusic();
+    Mix_FreeMusic(music);
+    
+    Mix_FreeChunk(horn);
+    
     fclose(names);
     
     SDL_GL_DeleteContext(mainGLContext);
@@ -483,7 +491,6 @@ void mainLoop(void){
                currentTime=millis();
                prevPrevTime=currentTime;
        }       
-       
        /*
         *      Update timing values. This is crucial to calling logic and updating the window (basically
         *      the entire game).
@@ -496,8 +503,8 @@ void mainLoop(void){
        /*
         *      Run the logic handler if MSEC_PER_TICK milliseconds have passed.
        */
-       
-       if(prevPrevTime + MSEC_PER_TICK >= currentTime){
+       ui::handleEvents();
+       if(prevPrevTime + MSEC_PER_TICK <= currentTime){
                logic();
                prevPrevTime = currentTime;
        }
@@ -511,7 +518,6 @@ void mainLoop(void){
        /*
         *      Update debug variables if necessary
        */
-       
        if(++debugDiv==20){
                debugDiv=0;
                
@@ -522,7 +528,6 @@ void mainLoop(void){
        }
 
        render();       // Call the render loop
-       
 }
 
 extern bool fadeEnable;
@@ -773,7 +778,6 @@ void render(){
        /*
         *      Here we draw a black overlay if it's been requested.
        */
-
        if(fadeIntensity){
                glColor4ub(0,0,0,fadeIntensity);
                glRectf(offset.x-SCREEN_WIDTH /2,
@@ -784,7 +788,6 @@ void render(){
                        ui::importantText("The screen is black.");
                }
        }else if(ui::fontSize != 16) ui::setFontSize(16);
-
        /**************************
        ****  END RENDERING   ****
        **************************/
@@ -805,7 +808,6 @@ void render(){
 }
 
 void logic(){
-
        /*
         *      NPCSelected is used to insure that only one NPC is made interactable with the mouse
         *      if, for example, multiple entities are occupying one space.
@@ -816,14 +818,12 @@ void logic(){
        /*
         *      Handle user input (keyboard & mouse).
        */
-
-       ui::handleEvents();
+       //ui::handleEvents();
 
        /*
         *      Run the world's detect function. This handles the physics of the player and any entities
         *      that exist in this world.
        */
-
        currentWorld->detect(player);
        if(player->loc.y<.02)gameRunning=false;
 
@@ -833,7 +833,6 @@ void logic(){
         *      click detection is done as well for NPC/player interaction.
         *
        */
-
        if((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) && !ui::dialogBoxExists)player->inv->useItem();
 
        for(auto &n : currentWorld->npc){
@@ -907,7 +906,6 @@ void logic(){
                        }else n->near=false;
                }
        }
-
        for(auto &m : currentWorld->mob){
                if(m->alive){
 
@@ -929,7 +927,6 @@ void logic(){
                        }
                }
        }
-
        unsigned int i = 0;
        for(auto &o : currentWorld->object){
                if(o->alive){
@@ -960,7 +957,6 @@ void logic(){
        /*
         *      Switch between day and night (SUNNY and DARK) if necessary.
        */
-
        if(!(tickCount%DAY_CYCLE)||!tickCount){
                if(weather==SUNNY){
                        weather=DARK;
@@ -978,7 +974,6 @@ void logic(){
        /*
         *      Transition to and from black if necessary.
        */
-
        if(fadeEnable){
                         if(fadeIntensity < 160)fadeIntensity+=5;
                else if(fadeIntensity < 255)fadeIntensity+=1;
index bfa89668e2e18e901bc7e712a836f3649acdff68..4e8522ddf985f5fe6abdd3ddc26cef415b473297 100644 (file)
@@ -7,25 +7,22 @@
 #define END            }),\r
 \r
 const Quest QuestList[TOTAL_QUESTS]={\r
-//     Quest("Test","A test quest",(struct item_t){1,TEST_ITEM}),\r
-\r
 // Get quest list\r
 #include "../config/quest_list.txt"\r
-\r
 };\r
 \r
 \r
 Quest::Quest(const char *t,const char *d,struct item_t r){\r
-       title = new char[strlen(t)+1];  //(char *)calloc(safe_strlen(t),sizeof(char));\r
-       desc = new char[strlen(d)+1];           //(char *)calloc(safe_strlen(d),sizeof(char));\r
+       title = new char[strlen(t)+1];\r
+       desc = new char[strlen(d)+1];\r
        strcpy(title,t);\r
        strcpy(desc,d);\r
        memcpy(&reward,&r,sizeof(struct item_t));\r
 }\r
 \r
 Quest::~Quest(){\r
-       delete[] title; //free(title);\r
-       delete[] desc;  //free(desc);\r
+       delete[] title;\r
+       delete[] desc;\r
        memset(&reward,0,sizeof(struct item_t));\r
 }\r
 \r
index 8b4051351199b69c7789baddc57131d714b8d431..a3a8afe755a97b753b692f6d72eadafa5f19765a 100644 (file)
@@ -13,7 +13,6 @@ namespace Texture{
        GLuint loadTexture(const char *fileName){
                SDL_Surface *image;
                GLuint object = 0;
-               unsigned int i;
 
                for(unsigned int i=0;i<LoadedTextureCounter;i++){
                        if(!strcmp(LoadedTexture[i]->name,fileName)){
@@ -74,9 +73,13 @@ Texturec::Texturec(uint amt, ...){
        va_end(fNames);
 }
 
+Texturec::~Texturec(){
+       delete[] image;
+}
+
 void Texturec::bind(unsigned int bn){
        texState = bn;
-       glBindTexture(GL_TEXTURE_2D, image[texState]);
+       glBindTexture(GL_TEXTURE_2D,image[(int)texState]);
 }
 
 void Texturec::bindNext(){
index 4e582c986194ffc3a7488f26a2f365a76618ffe2..100eefbd910a78da15e52277e38bf73e446537f9 100644 (file)
@@ -10,6 +10,39 @@ extern Player *player;
 
 extern const char *itemName;
 
+void getRandomName(Entity *e){
+       int tempNum,max=0;
+       char buf,*bufs;
+       
+       rewind(names);
+       
+       bufs = new char[16];    //(char *)malloc(16);
+       
+       for(;!feof(names);max++){
+               fgets(bufs,16,(FILE*)names);
+       }
+       
+       tempNum = rand() % max;
+       rewind(names);
+       
+       for(int i=0;i<tempNum;i++){
+               fgets(bufs,16,(FILE*)names);
+       }
+       
+       switch(fgetc(names)){
+       case 'm': e->gender = MALE;  break;
+       case 'f': e->gender = FEMALE;break;
+       default : break;
+       }
+       
+       if((fgets(bufs,16,(FILE*)names)) != NULL){
+               bufs[strlen(bufs)-1] = '\0';
+               strcpy(e->name,bufs);
+       }
+       
+       delete[] bufs;
+}
+
 void Entity::spawn(float x, float y){  //spawns the entity you pass to it based off of coords and global entity settings
        loc.x = x;
        loc.y = y;
@@ -33,8 +66,8 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o
                }
        }
        
-       name = new char[16];    //(char*)malloc(16);
-       getName();
+       name = new char[16];
+       getRandomName(this);
 }
 
 Player::Player(){ //sets all of the player specific traits on object creation
@@ -48,6 +81,11 @@ Player::Player(){ //sets all of the player specific traits on object creation
        tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png");
        inv = new Inventory(PLAYER_INV_SIZE);
 }
+Player::~Player(){
+       delete inv;
+       delete tex;
+       delete[] name;
+}
 
 NPC::NPC(){    //sets all of the NPC specific traits on object creation
        width = HLINE * 10;
@@ -63,6 +101,15 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation
        tex = new Texturec(1,"assets/NPC.png");
        inv = new Inventory(NPC_INV_SIZE);
 }
+NPC::~NPC(){
+       while(!aiFunc.empty()){
+               aiFunc.pop_back();
+       }
+       
+       delete inv;
+       delete tex;
+       delete[] name;
+}
 
 Structures::Structures(){ //sets the structure type
        health = maxHealth = 1;
@@ -74,6 +121,11 @@ Structures::Structures(){ //sets the structure type
        
        inWorld = NULL;
 }
+Structures::~Structures(){
+       delete inv;
+       delete tex;
+       delete[] name;
+}
 
 Mob::Mob(int sub){
        type = MOBT;
@@ -99,6 +151,11 @@ Mob::Mob(int sub){
        
        inv = new Inventory(NPC_INV_SIZE);
 }
+Mob::~Mob(){
+       delete inv;
+       delete tex;
+       delete[] name;
+}
 
 Object::Object(ITEM_ID id, bool qo, const char *pd){
        identifier = id;
@@ -107,6 +164,7 @@ Object::Object(ITEM_ID id, bool qo, const char *pd){
        pickupDialog = new char[strlen(pd)+1];
        strcpy(pickupDialog,pd);
        
+
        type = OBJECTT;
        alive = true;
        near = false;
@@ -115,8 +173,15 @@ Object::Object(ITEM_ID id, bool qo, const char *pd){
 
        maxHealth = health = 1;
        tex = new Texturec(1,getItemTexturePath(id));
-}
 
+}
+Object::~Object(){
+       delete[] pickupDialog;
+       
+       delete inv;
+       delete tex;
+       delete[] name;
+}
 
 void Entity::draw(void){               //draws the entities
        glPushMatrix();
@@ -208,38 +273,6 @@ NOPE:
        }
 }
 
-void Entity::getName(){
-       rewind(names);
-       char buf,*bufs = new char[16];  //(char *)malloc(16);
-       int tempNum,max = 0;
-       for(;!feof(names);max++){
-               fgets(bufs,16,(FILE*)names);
-       }
-       tempNum = rand()%max;
-       rewind(names);
-       for(int i=0;i<tempNum;i++){
-               fgets(bufs,16,(FILE*)names);
-       }
-       switch(fgetc(names)){
-       case 'm':
-               gender = MALE;
-               //std::puts("Male");
-               break;
-       case 'f':
-               gender = FEMALE;
-               //std::puts("Female");
-               break;
-       default:
-               break;
-       }
-       if((fgets(bufs,16,(FILE*)names)) != NULL){
-               //std::puts(bufs);
-               bufs[strlen(bufs)-1] = '\0';
-               strcpy(name,bufs);
-       }
-       delete[] bufs;  //free(bufs);
-}
-
 void Player::interact(){ //the function that will cause the player to search for things to interact with
        
 }
index 2fd7424d8c5fc5ae2844f00b940c67844ce5e0aa..b7eab727076e6aa22566c3c562a5fa0205351d35 100644 (file)
@@ -5,42 +5,6 @@
 
 extern World   *currentWorld;
 extern Player  *player;
-extern void mainLoop(void);
-extern SDL_Window *window;
-extern bool fadeEnable;
-
-void story(void){
-       for(int i=0;i<600;i++){
-               glMatrixMode(GL_PROJECTION);
-               glPushMatrix();
-               glLoadIdentity();
-               glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1);
-               glMatrixMode(GL_MODELVIEW);
-               glPushMatrix();
-               glLoadIdentity();
-               glEnable(GL_STENCIL_TEST);
-               glPushMatrix();
-
-               glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT );
-               glClear(GL_COLOR_BUFFER_BIT);
-
-               glColor4f(0.0f,0.0f,0.0f,0.0f);
-               glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT);
-               glColor4f(1.0f,1.0f,1.0f,1.0f);
-               ui::importantText("Oh hello, where are you?");
-               //ui::setFontSize(16);
-               //ui::putText(54,540,"BITC.");
-
-               glPopMatrix();
-               SDL_GL_SwapWindow(window);
-       }
-}
-
-void waitForDialog(void){
-       do{
-               mainLoop();
-       }while(ui::dialogBoxExists);
-}
 
 int compTestQuest(NPC *speaker){
        ui::dialogBox(speaker->name,NULL,"Ooo, that's a nice quest you got there. Lemme finish that for you ;).");
@@ -51,16 +15,13 @@ int compTestQuest(NPC *speaker){
 int giveTestQuest(NPC *speaker){
        unsigned char i;
        
-       char opt[]=":Yes:No";
-       ui::dialogBox(speaker->name,opt,"Here, have a quest!");
-       
-       waitForDialog();
+       ui::dialogBox(speaker->name,":Yes:No","Here, have a quest!");
+       ui::waitForDialog();
        
        if(ui::dialogOptChosen == 1){
        
                ui::dialogBox(speaker->name,NULL,"Have a good day! :)");
-
-               waitForDialog();
+               ui::waitForDialog();
 
                player->qh.assign("Test");
                currentWorld->npc[1]->addAIFunc(compTestQuest,true);
@@ -73,14 +34,12 @@ int giveTestQuest(NPC *speaker){
 static Arena *a;
 
 void CUTSCENEEE(void){
-       char opt[]=":K.";
        player->vel.x = 0;
-       ui::dialogBox(player->name,opt,"No way I\'m gettin\' up this hill.");
        
-       waitForDialog();
+       ui::dialogBox(player->name,":K.","No way I\'m gettin\' up this hill.");
+       ui::waitForDialog();
 
        a = new Arena(currentWorld,player);
-       
        currentWorld = a;
        
        /*player->right = true;
@@ -91,6 +50,13 @@ void CUTSCENEEE(void){
 float playerSpawnHillFunc(float x){
        return (float)(pow(2,(-x+200)/5) + 80);
 }
+
+static World *test;
+static World *playerSpawnHill;
+static IndoorWorld *iw;
+
+void destroyEverything(void);
+
 void initEverything(void){
        unsigned int i;
        
@@ -98,17 +64,18 @@ void initEverything(void){
         *      World creation:
        */
        
-       World *test=new World();
-       World *playerSpawnHill=new World();
+       test=new World();
        
        test->generate(SCREEN_WIDTH*2);
-       test->addHole(100,150);
-       
        test->setBackground(BG_FOREST);
+       
+       test->addHole(100,150);
        test->addLayer(400);
        
-       playerSpawnHill->generateFunc(1280,playerSpawnHillFunc);
+       playerSpawnHill=new World();
+       
        playerSpawnHill->setBackground(BG_FOREST);
+       playerSpawnHill->generateFunc(1280,playerSpawnHillFunc);
        //playerSpawnHill->generate(1920);
 
        /*
@@ -116,6 +83,7 @@ void initEverything(void){
        */
        
        currentWorld=playerSpawnHill;
+       
        playerSpawnHill->toRight=test;
        test->toLeft=playerSpawnHill;
        
@@ -130,22 +98,21 @@ void initEverything(void){
         *      Create a structure (this will create villagers when spawned).
        */
        
-       IndoorWorld *iw=new IndoorWorld();
+       iw=new IndoorWorld();
        iw->generate(200);
        
-       currentWorld->addStructure(STRUCTURET,(rand()%120*HLINE),10,test,iw);
-       
        /*
-        *      Spawn some mobs.
+        *      Spawn some entities.
        */
 
+       playerSpawnHill->addStructure(STRUCTURET,(rand()%120*HLINE),10,test,iw);
        playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);
        
+       playerSpawnHill->addObject(SWORD_WOOD, false, "", 500,200);
+       playerSpawnHill->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200);
+       
        test->addMob(MS_RABBIT,200,100);
        test->addMob(MS_BIRD,-500,500);
-       
-       currentWorld->addObject(SWORD_WOOD, false, "", 500,200);
-       currentWorld->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200);
 
        /*currentWorld->addObject(DEBUG_ITEM, 500,200);
        currentWorld->addObject(TEST_ITEM,  550,200);
@@ -153,9 +120,52 @@ void initEverything(void){
        currentWorld->addObject(SWORD_WOOD, 650,200);
        currentWorld->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",700,200);
        */
-       /*
-        *      Link all the entities that were just created to the initial world, and setup a test AI function. 
-       */
        
-       currentWorld->npc[0]->addAIFunc(giveTestQuest,false);
+       playerSpawnHill->npc[0]->addAIFunc(giveTestQuest,false);
+       
+       atexit(destroyEverything);
+}
+
+extern std::vector<int (*)(NPC *)> AIpreload;
+extern std::vector<NPC *> AIpreaddr;
+
+void destroyEverything(void){
+       delete test;
+       delete playerSpawnHill;
+       
+       while(!AIpreload.empty()){
+               AIpreload.pop_back();
+       }
+       while(!AIpreaddr.empty()){
+               AIpreaddr.pop_back();
+       }
+       
+       //delete iw;    // segfaults
 }
+
+/*void story(void){
+       for(int i=0;i<600;i++){
+               glMatrixMode(GL_PROJECTION);
+               glPushMatrix();
+               glLoadIdentity();
+               glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1);
+               glMatrixMode(GL_MODELVIEW);
+               glPushMatrix();
+               glLoadIdentity();
+               glEnable(GL_STENCIL_TEST);
+               glPushMatrix();
+
+               glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT );
+               glClear(GL_COLOR_BUFFER_BIT);
+
+               glColor4f(0.0f,0.0f,0.0f,0.0f);
+               glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT);
+               glColor4f(1.0f,1.0f,1.0f,1.0f);
+               ui::importantText("Oh hello, where are you?");
+               //ui::setFontSize(16);
+               //ui::putText(54,540,"BITC.");
+
+               glPopMatrix();
+               SDL_GL_SwapWindow(window);
+       }
+}*/
index cd01c11e628553cd3334c59009760059c03d1a2a..28612ae531032a7cd5f41f7aa2c9e5ebb0e1d291 100644 (file)
@@ -7,10 +7,6 @@
 extern Player *player;
 extern GLuint invUI;
 
-static Item item[5]= {
-       #include "../config/items.h"
-};
-
 void itemDraw(Player *p,ITEM_ID id);
 
 char *getItemTexturePath(ITEM_ID id){
@@ -25,8 +21,8 @@ Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const
        maxStackSize = m;
        count = 0;
 
-       name            = new char[strlen(n)+1];        //(char*)calloc(strlen(n ),sizeof(char));
-       textureLoc      = new char[strlen(tl)+1];       //(char*)calloc(strlen(tl),sizeof(char));
+       name            = new char[strlen(n)+1];
+       textureLoc      = new char[strlen(tl)+1];
 
        strcpy(name,n);
        strcpy(textureLoc,tl);
@@ -37,14 +33,13 @@ Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const
 Inventory::Inventory(unsigned int s){
        sel=0;
        size=s;
-       inv = new struct item_t[size];  //(struct item_t *)calloc(size,sizeof(struct item_t));
+       inv = new struct item_t[size];
        memset(inv,0,size*sizeof(struct item_t));
        tossd=false;
 }
 
 Inventory::~Inventory(void){
        delete[] inv;
-       //free(item);
 }
 
 void Inventory::setSelection(unsigned int s){
@@ -86,6 +81,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
 void Inventory::draw(void){
        ui::putText(offset.x-SCREEN_WIDTH/2,480,"%d",sel);
        unsigned int i=0;
+       static unsigned int lop = 0;
        float y,xoff;
        static int numSlot = 7;
        static std::vector<int>dfp(numSlot);
@@ -106,9 +102,9 @@ void Inventory::draw(void){
                end = 0;
                for(auto &d : dfp){
                        if(a != 0){
-                               if(dfp[a-1]>25)d+=25;
+                               if(dfp[a-1]>50)d+=1.65*deltaTime;
                        }else{
-                               d += 25;
+                               d += 1.65*deltaTime;
                        }
                        if(d >= range)
                                d = range;
@@ -118,15 +114,9 @@ void Inventory::draw(void){
        }else if(!invOpening){
                for(auto &d : dfp){
                        if(d > 0){
-                               if(a != 0){
-                                       //d-=25;
-                                       if(dfp[a-1]+25<d || dfp[a-1]<=0)d-=25;
-                               }else{
-                                       d-=25;
-                               }
+                               d-=1.65*deltaTime;
                        }else end++;
-                       a++;
-               }a=0;
+               }
                if(end >= numSlot)invOpen=false;
        }
        if(invOpen){
@@ -136,14 +126,24 @@ void Inventory::draw(void){
                        curCoord[a].y += float((dfp[a]) * sin(angle*PI/180));
                        r.end = curCoord[a];
 
-                       item[inv[i].id].tex->bind(0);                   
-                       glColor4f(1.0f, 1.0f, 1.0f, (float)dfp[a]/(float)range);
+                       glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)range));
                        glBegin(GL_QUADS);
-                               glTexCoord2i(0,1);glVertex2i(r.end.x,           r.end.y);
-                               glTexCoord2i(1,1);glVertex2i(r.end.x+45,        r.end.y);
-                               glTexCoord2i(1,0);glVertex2i(r.end.x+45,        r.end.y+45);
-                               glTexCoord2i(0,0);glVertex2i(r.end.x,           r.end.y+45);
+                               glVertex2i(r.end.x,             r.end.y);
+                               glVertex2i(r.end.x+45,  r.end.y);
+                               glVertex2i(r.end.x+45,  r.end.y+45);
+                               glVertex2i(r.end.x,             r.end.y+45);
                        glEnd();
+
+                       if(inv[a].count > 0){
+                               glBindTexture(GL_TEXTURE_2D, item[inv[a].id].text);                     
+                               glColor4f(1.0f, 1.0f, 1.0f, (float)dfp[a]/(float)range);
+                               glBegin(GL_QUADS);
+                                       glTexCoord2i(0,1);glVertex2i(r.end.x,           r.end.y);
+                                       glTexCoord2i(1,1);glVertex2i(r.end.x+45,        r.end.y);
+                                       glTexCoord2i(1,0);glVertex2i(r.end.x+45,        r.end.y+45);
+                                       glTexCoord2i(0,0);glVertex2i(r.end.x,           r.end.y+45);
+                               glEnd();
+                       }
                        a++;
                }
        }
@@ -181,6 +181,7 @@ void Inventory::draw(void){
        }*/
        
        if(inv[sel].count)itemDraw(player,inv[sel].id);
+       lop++;
 }
 
 static vec2 item_coord = {0,0};
index 324192d57b4a84221fac05360c7f828abcec0849..8d57c36e6b325ce9f47f10f99e3f08f232304be7 100644 (file)
@@ -49,6 +49,8 @@ static char *dialogOptText[4];
 static float dialogOptLoc[4][3];
 static unsigned char dialogOptCount = 0;
 
+extern void mainLoop(void);
+
 /*
  *     Toggled by pressing 'q', disables some controls when true.
 */
@@ -366,11 +368,10 @@ namespace ui {
                
                return width;
        }
-       
-       void dialogBox(const char *name,char *opt,const char *text,...){
+       void dialogBox(const char *name,const char *opt,const char *text,...){
                va_list dialogArgs;
                unsigned int len;
-               char *sopt;
+               char *sopt,*soptbuf;
                
                /*
                 *      Set up the text buffer.
@@ -404,7 +405,9 @@ namespace ui {
                dialogOptChosen=0;
                dialogOptCount=0;
                
-               sopt=strtok(opt,":");
+               soptbuf = new char[strlen(opt)+1];
+               
+               sopt=strtok(soptbuf,":");
                while(sopt != NULL){
                        dialogOptText[dialogOptCount] = new char[strlen(sopt)+1];       //(char *)malloc(strlen(sopt));
                        strcpy(dialogOptText[dialogOptCount++],sopt);
@@ -418,6 +421,11 @@ namespace ui {
                dialogBoxExists = true;
                
        }
+       void waitForDialog(void){
+               do{
+                       mainLoop();
+               }while(ui::dialogBoxExists);
+       }
        void importantText(const char *text,...){
                va_list textArgs;
                char *ttext,*rtext;
index c977c7fdadf04225cbde2f677592e2be850d05f1..5cc3f2aa7cf0fdb19c8ff84e8e87fa48386e8ee0 100644 (file)
@@ -71,6 +71,39 @@ World::World(void){
        memset(star,0,100*sizeof(vec2));
 }
 
+void World::deleteEntities(void){
+       while(!mob.empty()){
+               delete mob.back();
+               mob.pop_back();
+       }
+       while(!npc.empty()){
+               delete npc.back();
+               npc.pop_back();
+       }
+       while(!build.empty()){
+               delete build.back();
+               build.pop_back();
+       }
+       while(!object.empty()){
+               delete object.back();
+               object.pop_back();
+       }
+       while(!entity.empty()) entity.pop_back();
+}
+
+World::~World(void){
+       
+       if(behind){
+               delete behind;
+       }
+       
+       delete bgTex;
+       delete[] star;
+       delete[] line;
+       
+       deleteEntities();
+}
+
 void World::generate(unsigned int width){      // Generates the world and sets all variables contained in the World class.
        unsigned int i;
        float inc;
@@ -196,10 +229,6 @@ void World::generateFunc(unsigned int width,float(*func)(float)){
        }
 }
 
-World::~World(void){
-       delete[] line;
-}
-
 void World::update(Player *p,unsigned int delta){
        p->loc.y+= p->vel.y                      *delta;
        p->loc.x+=(p->vel.x*p->speed)*delta;
@@ -654,7 +683,7 @@ void World::singleDetect(Entity *e){
                
                }else{
                        
-                       if(e->vel.y > -2)e->vel.y-=.001 * deltaTime;
+                       if(e->vel.y > -2)e->vel.y-=.003 * deltaTime;
                        
                }
                
@@ -836,7 +865,11 @@ IndoorWorld::IndoorWorld(void){
 }
 
 IndoorWorld::~IndoorWorld(void){
-       delete[] line;  //free(line);
+       delete bgTex;
+       delete[] star;
+       delete[] line;
+
+       deleteEntities();
 }
 
 void IndoorWorld::generate(unsigned int width){                // Generates a flat area of width 'width'
@@ -897,6 +930,14 @@ Arena::Arena(World *leave,Player *p){
        pxy = p->loc;
 }
 
+Arena::~Arena(void){
+       delete bgTex;
+       delete[] star;
+       delete[] line;
+       
+       deleteEntities();
+}
+
 World *Arena::exitArena(Player *p){
        npc[0]->loc.x = door.x;
        npc[0]->loc.y = door.y;
diff --git a/xcf/door.xcf b/xcf/door.xcf
new file mode 100644 (file)
index 0000000..7965018
Binary files /dev/null and b/xcf/door.xcf differ