]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fixes
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 14 Sep 2015 20:50:45 +0000 (16:50 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 14 Sep 2015 20:50:45 +0000 (16:50 -0400)
include/UIClass.h
src/UIClass.cpp
src/World.cpp
src/main.cpp

index e61bf14117c35da47f04c03cbf9b6de2b98f18b8..9aafbd39a9b6b6e69e5220354a8fee65c60ce4fd 100644 (file)
@@ -2,13 +2,18 @@
 #define UICLASS_H\r
 \r
 #include <common.h>\r
+#include <cstdarg>\r
+#include <cstdio>\r
 \r
 class UIClass {\r
-       public:\r
-               void init(const char *ttf);\r
-               void setFontSize(unsigned int fs);\r
-               void putText(float x,float y,const char *s);\r
-               void handleEvents();\r
+private:\r
+       unsigned int fontSize;\r
+public:\r
+       void init(const char *ttf);\r
+       void setFontSize(unsigned int fs);\r
+       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
 \r
 #endif // UICLASS_H\r
index b0e020609d8ac519278c30203b008cfce937c078..68654c75e71219bf7007cc92ba0061f09c362230 100644 (file)
@@ -22,9 +22,10 @@ void UIClass::init(const char *ttf){
        
 }
 void UIClass::setFontSize(unsigned int fs){
-       FT_Set_Pixel_Sizes(ftf,0,fs);
+       fontSize=fs;
+       FT_Set_Pixel_Sizes(ftf,0,fontSize);
 }
-void UIClass::putText(float x,float y,const char *s){
+void UIClass::putString(const float x,const float y,const char *s){
        unsigned int i=0,j;
        float xo=x,yo=y,w,h;
        char *buf;
@@ -57,10 +58,20 @@ void UIClass::putText(float x,float y,const char *s){
                        glTexCoord2f(0,0);glVertex2f(xo,yo+h);
                glEnd();
                glDisable(GL_TEXTURE_2D);
-               xo+=w+.01;
+               xo+=w+(fontSize*.0001);
                free(buf);
        }while(s[i++]);
 }
+void UIClass::putText(const float x,const float y,const char *str,...){
+       va_list args;
+       char *buf;
+       buf=(char *)calloc(128,sizeof(char));
+       va_start(args,str);
+       vsnprintf(buf,128,str,args);
+       va_end(args);
+       putString(x,y,buf);
+       free(buf);
+}
 
 void UIClass::handleEvents(){
        static bool space=false;
@@ -91,6 +102,7 @@ void UIClass::handleEvents(){
                                        if(player.loc.x>thing-1&&
                                           player.loc.x<thing-1+currentWorld->behind->getWidth()){
                                                player.loc.x-=thing;
+                                               memset(&player.vel,0,sizeof(vec2));
                                                currentWorld=currentWorld->behind;
                                        }
                                }
@@ -98,6 +110,7 @@ void UIClass::handleEvents(){
                        if(e.key.keysym.sym == SDLK_k){
                                if(currentWorld->infront){
                                        player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2;
+                                       memset(&player.vel,0,sizeof(vec2));
                                        currentWorld=currentWorld->infront;
                                }
                        }
index 45df63c86faaeb9e8c945d3c83bd919df7d0df17..41649d9d5feee2600e87364a267c6db7ff8d95d4 100644 (file)
@@ -110,13 +110,14 @@ void World::detect(vec2 *v,vec2 *vel,const float width){
                if(v->y<line[i].start){                                                                                         // If we're inside the line\r
                        if(v->x>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){                                   // And we're inside it ;)\r
                                vel->y=0;v->y=line[i].start+HLINE/8;                                                    // Correct\r
-//                             return; // :/\r
+                               return; // :/\r
                        }else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){ // Same as above, but coming from right side instead of left\r
                                vel->y=0;v->y=line[i].start+HLINE/8;\r
-//                             return; // ;)\r
+                               return; // ;)\r
                        }\r
-               }else if(v->y>line[i].start+HLINE){                                                                     // Trashy gravity handling\r
-                       vel->y-=.0000002;\r
+               }\r
+               if(v->y>line[i].start+HLINE){                                                                   // Trashy gravity handling\r
+                       vel->y-=.0000001;\r
                }\r
        }\r
 }\r
index a92ff165e641361aca61d18fb880faa0a680412b..4d48d814e8e2558fd8c000d5733e8269a6f3e460 100644 (file)
@@ -1,6 +1,5 @@
 #include <common.h>
 #include <cstdio>
-#include <ctime>
 #include <chrono>
 
 #define TICKS_PER_SEC 20
@@ -29,17 +28,13 @@ World *currentWorld;//u-huh
 void logic();
 void render();
 
-static unsigned int initTime;
 unsigned int millis(void){
-       //return (float)(clock()-initTime)/(CLOCKS_PER_SEC/1000.0f);
        std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
-       std::chrono::nanoseconds m=now.time_since_epoch();
-       return std::chrono::duration_cast<std::chrono::milliseconds>(m).count();
+       return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
 }
 
 int main(int argc,char **argv){
-       float gw;
-    //runs start-up procedures
+       //runs start-up procedures
     if(!SDL_Init(SDL_INIT_VIDEO)){
        atexit(SDL_Quit);
        if(!(IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)&(IMG_INIT_PNG|IMG_INIT_JPG))){
@@ -80,7 +75,6 @@ int main(int argc,char **argv){
        **************************/
 
        ui.init("ttf/VCR_OSD_MONO_1.001.ttf");
-       ui.setFontSize(100);
 
        irand(time(NULL));
        entPlay = &player;
@@ -104,8 +98,7 @@ int main(int argc,char **argv){
                currentWorld->addEntity((void *)entnpc[jklasdf]);
        }
        
-       initTime=clock();
-       currentTime=initTime;
+       currentTime=millis();
        
        while(gameRunning){
                prevTime = currentTime;
@@ -118,6 +111,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);
                player.loc.y += player.vel.y * deltaTime;
                for(int i = 0; i < eAmt(entnpc); i++){
                        if(npc[i].alive == true){
@@ -125,26 +119,7 @@ int main(int argc,char **argv){
                                npc[i].loc.x += npc[i].vel.x * deltaTime;
                        }
            }
-               
-
-               gw=currentWorld->getWidth();
-               if(player.loc.x+player.width>-1+gw){
-                       if(currentWorld->toRight){
-                               goWorldRight(currentWorld)
-                               player.loc.x=-1+HLINE;
-                       }else{
-                               player.loc.x=gw-1-player.width-HLINE;
-                       }
-               }
-               if(player.loc.x<-1){
-                       if(currentWorld->toLeft){
-                               goWorldLeft(currentWorld);
-                               player.loc.x=currentWorld->getWidth()-1-player.width-HLINE;
-                       }else{
-                               player.loc.x=-1+HLINE;
-                       }
-               }
-
+           
                render();
        }
        
@@ -192,7 +167,8 @@ void render(){
                glRectf(build.loc.x, build.loc.y, build.loc.x + build.width, build.loc.y + build.height);
                ///BWAHHHHHHHHHHHH
                
-               ui.putText(0,0,"Hello");
+               ui.setFontSize(16);
+               ui.putText(player.loc.x,player.loc.y-(HLINE*10),"(%+1.3f,%+1.3f)",player.loc.x,player.loc.y);
                
                /**************************
                ****  CLOSE THE LOOP   ****
@@ -203,17 +179,12 @@ void render(){
 }
 
 void logic(){
-       static unsigned int lastTime=0;
        float gw;
        ui.handleEvents();                                                              // Handle events
 
-       if(player.right == true) {player.vel.x = .00075;}
-       if(player.left == true) {player.vel.x = -.00075;}
-       if(player.right == false && player.left == false) {player.vel.x = 0;}
-
-       //std::cout<<"\r("<<player.loc.x<<","<<player.loc.y<<")";
-       std::cout<<millis()-lastTime<<std::endl;
-       lastTime=millis();
+       if(player.right)player.vel.x=.00075;
+       else if(player.left)player.vel.x=-.00075;
+       else player.vel.x = 0;
 
        currentWorld->detect(&player.loc,&player.vel,player.width);
        gw=currentWorld->getWidth();