diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-29 08:47:33 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-29 08:47:33 -0400 |
commit | 4031320180ff5e6c6452fc58575f5d7eac8eddbe (patch) | |
tree | 4dc3c3b2cdf2187d37936c070fa81bd7603bf790 /src | |
parent | 9137c25a3409a67ee04042e566f3c543d61d93d5 (diff) | |
parent | 1f2f646c41e90aa05ff561676752df2188fdd7ba (diff) |
fixed entity lags
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 19 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index b33f226..af4b45f 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -61,7 +61,7 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation } void NPC::interact(){ //have the npc's interact back to the player - //loc.y += .01; + loc.y += 5; } Structures::Structures(){ //sets the structure type diff --git a/src/main.cpp b/src/main.cpp index cb3c086..6c4047c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,8 @@ std::vector<Entity*>entity; std::vector<NPC>npc; std::vector<Structures>build; +int mx, my; + void logic(); void render(); @@ -172,6 +174,7 @@ void render(){ fps=1000/deltaTime; d=deltaTime; debugDiv=0; + }else if(debugDiv%10==0){ rndy = player->loc.y; } 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", @@ -189,12 +192,16 @@ void render(){ /************************** **** CLOSE THE LOOP **** **************************/ - int mx = ui::mouse.x, my=ui::mouse.y; + mx = ui::mouse.x + player->loc.x; + my = ui::mouse.y; my = 720 - my; mx -= (SCREEN_WIDTH/2); - glColor3ub(0,0,0); - glRectf(mx + player->loc.x, my, mx + player->loc.x + HLINE * 1, my + HLINE * 1); - + glColor3ub(255,255,255); + glBegin(GL_TRIANGLES); + glVertex2i(mx,my); + glVertex2i(mx+HLINE*3.5,my); + glVertex2i(mx,my-HLINE*3.5); + glEnd(); glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer SDL_GL_SwapWindow(window); //give the stack to SDL to render it @@ -206,6 +213,10 @@ void logic(){ for(int i=0;i<=entity.size();i++){ if(entity[i]->alive&&entity[i]->type == NPCT){ entity[i]->wander((rand()%120 + 30), &entity[i]->vel); + if( pow((entity[i]->loc.x - player->loc.x),2) + pow((entity[i]->loc.y - player->loc.y),2) <= pow(40,2)){ + if(mx >= entity[i]->loc.x && mx <= entity[i]->loc.x + entity[i]->width && my >= entity[i]->loc.y && my <= entity[i]->loc.y + entity[i]->width) + entity[i]->interact(); + } } } } |