]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
arenas
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 14 Dec 2015 13:41:31 +0000 (08:41 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 14 Dec 2015 13:41:31 +0000 (08:41 -0500)
Changelog
assets/sounds/frig.wav [new file with mode: 0644]
include/entities.h
include/ui.h
include/world.h
main.cpp
src/entities.cpp
src/gameplay.cpp
src/ui.cpp
src/world.cpp

index 44e0bfc2aeee45592751ae945a80f2e67b544fac..c894c5c788d2224795e7c6b62cd734a6dfcc512a 100644 (file)
--- a/Changelog
+++ b/Changelog
        - imrpoved BGM handling
        - continued work on particles, made a fountain
        - added sanic
+       
+       ~ Broke 5000 lines of code/doc, now with some file Doxygen'd
+
+12/14/2015:
+===========
+
+       - Re-implemented Arena
+               added door mob for exit
+               added white flash + sound transition
+       - fixed fading bugs
+       - continued fixing general game bugs
+       - fixed structure spawn issues
diff --git a/assets/sounds/frig.wav b/assets/sounds/frig.wav
new file mode 100644 (file)
index 0000000..86d64e9
Binary files /dev/null and b/assets/sounds/frig.wav differ
index dd3adabb695f8d60fd49e54276b0feff1fff4221..30947f5a7479e8eddd32d80c3f7c7ce01fdcede1 100644 (file)
@@ -31,7 +31,8 @@ enum GENDER{
 enum MOB_SUB {
        MS_RABBIT = 1,
        MS_BIRD,
-       MS_TRIGGER
+       MS_TRIGGER,
+       MS_DOOR
 };
 
 class Entity{
index 2fe3b0aa1cef58cf04b691cdd77204ac64e53e2a..5d17c47edcede3914bce228d6538659a7e16189c 100644 (file)
@@ -87,6 +87,7 @@ namespace ui {
        void toggleBlack(void);
        void toggleBlackFast(void);
        void toggleWhite(void);
+       void toggleWhiteFast(void);
        void waitForCover(void);
        
 }
index 1e78cd0d9b50253d2021db47645e8c5526eaa812..777f5b813d680aa1fbe5cd4e424e0ad2f4131abd 100644 (file)
@@ -231,6 +231,9 @@ public:
        World *goWorldRight(Player *p);                                 
        World *goWorldBack(Player *p);
        World *goWorldFront(Player *p);
+
+       bool isWorldLeft(void);
+       bool isWorldRight(void);
        
        /*
         *      Called to enter/exit a structure.
@@ -277,7 +280,6 @@ public:
 class Arena : public World {
 private:
        vec2     pxy;
-       vec2     door;
        World   *exit;
 public:
        Arena(World *leave,Player *p);
index 4e451895f6d077c8f6e5efbfc23e48e9364e3735..b31c7e00bd4a55913c612c2c2a69de8c0591e066 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -212,7 +212,7 @@ extern WEATHER weather;
 extern bool fadeEnable;
 extern bool fadeWhite;
 extern bool fadeFast;
-extern unsigned int fadeIntensity;
+extern int  fadeIntensity;
 
 /*******************************************************************************
  * MAIN ************************************************************************
@@ -717,9 +717,9 @@ void render(){
        
        if(fadeIntensity){
                if(fadeWhite)
-                       glColor4ub(255,255,255,fadeIntensity);
+                       safeSetColorA(255,255,255,fadeIntensity);
                else
-                       glColor4ub(0,0,0,fadeIntensity);
+                       safeSetColorA(0,0,0,fadeIntensity);
                glRectf(offset.x-SCREEN_WIDTH /2,
                                offset.y-SCREEN_HEIGHT/2,
                                offset.x+SCREEN_WIDTH /2,
@@ -916,6 +916,8 @@ void logic(){
                        case MS_TRIGGER:
                                m->wander(0);
                                break;
+                       case MS_DOOR:
+                               break;
                        default:
                                std::cout<<"Unhandled mob of subtype "<<m->subtype<<"."<<std::endl;
                                break;
@@ -955,7 +957,6 @@ void logic(){
        if(!(tickCount%DAY_CYCLE)||!tickCount){
                if(weather==SUNNY){
                        weather=DARK;
-                       Mix_PlayChannel(2,crickets,0);
                }else{
                        weather=SUNNY;
                        Mix_Pause(2);
@@ -971,12 +972,15 @@ void logic(){
        /*
         *      Transition to and from black if necessary.
        */
+       
        if(fadeEnable){
-                        if(fadeIntensity < 150)fadeIntensity+=fadeFast?30:10;
-               else if(fadeIntensity < 255)fadeIntensity+=fadeFast?15:5;
+                        if(fadeIntensity < 150)fadeIntensity+=fadeFast?40:10;
+               else if(fadeIntensity < 255)fadeIntensity+=fadeFast?20:5;
+               else fadeIntensity = 255;
        }else{
-                        if(fadeIntensity > 150)fadeIntensity-=fadeFast?15:5;
-               else if(fadeIntensity > 0)      fadeIntensity-=fadeFast?30:10;
+                        if(fadeIntensity > 150)fadeIntensity-=fadeFast?20:5;
+               else if(fadeIntensity > 0)      fadeIntensity-=fadeFast?40:10;
+               else fadeIntensity = 0;
        }
 
        /*
index 5c00cc7e98801ee15dc49af02271663f57ef296d..15f120a850cb0beedcc8a37ce45567c2997218d7 100644 (file)
@@ -151,6 +151,10 @@ Mob::Mob(int sub){
                width = HLINE * 20;
                height = 2000;
                tex = new Texturec(0);
+       case MS_DOOR:
+               width = HLINE * 10;
+               height = HLINE * 16;
+               tex = new Texturec(1,"assets/door.png");
                break;
        }
        
@@ -236,6 +240,7 @@ void Entity::draw(void){            //draws the entities
                                goto NOPE;
                                break;
                        case MS_BIRD:
+                       case MS_DOOR:
                        default:
                                tex->bind(0);
                                break;
@@ -437,6 +442,7 @@ void Mob::wander(int timeRun){
                        hey(this);
                }
                break;
+       case MS_DOOR:
        default:
                break;
        }
index 74414d705a073c54ad93cd538137f68bcb4eacbd..6d8fb0b06a20b2060e18db18e903a0bc62f7289f 100644 (file)
@@ -48,9 +48,17 @@ void worldSpawnHill1_hillBlock(Mob *callee){
        callee->alive = true;
 }
 
+static Arena *a;
 void worldSpawnHill2_infoSprint(Mob *callee){
-       ui::dialogBox("B-) ",NULL,true,"Press \'Shift\' to run!");
        callee->alive = false;
+       a = new Arena(currentWorld,player);
+       a->setBackground(BG_FOREST);
+       a->setBGM("assets/music/embark.wav");
+       ui::toggleWhiteFast();
+       ui::waitForCover();
+       currentWorld = a;
+       ui::toggleWhiteFast();
+       //ui::dialogBox("B-) ",NULL,true,"Press \'Shift\' to run!");
 }
 
 void worldSpawnHill3_itemGet(Mob *callee){
index 26b30c45cdbac02bd501b3a806e929a27364bfe1..11bc1950aab23b76d7e0f2324bb6b979d5929247 100644 (file)
@@ -65,6 +65,7 @@ bool fadeFast = false;
 unsigned int fadeIntensity = 0;
 
 bool inBattle = false;
+Mix_Chunk *battleStart;
 
 namespace ui {
        
@@ -460,7 +461,8 @@ namespace ui {
        void waitForCover(void){
                do{
                        mainLoop();
-               }while(fadeIntensity != 255);
+               }while(fadeIntensity < 255);
+               fadeIntensity = 255;
        }
        void importantText(const char *text,...){
                va_list textArgs;
@@ -598,6 +600,7 @@ DONE:
                static vec2 premouse={0,0};
                static int heyOhLetsGo = 0;
                World *tmp;
+               vec2 oldpos,tmppos;
                SDL_Event e;
                
                mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
@@ -628,9 +631,9 @@ DONE:
                                        gameRunning = false;
                                        return;
                                }else if(SDL_KEY == SDLK_SPACE){
-                                       if(dialogBoxExists)
+                                       /*if(dialogBoxExists)
                                                dialogAdvance();
-                                       else if(player->ground){
+                                       else */if(player->ground){
                                                player->vel.y=.4;
                                                player->loc.y+=HLINE*2;
                                                player->ground=false;
@@ -640,35 +643,65 @@ DONE:
                                        tmp = currentWorld;
                                        switch(SDL_KEY){
                                        case SDLK_a:
+                                               if(fadeEnable)break;
                                                player->vel.x=-.15;
                                                player->left = true;
                                                player->right = false;
                                                left = true;
                                                right = false;
-                                               currentWorld=currentWorld->goWorldLeft(player);
-                                               if(tmp!=currentWorld)
-                                                       dialogBoxExists = false;
+                                               if(currentWorld->isWorldLeft()){
+                                                       memcpy(&oldpos,&player->loc,sizeof(vec2));
+                                                       tmp = currentWorld->goWorldLeft(player);
+                                                       if(currentWorld != tmp){
+                                                               memcpy(&tmppos,&player->loc,sizeof(vec2));
+                                                               memcpy(&player->loc,&oldpos,sizeof(vec2));
+                                                               toggleBlackFast();
+                                                               waitForCover();
+                                                               memcpy(&player->loc,&tmppos,sizeof(vec2));
+                                                               currentWorld = tmp;
+                                                               toggleBlackFast();
+                                                               dialogBoxExists = false;
+                                                       }
+                                               }
                                                break;
                                        case SDLK_d:
+                                               if(fadeEnable)break;
                                                player->vel.x=.15;
                                                player->right = true;
                                                player->left = false;
                                                left = false;
                                                right = true;
-                                               currentWorld=currentWorld->goWorldRight(player);
-                                               if(tmp!=currentWorld)
-                                                       dialogBoxExists = false;
+                                               if(currentWorld->isWorldRight()){
+                                                       memcpy(&oldpos,&player->loc,sizeof(vec2));
+                                                       tmp = currentWorld->goWorldRight(player);
+                                                       if(currentWorld != tmp){
+                                                               memcpy(&tmppos,&player->loc,sizeof(vec2));
+                                                               memcpy(&player->loc,&oldpos,sizeof(vec2));
+                                                               toggleBlackFast();
+                                                               waitForCover();
+                                                               memcpy(&player->loc,&tmppos,sizeof(vec2));
+                                                               currentWorld = tmp;
+                                                               toggleBlackFast();
+                                                               dialogBoxExists = false;
+                                                       }
+                                               }
                                                break;
                                        case SDLK_s:
-                                               if(player->ground == 2){
+                                               /*if(player->ground == 2){
                                                        player->ground=false;
                                                        player->loc.y-=HLINE*1.5;
-                                               }
+                                               }*/
                                                break;
                                        case SDLK_w:
-                                               if(inBattle)
-                                                        currentWorld=((Arena *)currentWorld)->exitArena(player);
-                                               else currentWorld=currentWorld->goInsideStructure(player);
+                                               if(inBattle){
+                                                       tmp = currentWorld;
+                                                       currentWorld = ((Arena *)currentWorld)->exitArena(player);
+                                                       if(tmp != currentWorld){
+                                                               //delete &tmp;
+                                                               toggleBlackFast();
+                                                       }
+                                               }else
+                                                       currentWorld=currentWorld->goInsideStructure(player);
                                                break;
                                        case SDLK_i:
                                                currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible  
@@ -718,6 +751,13 @@ DONE:
                                        default:
                                                break;
                                        }
+                                       if(tmp != currentWorld){
+                                               std::swap(tmp,currentWorld);
+                                               toggleBlackFast();
+                                               waitForCover();
+                                               std::swap(tmp,currentWorld);
+                                               toggleBlackFast();
+                                       }
                                }
                                break;
                        /*
@@ -795,4 +835,11 @@ DONE:
                fadeWhite = true;
                fadeFast = false;
        }
+       void toggleWhiteFast(void){
+               fadeEnable ^= true;
+               fadeWhite = true;
+               fadeFast = true;
+               battleStart = Mix_LoadWAV("assets/sounds/frig.wav");
+               Mix_PlayChannel(1,battleStart,0);
+       }
 }
index 3f35e21222ebd595d15f8291be2e9de7d347f630..7b578d35e983a4c98aa037e5abdff53ffb07c075 100644 (file)
@@ -351,7 +351,7 @@ LLLOOP:
                current=current->infront;
                goto LLLOOP;
        }
-       cx_start = current->x_start;
+       cx_start = current->x_start * 1.5;
        width = (-x_start) << 1;
        
        glEnable(GL_TEXTURE_2D);
@@ -437,6 +437,9 @@ LLLOOP:
        
        glDisable(GL_TEXTURE_2D);
        
+       glColor3ub(0,0,0);
+       glRectf(cx_start,GEN_MIN,-cx_start,0);
+       
        /*
         *      World drawing is done recursively, meaning that this function jumps
         *      back as many 'layers' as it can and then draws, eventually coming
@@ -941,6 +944,14 @@ World *World::goWorldFront(Player *p){
        return this;
 }
 
+bool World::isWorldLeft(void){
+       return toLeft ? true : false;
+}
+
+bool World::isWorldRight(void){
+       return toRight ? true : false;
+}
+
 std::vector<void *>thing;
 World *World::goInsideStructure(Player *p){
        if(!thing.size()){
@@ -1078,18 +1089,13 @@ extern bool inBattle;
 
 Arena::Arena(World *leave,Player *p){
        generate(300);
-       //door.y = line[299].y;
-       //door.x = 100;
-       exit = leave;
-       
-       /*npc.push_back(new NPC());
-       entity.push_back(npc.back());
-       entity.back()->spawn(door.x,door.y);
-       entity.back()->width = HLINE * 12;
-       entity.back()->height = HLINE * 16;*/
-       
+       addMob(MS_DOOR,100,100);
        inBattle = true;
+       exit = leave;
        pxy = p->loc;
+       
+       star = new vec2[100];
+       memset(star,0,100 * sizeof(vec2));
 }
 
 Arena::~Arena(void){
@@ -1101,11 +1107,11 @@ Arena::~Arena(void){
 }
 
 World *Arena::exitArena(Player *p){
-       npc[0]->loc.x = door.x;
-       npc[0]->loc.y = door.y;
-       if(p->loc.x + p->width / 2 > door.x                              &&
-          p->loc.x + p->width / 2 < door.x + HLINE * 12 ){
+       if(p->loc.x + p->width / 2 > mob[0]->loc.x                              &&
+          p->loc.x + p->width / 2 < mob[0]->loc.x + HLINE * 12 ){
                inBattle = false;
+               ui::toggleBlackFast();
+               ui::waitForCover();
                p->loc = pxy;
                return exit;
        }else{