]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added mouse support, and debug
authorAndy Belle-Isle <abelleisle@roadrunner.com>
Tue, 15 Sep 2015 01:20:01 +0000 (21:20 -0400)
committerAndy Belle-Isle <abelleisle@roadrunner.com>
Tue, 15 Sep 2015 01:20:09 +0000 (21:20 -0400)
Added FPS display and deltaTime display

include/UIClass.h
include/entities.h
src/entities.cpp
src/main.cpp

index 9aafbd39a9b6b6e69e5220354a8fee65c60ce4fd..62d3e7e5a4b6613abcc88dc6f622af22ce57ed1f 100644 (file)
@@ -14,6 +14,8 @@ public:
        void putText(const float x,const float y,const char *s,...);\r
        void putString(const float x,const float y,const char *s);\r
        void handleEvents();\r
+\r
+       float mousex, mousey;\r
 };\r
 \r
 #endif // UICLASS_H\r
index 2ed97ee2f48330a8f3fb172eee140fd0cd3e864e..7d5e356a40fb2b4fb631dfd3a92d3428bd02acb0 100644 (file)
@@ -19,6 +19,7 @@ public:
        void spawn(float, float);
        void draw(void);
        void wander(int, vec2*);
+       virtual void interact(){}
 private:
        int ticksToUse;
 };
@@ -26,11 +27,13 @@ private:
 class Player : public Entity{
 public:
        Player();
+       void interact();
 };
 
 class NPC : public Entity{
 public:
        NPC();
+       void interact();
 };
 
 extern Entity *entnpc[32];     //The NPC base
index e9e69ce5782bd5836f4cd175f30a9cf379b1b742..b418534b9038fa3e34dd9ea46afc3f4479fa26a0 100644 (file)
@@ -35,6 +35,10 @@ Player::Player(){
        alive = true;
 }
 
+void Player::interact(){
+       
+}
+
 NPC::NPC(){    
        width = HLINE * 8;
        height = HLINE * 18;
@@ -45,6 +49,10 @@ NPC::NPC(){
        canMove = true;
 }
 
+void NPC::interact(){
+
+}
+
 Structures::Structures(){
        type = -1;
        speed = 0;
index f3e95eea747e2625301fd51bd4b13cb1e740c11f..905e4cdca2455af74f8041ffbc4d4dae51e6ba79 100644 (file)
@@ -71,6 +71,7 @@ int main(int argc,char **argv){
        glClearColor(.3,.5,.8,0);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+       SDL_ShowCursor(SDL_DISABLE);
        
        /**************************
        ****     GAMELOOP      ****
@@ -113,7 +114,7 @@ int main(int argc,char **argv){
                }
 
                player.loc.x += (player.vel.x * player.speed) * deltaTime;                                              //update the player's x based on 
-//             printf("%lf * %u\n",player.vel.y,deltaTime);
+               //printf("%lf * %u\n",player.vel.y,deltaTime);
                player.loc.y += player.vel.y * deltaTime;
                for(int i = 0; i < eAmt(entnpc); i++){
                        if(npc[i].alive == true){
@@ -122,6 +123,8 @@ int main(int argc,char **argv){
                        }
            }
            
+           SDL_GetMouseState((int*)(&ui.mousex), (int*)(&ui.mousey));
+           ui.mousey = SCREEN_HEIGHT - ui.mousey;
                render();
        }
        
@@ -159,7 +162,6 @@ void render(){
                /**************************
                **** RENDER STUFF HERE ****
                **************************/
-                
                currentWorld->draw(); // layers dont scale x correctly...
                glColor3ub(120,30,30);                                                  //render the player
                glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height);
@@ -169,13 +171,20 @@ void render(){
                glRectf(build.loc.x, build.loc.y, build.loc.x + build.width, build.loc.y + build.height);
                ///BWAHHHHHHHHHHHH
                
+               float d = deltaTime;
+               float fps = (1000 / d);
+
                ui.setFontSize(16);
+               ui.putText(-.98 + player.loc.x, .94, "FPS: %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);
                
                /**************************
                ****  CLOSE THE LOOP   ****
                **************************/
 
+               //DRAW MOUSE HERE!!!!!W
+
                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
 }
@@ -188,6 +197,8 @@ void logic(){
        else if(player.left)player.vel.x=-.00075;
        else player.vel.x = 0;
 
+       std::cout << deltaTime << std::endl;
+
        currentWorld->detect(&player.loc,&player.vel,player.width);
        gw=currentWorld->getWidth();
        if(player.loc.x+player.width>-1+gw){
@@ -211,7 +222,7 @@ void logic(){
        for(int i = 0; i < eAmt(entnpc); i++){
                if(npc[i].alive == true){
                        currentWorld->detect(&npc[i].loc,&npc[i].vel,npc[i].width);
-                       entnpc[i]->wander((grand()%91 + 1), &npc[i].vel);
+                       entnpc[i]->wander((grand()%181 + 1), &npc[i].vel);
                }
        }
        tickCount++;