diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2015-09-29 08:46:08 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2015-09-29 08:46:08 -0400 |
commit | 1f2f646c41e90aa05ff561676752df2188fdd7ba (patch) | |
tree | f46d65bb8a0eaeeec35758476b20b2b6995062fb | |
parent | 764e0983c21247e325807933227b077bdc1ef6be (diff) |
Fixed mouse, and added the start to NPC interaction
-rw-r--r-- | include/common.h | 1 | ||||
-rw-r--r-- | src/entities.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 18 |
3 files changed, 17 insertions, 4 deletions
diff --git a/include/common.h b/include/common.h index 2a35317..0c35604 100644 --- a/include/common.h +++ b/include/common.h @@ -5,6 +5,7 @@ #include <iostream> #include <vector> +#include <math.h> #include <cstdlib> #include <SDL2/SDL.h> #include <SDL2/SDL_image.h> diff --git a/src/entities.cpp b/src/entities.cpp index 3560a2d..56141c1 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 d36929a..4be52fd 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",fps,d,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT,entity.size(),player->loc.x,rndy); @@ -188,11 +191,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); - 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 @@ -204,6 +212,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(); + } } } } |