]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
more fixes :)
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 10 Sep 2015 19:51:18 +0000 (15:51 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 10 Sep 2015 19:51:18 +0000 (15:51 -0400)
include/World.h
include/entities.h
src/UIClass.cpp
src/World.cpp
src/entities.cpp
src/main.cpp

index d8440a07a8eb9ee7e69d0809d75f1eeeddfce653..f6a08f90bc0e1f4198917c6590204c12d052717c 100644 (file)
@@ -19,6 +19,7 @@ public:
        World(const float width,World *l,World *r);\r
        void draw(void);\r
        void detect(vec2 *v,const float width);\r
+       float getWidth(void);\r
 };\r
 \r
 #endif // WORLD_H
index 89d9ec3b7c716822649b763cb84ad20a363be672..5f0c9ee6635ca5463820c86b871b9ba795b17612 100644 (file)
@@ -1,10 +1,8 @@
-<<<<<<< HEAD
 #ifndef ENTITIES_H
 #define ENTITIES_H
 
 #include <common.h>
 
-
 class Entities{
 public:
        float width;
@@ -27,31 +25,4 @@ public:
        ~Player();
 };
 
-=======
-#ifndef ENTITIES_H
-#define ENTITIES_H
-
-#include <common.h>
-
-
-class Entities{
-public:
-       float width;
-       float height;
-       float speed;
-       int type;
-       vec2 loc;
-
-       void spawn(float, float);
-
-
-};
-
-class Player : public Entities{
-public:
-       Player();
-       ~Player();
-};
-
->>>>>>> origin/master
-#endif //ENTITIES_H
\ No newline at end of file
+#endif // ENTITIES_H
index bf76336d589ad0415d57402c8a9f68e485841568..56a9f47594c1295e9a5652b9d78e6ccfdfeb9cfc 100644 (file)
@@ -1,5 +1,5 @@
-<<<<<<< HEAD
 #include <UIClass.h>
+
 extern Player player;
 
 void UIClass::handleEvents(){
@@ -37,27 +37,3 @@ void UIClass::handleEvents(){
                }
        }
 }
-=======
-#include <UIClass.h>
-
-void UIClass::handleEvents(){
-       SDL_Event e;
-       while(SDL_PollEvent(&e)){
-               switch(e.type){
-               case SDL_QUIT:
-                       gameRunning=false;
-                       break;
-               case SDL_KEYDOWN:
-                       switch(e.key.keysym.sym){
-                       case 27:
-                               gameRunning=false;
-                               break;
-                       default:
-                               break;
-                       }
-               default:
-                       break;
-               }
-       }
-}
->>>>>>> origin/master
index c3a76c731dbd8603a2e7db26733429cbc12bbf44..24f836f520244edefe5ebfbdcd5bd65823e03fb4 100644 (file)
@@ -78,3 +78,6 @@ void World::detect(vec2 *v,const float width){
                }\r
        }\r
 }\r
+float World::getWidth(void){\r
+       return (lineCount-1)*HLINE;\r
+}\r
index 1b8861a11cef42edf6c9a003816bae36b708122b..8d582a1207b9e76fdd2645b561303edba9bc168f 100644 (file)
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
 #include <entities.h>
 
 void Entities::spawn(float x, float y){
@@ -19,21 +18,4 @@ Player::Player(){
        type = 0;
 }
 
-=======
-#include <entities.h>
-
-void Entities::spawn(float x, float y){
-       loc.x = x;
-       loc.y = y;
-
-}
-
-Player::Player(){
-       width = 24;
-       height = 42;
-       speed = 1;
-       type = 0;
-}
-
->>>>>>> origin/master
-Player::~Player(){}
\ No newline at end of file
+Player::~Player(){}
index 8bc01e2834cb6e3c5393b8cb3cf3dc1576408e43..52ef69beaa22913405e2510f98573a85f1ca0101 100644 (file)
@@ -1,23 +1,27 @@
 #include <common.h>
 #include <ctime>
 
+#define TICKS_PER_SEC 20
+#define MSEC_PER_TICK (1000/TICKS_PER_SEC)
+
 SDL_Window    *window = NULL;
 SDL_Surface   *renderSurface = NULL;
 SDL_GLContext  mainGLContext = NULL;
 
 bool gameRunning = true;
 
-const float ticksPerSec = 20;
-const float msecPerTick = 1000 / ticksPerSec;
-int prevTime = GetTickCount();
-int currentTime = 0;
-float deltaTime = 0;
+static unsigned int tickCount   = 0,
+                                       prevTime    = 0,
+                                       currentTime = 0,
+                                       deltaTime   = 0;
 
 Entities *entit1;
 Player player;
 UIClass ui;
 World *currentWorld;
 
+unsigned int logic(unsigned int interval,void *param);
+
 float interpolate(float goal, float current, float dt){
        float difference = goal - current;
        if(difference > dt){
@@ -61,6 +65,7 @@ int main(int argc,char **argv){
                return -1;
        }
        srand(time(NULL));
+       SDL_AddTimer(MSEC_PER_TICK,logic,NULL);
        glClearColor(.3,.5,.8,0);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
@@ -70,37 +75,35 @@ int main(int argc,char **argv){
        **************************/
 
        entit1 = &player;
-       entit1->spawn(4, 0);
+       entit1->spawn(0, 0);
 
        World *w=NULL;
        World *w2=new World(4,w,NULL);
        w=new World(2,NULL,w2);
        currentWorld=w;
        
+       float gw;
+       
        while(gameRunning){
                prevTime = currentTime;
-               currentTime = GetTickCount();
+               currentTime = tickCount;
                deltaTime = currentTime - prevTime;
-
-               if(prevTime + msecPerTick <= GetTickCount()){           //HANDLE ALL LOGIC STUFF HERE
-                       ui.handleEvents();                                                              // Handle events
-
-                       player.vel.x = 0;
-
-                       std::cout << player.vel.x << std::endl;
-                       std::cout << player.velg.y << std::endl;
-                       std::cout << "d:" << deltaTime << std::endl;
-
-                       prevTime = GetTickCount();
-               }
                                                                                                                        //DO ALL RENDERING HERE         
-               player.vel.x = interpolate(player.velg.x, player.vel.x, deltaTime) * .001;
+               player.vel.x = interpolate(player.velg.x, player.vel.x, deltaTime) * .005;
                if(player.vel.x > .05) player.vel.x = .05;
                if(player.vel.x < -.05) player.vel.x = -.05;
                player.loci.x += player.vel.x;
 
-               render();
+               gw=currentWorld->getWidth();
+               if(player.loci.x+player.width>-1+gw&&currentWorld->toRight){
+                       goWorldRight(currentWorld);
+                       player.loci.x=-1+HLINE;
+               }else if(player.loci.x<-1&&currentWorld->toLeft){
+                       goWorldLeft(currentWorld);
+                       player.loci.x=currentWorld->getWidth()-1-player.width-HLINE;
+               }
 
+               render();
        }
        
        /**************************
@@ -142,3 +145,16 @@ void render(){
                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
 }
+
+unsigned int logic(unsigned int interval,void *param){
+       ui.handleEvents();                                                              // Handle events
+
+       player.vel.x = 0;
+
+       //std::cout << player.vel.x << std::endl;
+       //std::cout << player.velg.y << std::endl;
+       //std::cout << "d:" << deltaTime << std::endl;
+
+       tickCount++;
+       return interval;
+}