]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Fixed mouse, and added the start to NPC interaction
authordrumsetmonkey <abelleisle@roadrunner.com>
Tue, 29 Sep 2015 12:46:08 +0000 (08:46 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Tue, 29 Sep 2015 12:46:08 +0000 (08:46 -0400)
include/common.h
src/entities.cpp
src/main.cpp

index 2a353177218188e16d75adf6f34dc6141b9d874f..0c356048748771617835d84a93a11f49a771ea0b 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <iostream>
 #include <vector>
+#include <math.h>
 #include <cstdlib>
 #include <SDL2/SDL.h>
 #include <SDL2/SDL_image.h>
index 3560a2da85ddd465b0627213db6a7a4e67d9849d..56141c14863e367e10ab4e2d7b5e20de9d5d58f1 100644 (file)
@@ -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
index d36929a62e871e9b2915abb31f92e1795356604a..4be52fd6135282c13b6ddcd5555dc96f5fb7f5d1 100644 (file)
@@ -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();
+                       }
                }
        }
 }