]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
ROTATIONZ
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 5 Oct 2015 12:17:13 +0000 (08:17 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 5 Oct 2015 12:17:13 +0000 (08:17 -0400)
include/ui.h
src/entities.cpp
src/gameplay.cpp
src/main.cpp
src/ui.cpp

index b94b28468d8282e861e937f6fd7566b02a46a59f..5304c1b6513aad52d53c38a8d75c1c02a5be3325 100644 (file)
@@ -10,6 +10,7 @@ namespace ui {        // Functions are kept in a namespace simply
        extern vec2 mouse;
 
        extern bool debug;
+       extern bool dialogBoxExists;
        extern unsigned int fontSize;
 
        void initFonts(void);   // Checks for and initializes the FreeType 2 library
index bd0cc6706d86d24064ce69804aa0b282d5254d78..85ba53898a84ab1af9f3763929a7c5836c20cc72 100644 (file)
@@ -21,50 +21,35 @@ void Entity::spawn(float x, float y){       //spawns the entity you pass to it based o
 }
 
 void Entity::draw(void){               //draws the entities
-       glMatrixMode(GL_TEXTURE);
-       glLoadIdentity();
-       glEnable(GL_TEXTURE_2D);
-       glBindTexture(GL_TEXTURE_2D,texture);
-       glBegin(GL_QUADS);
+       glPushMatrix();
        if(type==NPCT){
                if(gender == MALE){
                        glColor3ub(255,255,255);
-                       glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
-                       glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
-                       glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
-                       glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height);
                }else if(gender == FEMALE){
                        glColor3ub(255,105,180);
-                       glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
-                       glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
-                       glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
-                       glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height);
                }
-       }
-       if(type==PLAYERT){
-               if(right==true){
-                       glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
-                       glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
-                       glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
-                       glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height);
-               }if(left==true){
-                       glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
-                       glScalef(-1.0f,1.0f,1.0f);
-                       glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
-                       glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
-                       glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
-                       glTexCoord2i(0,-0);glVertex2i(loc.x, loc.y + height);
+               if(NPCp(this)->aiFunc.size()){
+                       glColor3ub(255,255,0);
+                       glRectf(loc.x+width/3,loc.y+height,loc.x+width*2/3,loc.y+height+width/3);
                }
-
-       }else{
+       }
+       if(left){
+               glScalef(-1.0f,1.0f,1.0f);
+               glTranslatef(0-width-loc.x*2,0,0);
+       }
+       glMatrixMode(GL_TEXTURE);
+       glLoadIdentity();
+       glEnable(GL_TEXTURE_2D);
+       glBindTexture(GL_TEXTURE_2D,texture);
+       glBegin(GL_QUADS);
                glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
                glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
                glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
                glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height);
-       }
        glEnd();
        glDisable(GL_TEXTURE_2D);
        glMatrixMode(GL_MODELVIEW);
