]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Fixed mouse, and debug
authorAndy Belle-Isle <abelleisle@roadrunner.com>
Wed, 16 Sep 2015 15:48:48 +0000 (11:48 -0400)
committerAndy Belle-Isle <abelleisle@roadrunner.com>
Wed, 16 Sep 2015 15:48:48 +0000 (11:48 -0400)
include/UIClass.h
include/World.h
include/common.h
include/entities.h
src/UIClass.cpp
src/World.cpp
src/entities.cpp
src/main.cpp

index e6f48256dbd62e1819d94cfb01b2a4ef98bc8d19..9bf301c4d2cfd3ec8240539cce0f96402cae6e24 100644 (file)
@@ -16,6 +16,7 @@ public:
        void msgBox(const char *str,...);\r
        void handleEvents();\r
        int mousex, mousey;\r
+       bool debug = false;\r
 };\r
 \r
 #endif // UICLASS_H\r
index fca108d52cf3264b6504a270cb5e754a0f138d8e..7d9224e6b8c408aa2a9919d0081113babfc9b902 100644 (file)
@@ -4,7 +4,7 @@
 #include <common.h>\r
 \r
 // Total amount of entities that can be bound to a layer\r
-#define MAX_ENTITIES 16\r
+#define MAX_ENTITIES 32\r
 \r
 // Easy shortcuts used in UIClass\r
 #define goWorldLeft(w)  if(w->toLeft){w=w->toLeft;}\r
@@ -18,7 +18,7 @@ private:
        } __attribute__ ((packed)) *line;\r
        unsigned int lineCount;                   // Size of line array, calculated in the constructor\r
        unsigned int entCount;                    // Count of currently bound entities\r
-       void *entity[MAX_ENTITIES];\r
+       void **entity;\r
 public:\r
        World *behind,*infront;                                                   // As in layers\r
        World *toLeft,*toRight;                                                   // 'new' worlds (off screen)\r
@@ -31,4 +31,4 @@ public:
        void addEntity(void *e);                                                  // Adds (binds) an entity to the world\r
 };\r
 \r
-#endif // WORLD_H
+#endif // WORLD_H\r
index 290e47a263b1ed34f565e66ab423e1d5c422cb7c..bddb1b38e29bea58530a20d38cf0c91fbaf56bf9 100644 (file)
@@ -7,6 +7,7 @@ typedef struct{float x; float y;}vec2;
 
 #include <iostream>
 #include <cstdlib>
+#include <math.h>
 #include <SDL2/SDL.h>
 #include <SDL2/SDL_image.h>
 #include <SDL2/SDL_opengl.h>
index 7d5e356a40fb2b4fb631dfd3a92d3428bd02acb0..bc277cdb82904bda9999f0b3a2156800ccf2a3f6 100644 (file)
@@ -16,6 +16,8 @@ public:
        bool right,left, canMove;
        bool alive;
 
+       unsigned int texture[];
+
        void spawn(float, float);
        void draw(void);
        void wander(int, vec2*);
index 04975756e7df87b97a4a27d5ec69b894922cd2e9..0ee56cadf02c6df19f032c7af81c74c4e6965f68 100644 (file)
@@ -144,6 +144,9 @@ void UIClass::handleEvents(){
                                        currentWorld=currentWorld->infront;
                                }
                        }
+                       if(e.key.keysym.sym == SDLK_F3){
+                               debug = !debug;
+                       }
                        break;
                case SDL_KEYUP:
                        if(e.key.keysym.sym == SDLK_d) player.right = false;
