From e02aaafad3ecef8752b538a2421c5e36fe4809c2 Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Tue, 1 Dec 2015 08:20:31 -0500 Subject: Fixed gameloop timestep and updated animations --- include/common.h | 4 ++-- main.cpp | 16 +--------------- src/Texture.cpp | 2 +- src/inventory.cpp | 12 ++++++------ src/world.cpp | 2 +- 5 files changed, 11 insertions(+), 25 deletions(-) diff --git a/include/common.h b/include/common.h index 50ba316..52daf4b 100644 --- a/include/common.h +++ b/include/common.h @@ -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 diff --git a/main.cpp b/main.cpp index 5ac85ba..26c44f8 100644 --- 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; diff --git a/src/Texture.cpp b/src/Texture.cpp index d723eda..de1af14 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -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(){ diff --git a/src/inventory.cpp b/src/inventory.cpp index ff180b0..28612ae 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -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; diff --git a/src/world.cpp b/src/world.cpp index 36f0f69..281cbad 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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; } -- cgit v1.2.3