diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 55 |
1 files changed, 38 insertions, 17 deletions
@@ -85,7 +85,6 @@ float handAngle; World *currentWorld=NULL; Player *player; - /* * Tells if player is currently inside a structure. */ @@ -215,7 +214,7 @@ typedef enum { RAIN } WEATHER; -#define DAY_CYCLE 2000 +#define DAY_CYCLE 300 static WEATHER weather = SUNNY; static vec2 star[100]; @@ -530,6 +529,7 @@ void mainLoop(void){ logic(); prevPrevTime = currentTime; } + //ui::handleMouse(); /* * Update player and entity coordinates. @@ -541,15 +541,15 @@ void mainLoop(void){ * Update debug variables if necessary */ - if(ui::debug){ - if(++debugDiv==20){ - debugDiv=0; - fps=1000/deltaTime; - }else if(!(debugDiv%10)){ - debugY = player->loc.y; - } - } - + if(++debugDiv==20){ + debugDiv=0; + + fps=1000/deltaTime; + + }else if(!(debugDiv%10)){ + debugY = player->loc.y; + } + render(); // Call the render loop } @@ -675,12 +675,15 @@ void render(){ * Draws stars if it is an appropriate time of day for them. */ + int base = 40 - (int)worldGetYBase(currentWorld); + int shade = worldShade*2; + if(((weather==DARK )&(tickCount%DAY_CYCLE)<DAY_CYCLE/2) || ((weather==SUNNY)&(tickCount%DAY_CYCLE)>DAY_CYCLE*.75) ){ if(tickCount%DAY_CYCLE){ // The above if statement doesn't check for exact midnight. - glColor4ub(255,255,255,255); + safeSetColorA(255,255,255,shade); for(unsigned int i=0;i<100;i++){ glRectf(star[i].x+offset.x*.9,star[i].y,star[i].x+offset.x*.9+HLINE,star[i].y+HLINE); } @@ -693,9 +696,6 @@ void render(){ * background elements should be. */ - int base = 40 - (int)worldGetYBase(currentWorld); - int shade = worldShade*2; - glEnable(GL_TEXTURE_2D); /* @@ -881,7 +881,7 @@ void render(){ ui::putText(offset.x-SCREEN_WIDTH/2, (offset.y+SCREEN_HEIGHT/2)-ui::fontSize, - "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nTc: %u\nQc: %u\n HA: %+.2f", + "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nTc: %u\nHA: %+.2f", fps, player->ground, SCREEN_WIDTH, // Window dimensions @@ -890,7 +890,6 @@ void render(){ player->loc.x, // The player's x coordinate debugY, // The player's y coordinate tickCount, - player->qh.current.size(), // Active quest count handAngle ); @@ -1075,6 +1074,28 @@ void logic(){ } } + unsigned int i = 0; + for(auto &o : currentWorld->object){ + if(o->alive){ + if(pow((o->loc.x - player->loc.x),2) + pow((o->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){ + + /* + * Check for a right click, and allow the Object to interact with the + * player if one was made. + */ + + if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){ + std::cout << "Picking up!\n"; + o->interact(); + } + } + } + if(!(o->alive)){ + currentWorld->object.erase(currentWorld->object.begin()+i); + } + i++; + } + /* * Switch between day and night (SUNNY and DARK) if necessary. */ |