index bde35de3dd27264cc1676e5efdd9c7421fdee00b..4237d42a278a2a332018d96472f7ac7912a392f9 100644 (file)
@@ -24,6 +24,7 @@ World::World(const float width,World *l,World *r){
        toRight=r;\r
        behind=infront=NULL;\r
        entCount=0;\r
+       entity=(void**)calloc(MAX_ENTITIES,sizeof(void**));\r
        if(toLeft){                                                                                                                                     // Make sure linked worlds link back\r
                if(toLeft->toRight){\r
                        std::cout<<"There's already a world to the left!"<<std::endl;\r
index b418534b9038fa3e34dd9ea46afc3f4479fa26a0..ee909d87a0f2e99b0368f7b30665b7ba810f1429 100644 (file)
@@ -50,7 +50,8 @@ NPC::NPC(){
 }
 
 void NPC::interact(){
-
+       loc.y += .01;
+       
 }
 
 Structures::Structures(){
index 1843f4a87fddf9ecee791d86fba3ec6bc1e20ccd..cad8fc9cb2c7d6368e87efa06eff065a1c08fcd8 100644 (file)
@@ -10,6 +10,7 @@ SDL_Surface   *renderSurface = NULL;
 SDL_GLContext  mainGLContext = NULL;
 
 bool gameRunning = true;
+static float mx,my;
 
 static unsigned int tickCount   = 0,
                                        prevTime    = 0,
@@ -94,11 +95,11 @@ int main(int argc,char **argv){
        // Generate the world
        World *w=NULL,*w2=NULL;
        w2=new World(4,w,NULL);
-       w=new World(10,NULL,w2);
+       w=new World(20,NULL,w2);
        
        spawn=currentWorld=w;
-       currentWorld->addLayer(3);
-       currentWorld->addLayer(4);
+       currentWorld->addLayer(15);
+       currentWorld->addLayer(10);
        // shh
        unsigned char jklasdf;
        for(jklasdf=0;jklasdf<npcAmt;jklasdf++){
@@ -139,7 +140,6 @@ int main(int argc,char **argv){
 }
 
 void render(){
-       static float mx,my;
        static float d,fps;
        static unsigned int div=0;
                                                                                                        //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack"
@@ -166,7 +166,12 @@ void render(){
        **** RENDER STUFF HERE ****
        **************************/
        currentWorld->draw(); // layers dont scale x correctly...
-       glColor3ub(120,30,30);                                                  //render the player
+
+       if((mx > player.loc.x && mx < player.loc.x + player.width) && (my > player.loc.y && my < player.loc.y + player.height)){
+               glColor3ub(255,0,0);
+       }else{
+               glColor3ub(120,30,30);                                                  //render the player
+       }
        glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height);
 
        
@@ -180,7 +185,6 @@ void render(){
                d=deltaTime;
                fps=(1000/d);
        }
-       ui.putText(-.98 + player.loc.x, .94, "FPS: %1.0f\nDT: %1.0f",fps);
        //ui.putText(-.98 + player.loc.x, .88, "DT: %1.0f",d);
        ui.putText(player.loc.x,player.loc.y-(HLINE*10),"(%+1.3f,%+1.3f)",player.loc.x,player.loc.y);
        
@@ -188,10 +192,21 @@ void render(){
        ****  CLOSE THE LOOP   ****
        **************************/
 
-       //DRAW MOUSE HERE!!!!!W
+       //DRAW MOUSE HERE!!!!!
        mx=(ui.mousex/(float)SCREEN_WIDTH)*2.0f-1.0f;
        my=((SCREEN_HEIGHT-ui.mousey)/(float)SCREEN_HEIGHT)*2.0f-1.0f;
-       if(player.loc.x-1>-1)mx+=player.loc.x;
+       if(player.loc.x-1>-1 && player.loc.x-1<-3+currentWorld->getWidth()){
+               if(ui.debug)
+                       ui.putText(-.98 + player.loc.x, .94, "FPS: %1.0f\nDT: %1.0f",fps, d);
+               mx+=player.loc.x;
+       }else if(player.loc.x-1>=-3+currentWorld->getWidth()){
+               if(ui.debug)
+                       ui.putText(-.98 + -2+currentWorld->getWidth(), .94, "FPS: %1.0f\nDT: %1.0f",fps, d);
+               mx =mx-1 + -1+currentWorld->getWidth();
+       }else{
+               if(ui.debug)
+                       ui.putText(-.98, .94, "FPS: %1.0f\nDT: %1.0f",fps, d);
+       }
 
        glBegin(GL_TRIANGLES);
 
@@ -238,6 +253,12 @@ void logic(){
                if(npc[i].alive == true){
                        currentWorld->detect(&npc[i].loc,&npc[i].vel,npc[i].width);
                        entnpc[i]->wander((grand()%181 + 1), &npc[i].vel);
+                       if((mx > entnpc[i]->loc.x && mx < entnpc[i]->loc.x + entnpc[i]->width) && (my > entnpc[i]->loc.y && my < entnpc[i]->loc.y + entnpc[i]->height)&&(SDL_GetMouseState(NULL,NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))){
+                               if(pow((entnpc[i]->loc.x - player.loc.x),2) + pow((entnpc[i]->loc.y - player.loc.y),2) < pow(.2,2)){
+                                       entnpc[i]->interact();
+                                       ui.putText(entnpc[i]->loc.x, entnpc[i]->loc.y - HLINE * 3, "HEY", NULL);
+                               }
+                       }
                }
        }
        tickCount++;