From: Clyne Sullivan Date: Thu, 10 Sep 2015 19:24:39 +0000 (-0400) Subject: fixed X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=becacb292c902bbbc55a196ba824a9ff678481ff;p=clyne%2Fgamedev.git fixed --- becacb292c902bbbc55a196ba824a9ff678481ff diff --cc include/World.h index 3b4b56d,dd133b9..d8440a0 --- a/include/World.h +++ b/include/World.h @@@ -1,24 -1,42 +1,24 @@@ -<<<<<<< HEAD -#ifndef WORLD_H -#define WORLD_H - -#include - -class World { -private: - struct line_t { - // x = 2.0 (window width) / HLINES - float start; // Where to change to dirt, going down (y) - } *line; - unsigned int lineCount; -public: - World(float width); - void draw(void); -}; - +#ifndef WORLD_H +#define WORLD_H + +#include + +#define goWorldLeft(w) if(w->toLeft){w=w->toLeft;} +#define goWorldRight(w) if(w->toRight){w=w->toRight;} + +class World { +private: + struct line_t { + // x = 2.0 (window width) / HLINES + double start; // Where to change to dirt, going down (y) + } *line; + unsigned int lineCount; +public: + World *toLeft,*toRight; + World(void); + World(const float width,World *l,World *r); + void draw(void); + void detect(vec2 *v,const float width); +}; + - #endif // WORLD_H + #endif // WORLD_H -======= -#ifndef WORLD_H -#define WORLD_H - -#include - -#define HLINE (2.0f/(SCREEN_WIDTH/4)) - -class World { -private: - struct line_t { - // x = 2.0 (window width) / HLINES - double start; // Where to change to dirt, going down (y) - } *line; - unsigned int lineCount; -public: - World(float width); - void draw(void); - void detect(vec2 *v,const float width); -}; - -#endif // WORLD_H ->>>>>>> origin/master diff --cc include/common.h index 9ce1be0,48a068d..df5b6ac --- a/include/common.h +++ b/include/common.h @@@ -1,31 -1,65 +1,31 @@@ - #ifndef COMMON_H - #define COMMON_H - - typedef struct{float x; float y;}vec2; - - ///THIS FILE IS USED FOR VARIABLES THAT WILL BE ACCESED BY MULTIPLE CLASSES/FILES - - #include - #include - #include - #include - #include - #include - #include - #include - - #define SCREEN_WIDTH 1280 - #define SCREEN_HEIGHT 800 - #define FULLSCREEN - - #define HLINE (2.0f/(SCREEN_WIDTH/4)) - - //SDL VARIABLES - extern SDL_Window *window; - extern SDL_Surface *renderSurface; - extern SDL_GLContext mainGLContext; - - //WINODWS VARIABLES - extern bool gameRunning; - - #endif // COMMON_H -<<<<<<< HEAD + #ifndef COMMON_H + #define COMMON_H + + typedef struct{float x; float y;}vec2; + + ///THIS FILE IS USED FOR VARIABLES THAT WILL BE ACCESED BY MULTIPLE CLASSES/FILES + + #include + #include + #include + #include + #include + #include + #include + #include + + #define SCREEN_WIDTH 1280 + #define SCREEN_HEIGHT 720 + //#define FULLSCREEN + + #define HLINE (2.0f / (SCREEN_WIDTH / 4)) + + //SDL VARIABLES + extern SDL_Window *window; + extern SDL_Surface *renderSurface; + extern SDL_GLContext mainGLContext; + + //WINDOW VARIABLES + extern bool gameRunning; + + #endif // COMMON_H -======= -#ifndef COMMON_H -#define COMMON_H - -typedef struct{float x; float y;}vec2; - -///THIS FILE IS USED FOR VARIABLES THAT WILL BE ACCESED BY MULTIPLE CLASSES/FILES - -#include -#include -#include -#include -#include -#include -#include -#include - -#define SCREEN_WIDTH 1280 -#define SCREEN_HEIGHT 800 -#define FULLSCREEN - - - -//SDL VARIABLES -extern SDL_Window *window; -extern SDL_Surface *renderSurface; -extern SDL_GLContext mainGLContext; - -//WINODWS VARIABLES -extern bool gameRunning; - -#endif // COMMON_H ->>>>>>> origin/master diff --cc src/main.cpp index fa3a9c4,e5c2339..8bc01e2 --- a/src/main.cpp +++ b/src/main.cpp @@@ -1,102 -1,241 +1,144 @@@ - #include - #include - - SDL_Window *window = NULL; - SDL_Surface *renderSurface = NULL; - SDL_GLContext mainGLContext = NULL; - - bool gameRunning = true; - - UIClass ui; - Entities *entit1; - Player player; - World *currentWorld; - - int main(int argc,char **argv){ - // Initialize SDL - if(!SDL_Init(SDL_INIT_VIDEO)){ - atexit(SDL_Quit); - }else{ - std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl; - return -1; - } - // Initialize SDL_image - if((IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)&(IMG_INIT_PNG|IMG_INIT_JPG))){ - atexit(IMG_Quit); - }else{ - std::cout<<"Could not init image libraries!\n"<spawn(0,0); - - World *w=NULL; - World *w2=new World(4,w,NULL); - w=new World(2,NULL,w2); - currentWorld=w; - - while(gameRunning){ - ui.handleEvents(); // Handle events - //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack" - //GL_PROJECTION has 2 matrices - //GL_MODELVIEW has 32 matrices - glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on - glPushMatrix(); //push the matrix to the top of the matrix stack - glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode - glOrtho(-1,1,-1,1,-1,1); //set the the size of the screen - glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects - glPushMatrix(); //push the matrix to the top of the matrix stack - glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode - glPushMatrix(); //basically here we put a blank canvas (new matrix) on the screen to draw on - glClear(GL_COLOR_BUFFER_BIT); //clear the matrix on the top of the stack - - /************************** - **** RENDER STUFF HERE **** - **************************/ - - currentWorld->draw(); - glColor3ub(0,0,0); - glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height); - - /************************** - **** CLOSE THE LOOP **** - **************************/ - - 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 - } - - /************************** - **** CLOSE PROGRAM **** - **************************/ - - //closes the window and frees resources - SDL_GL_DeleteContext(mainGLContext); - SDL_DestroyWindow(window); - return 0; - } -<<<<<<< HEAD + #include + #include + + 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; + + Entities *entit1; + Player player; + UIClass ui; ++World *currentWorld; + + float interpolate(float goal, float current, float dt){ + float difference = goal - current; + if(difference > dt){ + return current + dt;} + if(difference < dt){ + return current - dt;} + return goal; + } + - -World *w=new World(2); + void render(); + + int main(int argc,char **argv){ + //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))){ + std::cout<<"Could not init image libraries!\n"<spawn(4, 0); ++ ++ World *w=NULL; ++ World *w2=new World(4,w,NULL); ++ w=new World(2,NULL,w2); ++ currentWorld=w; + + while(gameRunning){ + prevTime = currentTime; + currentTime = GetTickCount(); + 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; + 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(); + + } + + /************************** + **** CLOSE PROGRAM **** + **************************/ + + //closes the window and frees resources + SDL_GL_DeleteContext(mainGLContext); + SDL_DestroyWindow(window); + return 0; + } + + void render(){ + //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack" + //GL_PROJECTION has 2 matrices + //GL_MODELVIEW has 32 matrices + glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on + glPushMatrix(); //push the matrix to the top of the matrix stack + glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode + glOrtho(-1 + player.loci.x, 1 + player.loci.x , -1, 1, -1,1); //set the the size of the screen + glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects + glPushMatrix(); //push the matrix to the top of the matrix stack + glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode + glPushMatrix(); //basically here we put a blank canvas (new matrix) on the screen to draw on + glClear(GL_COLOR_BUFFER_BIT); //clear the matrix on the top of the stack + + /************************** + **** RENDER STUFF HERE **** + **************************/ + - w->draw(); ++ currentWorld->draw(); + glColor3ub(0,0,0); + glRectf(player.loci.x, player.loci.y, player.loci.x + player.width, player.loci.y + player.height); + + /************************** + **** CLOSE THE LOOP **** + **************************/ + + 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 + } -======= -#include -#include - -SDL_Window *window = NULL; -SDL_Surface *renderSurface = NULL; -SDL_GLContext mainGLContext = NULL; - -bool gameRunning = true; - -UIClass ui; -Entities *entit1; -Player player; - -int main(int argc,char **argv){ - // Initialize SDL - if(!SDL_Init(SDL_INIT_VIDEO)){ - atexit(SDL_Quit); - }else{ - std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl; - return -1; - } - // Initialize SDL_image - if((IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)&(IMG_INIT_PNG|IMG_INIT_JPG))){ - atexit(IMG_Quit); - }else{ - std::cout<<"Could not init image libraries!\n"<spawn(0,0); - - World *w=new World(2); - - while(gameRunning){ - ui.handleEvents(); // Handle events - //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack" - //GL_PROJECTION has 2 matrices - //GL_MODELVIEW has 32 matrices - glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on - glPushMatrix(); //push the matrix to the top of the matrix stack - glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode - glOrtho(-1,1,-1,1,-1,1); //set the the size of the screen - glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects - glPushMatrix(); //push the matrix to the top of the matrix stack - glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode - glPushMatrix(); //basically here we put a blank canvas (new matrix) on the screen to draw on - glClear(GL_COLOR_BUFFER_BIT); //clear the matrix on the top of the stack - - /************************** - **** RENDER STUFF HERE **** - **************************/ - - w->draw(); - glColor3ub(0,0,0); - glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height); - - /************************** - **** CLOSE THE LOOP **** - **************************/ - - 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 - } - - /************************** - **** CLOSE PROGRAM **** - **************************/ - - //closes the window and frees resources - SDL_GL_DeleteContext(mainGLContext); - SDL_DestroyWindow(window); - return 0; -} ->>>>>>> origin/master