]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Fixed gameloop timestep and updated animations
authordrumsetmonkey <abelleisle@roadrunner.com>
Tue, 1 Dec 2015 13:20:31 +0000 (08:20 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Tue, 1 Dec 2015 13:20:31 +0000 (08:20 -0500)
include/common.h
main.cpp
src/Texture.cpp
src/inventory.cpp
src/world.cpp

index 50ba3166c7cd95113ee26924d599f206e44b094a..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
 
index 5ac85babbff1e10015bbbe27b5d56eb0ee12490a..26c44f82fd4d34ae5375b35652b8bedd3567ee38 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -483,7 +483,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 +495,7 @@ void mainLoop(void){
        /*
         *      Run the logic handler if MSEC_PER_TICK milliseconds have passed.
        */
-       
-       if(prevPrevTime + MSEC_PER_TICK >= currentTime){
+       if(prevPrevTime + MSEC_PER_TICK <= currentTime){
                logic();
                prevPrevTime = currentTime;
        }
@@ -511,7 +509,6 @@ void mainLoop(void){
        /*
         *      Update debug variables if necessary
        */
-       
        if(++debugDiv==20){
                debugDiv=0;
                
@@ -522,7 +519,6 @@ void mainLoop(void){
        }
 
        render();       // Call the render loop
-       
 }
 
 extern bool fadeEnable;
@@ -773,7 +769,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 +779,6 @@ void render(){
                        ui::importantText("The screen is black.");
                }
        }else if(ui::fontSize != 16) ui::setFontSize(16);
-
        /**************************
        ****  END RENDERING   ****
        **************************/
@@ -805,7 +799,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 +809,12 @@ void logic(){
        /*
         *      Handle user input (keyboard & mouse).
        */
-
        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 +824,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 +897,6 @@ void logic(){
                        }else n->near=false;
                }
        }
-
        for(auto &m : currentWorld->mob){
                if(m->alive){
 
@@ -929,7 +918,6 @@ void logic(){
                        }
                }
        }
-
        unsigned int i = 0;
        for(auto &o : currentWorld->object){
                if(o->alive){
@@ -960,7 +948,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 +965,6 @@ void logic(){
        /*
         *      Transition to and from black if necessary.
        */
-
        if(fadeEnable){
                         if(fadeIntensity < 160)fadeIntensity+=5;
                else if(fadeIntensity < 255)fadeIntensity+=1;
index d723edacfa3476d55b438568fa8eca4c8a0400b0..de1af14676cfb24440e1030eec8af0800b1adfbf 100644 (file)
@@ -75,7 +75,7 @@ Texturec::Texturec(uint amt, ...){
 
 void Texturec::bind(unsigned int bn){
        texState = bn;
-       glBindTexture(GL_TEXTURE_2D, image[texState]);
+       glBindTexture(GL_TEXTURE_2D, (unsigned int)image[(int)texState]);
 }
 
 void Texturec::bindNext(){
index ff180b0d5797d09df9731889e43597ef237cf864..28612ae531032a7cd5f41f7aa2c9e5ebb0e1d291 100644 (file)
@@ -98,23 +98,23 @@ void Inventory::draw(void){
                //dfp[a] = 0;
                a++;
        }a=0;
-       if(invOpening && lop % 1 == 0){
+       if(invOpening){
                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;
                        a++;
                }a=0;
                if(end < numSlot)invOpen=true;
-       }else if(!invOpening && lop % 1 == 0){
-               for(auto &d : boost::adaptors::reverse(dfp)){
+       }else if(!invOpening){
+               for(auto &d : dfp){
                        if(d > 0){
-                               d-=25;
+                               d-=1.65*deltaTime;
                        }else end++;
                }
                if(end >= numSlot)invOpen=false;
index 36f0f696904334be825fb361e187f77254546a12..281cbadf8592694560e3f856bd07e5486751905f 100644 (file)
@@ -662,7 +662,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;
                        
                }