+       glPopMatrix();
        if(near){
                ui::setFontSize(14);
                ui::putText(loc.x,loc.y-ui::fontSize-HLINE/2,"%s",name);
index 93318281b24f77b7e8e9107648aede60a7da4e37..b6b939ab9a23dab0636d6f8f156c5c107b0fc74c 100644 (file)
@@ -9,21 +9,26 @@ extern std::vector<NPC>npc;
 extern std::vector<Structures *>build;
 extern Player *player;
 
-int giveTestQuest(NPC *speaker){
-       ui::dialogBox(speaker->name,"Here, have a quest!");
-       player->qh.assign("Test");
+extern void mainLoop(void);
+
+int compTestQuest(NPC *speaker){
+       ui::dialogBox(speaker->name,"Ooo, that's a nice quest you got there. Lemme finish that for you ;).");
+       player->qh.finish("Test",player);
        return 0;
 }
 
-int compTestQuest(NPC *speaker){
-       if(player->qh.hasQuest("Test")){
-               ui::dialogBox(speaker->name,"Ooo, that's a nice quest you got there. Lemme finish that for you ;).");
-               player->qh.finish("Test",player);
-               return 0;
-       }else{
-               ui::dialogBox(speaker->name,"You need to get a quest from %s first.",entity[1]->name);
-               return 1;
+int giveTestQuest(NPC *speaker){
+       static bool done=false;
+       if(!done){
+               ui::dialogBox(speaker->name,"Here, have a quest!");
+               player->qh.assign("Test");
+               done=true;
        }
+       /*while(ui::dialogBoxExists){   
+               mainLoop();
+       }*/
+       NPCp(entity[2])->addAIFunc(compTestQuest);
+       return 0;
 }
 
 void initEverything(void){
@@ -51,18 +56,8 @@ void initEverything(void){
        iw->generate(200);
        build[0]->inside=iw;
        
+       NPCp(entity[1])->addAIFunc(giveTestQuest);
        for(i=0;i<entity.size()+1;i++){
                entity[i]->inWorld=test;
-               switch(i){
-               case 1:
-                       NPCp(entity[i])->addAIFunc(giveTestQuest);
-                       entity[i]->inv->addItem(TEST_ITEM,3);
-                       break;
-               case 2:
-                       NPCp(entity[i])->addAIFunc(compTestQuest);
-                       break;
-               default:
-                       break;
-               }
        }
 }
index 9b16085f88d7e498a7f931f6bbd03b8356ef85ec..fdb7d32d601f7cb97368b1e315fc04b63ffd6dce 100644 (file)
@@ -13,10 +13,6 @@ SDL_Surface   *renderSurface = NULL;
 SDL_GLContext  mainGLContext = NULL;
 
 bool gameRunning = true;
-unsigned int tickCount   = 0,
-                        prevTime    = 0,
-                        currentTime = 0,
-                        deltaTime   = 0;
 
 World *currentWorld=NULL;
 Player *player;
@@ -35,6 +31,7 @@ extern void initEverything(void);
 
 void logic();
 void render();
+void mainLoop(void);
 
 unsigned int millis(void){
        std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
@@ -113,20 +110,8 @@ int main(int argc, char *argv[]){
        ****     GAMELOOP      ****
        **************************/
        
-       currentTime=millis();
        while(gameRunning){
-               prevTime = currentTime;
-               currentTime = millis();
-               deltaTime = currentTime - prevTime;
-               
-               if(prevTime + MSEC_PER_TICK >= millis()){
-                       logic();
-                       prevTime = millis();
-               }
-
-               player->loc.y+=player->vel.y*deltaTime;
-               player->loc.x+=(player->vel.x*player->speed)*deltaTime;
-               render();
+               mainLoop();
        }
        
        /**************************
@@ -140,6 +125,49 @@ int main(int argc, char *argv[]){
     return 0;
 }
 
+static unsigned int fps=0;
+static float debugY=0;
+
+unsigned int deltaTime=0;
+
+void mainLoop(void){
+       static unsigned int debugDiv=0;
+       static unsigned int tickCount = 0,
+                                               prevTime    = 0,
+                                               currentTime = 0,
+                                               deltatime   = 0;
+       unsigned int i;
+       
+       if(!currentTime)currentTime=millis();
+       prevTime = currentTime;
+       currentTime = millis();
+       deltatime = currentTime - prevTime;
+       deltaTime = deltatime;
+       
+       if(prevTime + MSEC_PER_TICK >= millis()){
+               logic();
+               prevTime = millis();
+       }
+
+       player->loc.y+=player->vel.y*deltatime;
+       player->loc.x+=(player->vel.x*player->speed)*deltatime;
+       for(int i=0;i<=entity.size();i++){
+               entity[i]->loc.x += entity[i]->vel.x * deltatime;
+               entity[i]->loc.y += entity[i]->vel.y * deltatime;
+               if(entity[i]->vel.x<0)entity[i]->left=true;
+               if(entity[i]->vel.x>0)entity[i]->left=false;
+       }
+       
+       if(++debugDiv==20){
+               fps=1000/deltatime;
+               debugDiv=0;
+       }else if(!(debugDiv%10)){
+               debugY = player->loc.y;
+       }
+       
+       render();
+}
+
 void render(){
                                                                                                        //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack"
                                                                                                        //GL_PROJECTION has 2 matrices
@@ -168,25 +196,9 @@ void render(){
        ui::draw();                                                     // Draw any UI elements if they need to be
 
        if(ui::debug){
-               static unsigned int debugDiv=0;
-               static int fps,d;
-               static float rndy; // variable to round the player y-coord so it is easier to read
-               if(++debugDiv==20){
-                       fps=1000/deltaTime;
-                       d=deltaTime;
-                       debugDiv=0;
-               }else if(debugDiv%10==0){
-                       rndy = player->loc.y;
-               }
                ui::setFontSize(16);
-               ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nD: %d G:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n     (y)%+.2f\nQc: %u",
-                                       fps,d,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT,entity.size(),player->loc.x,rndy,player->qh.current.size());
-       }
-
-       for(int i=0;i<=entity.size();i++){
-               //entity[i]->draw();
-               entity[i]->loc.x += entity[i]->vel.x * deltaTime;
-               entity[i]->loc.y += entity[i]->vel.y * deltaTime;
+               ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n     (y)%+.2f\nQc: %u",
+                                       fps,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT,entity.size(),player->loc.x,debugY,player->qh.current.size());
        }
 
        /**************************
index 80ecc69eaca371cec63d7df22b595a4fb2309de9..cd5de15b06f15cf43b3dd9501a1f847914176b4a 100644 (file)
@@ -12,12 +12,12 @@ static FT_Library   ftl;            // Variables for the FreeType library and stuff
 static FT_Face      ftf;
 static GLuint       ftex;
 
-static bool dialogBoxExists=false;
 static char *dialogBoxText;
 
 namespace ui {
        vec2 mouse;
        bool debug=false;
+       bool dialogBoxExists=false;
        unsigned int fontSize;
        /*
         * initFonts(), setFontFace(), and setFontSize() are pretty self-explanatory
@@ -184,6 +184,7 @@ namespace ui {
                        */
                        case SDL_KEYDOWN:
                                if(SDL_KEY==SDLK_ESCAPE)gameRunning=false;                                                      // Exit the game with ESC
+                       if(!dialogBoxExists){
                                if(SDL_KEY==SDLK_a){                                                                                            // Move left
                                        left=true;
                                        player->vel.x=-.15;
@@ -212,8 +213,9 @@ namespace ui {
                                }
                                if(SDL_KEY==SDLK_i)currentWorld=currentWorld->goWorldBack(player);      // Go back a layer if possible
                                if(SDL_KEY==SDLK_k)currentWorld=currentWorld->goWorldFront(player);     // Go forward a layer if possible
+                               if(SDL_KEY==SDLK_LSHIFT)player->speed = 3;                                                      // Sprint
+                       }
                                if(SDL_KEY==SDLK_F3)debug^=true;
-                               if(SDL_KEY==SDLK_LSHIFT)player->speed = 3;
                                break;
                        /*
                                KEYUP