currentTime=millis();
prevPrevTime=currentTime;
}
-
/*
* Update timing values. This is crucial to calling logic and updating the window (basically
* the entire game).
/*
* 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;
}
/*
* Update debug variables if necessary
*/
-
if(++debugDiv==20){
debugDiv=0;
}
render(); // Call the render loop
-
}
extern bool fadeEnable;
/*
* Here we draw a black overlay if it's been requested.
*/
-
if(fadeIntensity){
glColor4ub(0,0,0,fadeIntensity);
glRectf(offset.x-SCREEN_WIDTH /2,
ui::importantText("The screen is black.");
}
}else if(ui::fontSize != 16) ui::setFontSize(16);
-
/**************************
**** END RENDERING ****
**************************/
}
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.
/*
* 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;
* 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){
}else n->near=false;
}
}
-
for(auto &m : currentWorld->mob){
if(m->alive){
}
}
}
-
unsigned int i = 0;
for(auto &o : currentWorld->object){
if(o->alive){
/*
* Switch between day and night (SUNNY and DARK) if necessary.
*/
-
if(!(tickCount%DAY_CYCLE)||!tickCount){
if(weather==SUNNY){
weather=DARK;
/*
* Transition to and from black if necessary.
*/
-
if(fadeEnable){
if(fadeIntensity < 160)fadeIntensity+=5;
else if(fadeIntensity < 255)fadeIntensity+=1;