diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-10 15:51:18 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-10 15:51:18 -0400 |
commit | 820bd80587b5dbba1f9a174ca17c5461880b97c1 (patch) | |
tree | 6e78fb6ad55c0d61d9e74bef48c6ff6685443705 /src | |
parent | becacb292c902bbbc55a196ba824a9ff678481ff (diff) |
more fixes :)
Diffstat (limited to 'src')
-rw-r--r-- | src/UIClass.cpp | 26 | ||||
-rw-r--r-- | src/World.cpp | 3 | ||||
-rw-r--r-- | src/entities.cpp | 20 | ||||
-rw-r--r-- | src/main.cpp | 58 |
4 files changed, 42 insertions, 65 deletions
diff --git a/src/UIClass.cpp b/src/UIClass.cpp index bf76336..56a9f47 100644 --- a/src/UIClass.cpp +++ b/src/UIClass.cpp @@ -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 diff --git a/src/World.cpp b/src/World.cpp index c3a76c7..24f836f 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -78,3 +78,6 @@ void World::detect(vec2 *v,const float width){ }
}
}
+float World::getWidth(void){
+ return (lineCount-1)*HLINE;
+}
diff --git a/src/entities.cpp b/src/entities.cpp index 1b8861a..8d582a1 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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(){} diff --git a/src/main.cpp b/src/main.cpp index 8bc01e2..52ef69b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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&¤tWorld->toRight){ + goWorldRight(currentWorld); + player.loci.x=-1+HLINE; + }else if(player.loci.x<-1&¤tWorld->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; +} |