From b6ee2b7c296abcfff1ae7f7ac4db976dc4d6fd8e Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 9 Sep 2015 21:04:08 -0400 Subject: world gen --- include/World.h | 16 +++++++--------- src/World.cpp | 57 +++++++++++++++++++++++++-------------------------------- src/main.cpp | 8 +++----- 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/include/World.h b/include/World.h index 4a097a6..212fe38 100644 --- a/include/World.h +++ b/include/World.h @@ -2,21 +2,19 @@ #define WORLD_H #include -#include -#define LAYER0_Y (-0.8f) -#define TEX_SIZE ( 0.2f) +#define HLINE (2.0f/ 200 ) class World { private: - struct layer_t { - unsigned int tex; - float offset; - } layer[4]; + 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(const char *l1,const char *l2,const char *l3,const char *bg); + World(float width); void draw(void); - void update(int player_accel); }; #endif // WORLD_H diff --git a/src/World.cpp b/src/World.cpp index feeeb1f..3d8cfb7 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1,38 +1,31 @@ #include -World::World(const char *l1,const char *l2,const char *l3,const char *bg){ - unsigned char i=0; - SDL_Surface *l; - const char *f[4]={l1,l2,l3,bg}; - memset(layer,0,sizeof(struct layer_t)*4); - for(;i<4;i++){ - l=IMG_Load(f[i]); - if(l!=NULL){ - glGenTextures(1,&layer[i].tex); - glBindTexture(GL_TEXTURE_2D,layer[i].tex); - glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,l->w,l->h,0,GL_RGB,GL_UNSIGNED_BYTE,l->pixels); - SDL_FreeSurface(l); - } +World::World(float width){ + unsigned int i; + lineCount=width/HLINE; + if((line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)))==NULL){ + std::cout<<"Failed to allocate memory!"<=0;i--){ - glBindTexture(GL_TEXTURE_2D,layer[i].tex); - glBegin(GL_QUADS); - for(x=-1;x<=1;x+=(TEX_SIZE/(float)(i+1))){ - glTexCoord2d(1,1);glVertex2f(x ,LAYER0_Y-TEX_SIZE+(i*.2)); - glTexCoord2d(0,1);glVertex2f(x+TEX_SIZE,LAYER0_Y-TEX_SIZE+(i*.2)); - glTexCoord2d(0,0);glVertex2f(x+TEX_SIZE,LAYER0_Y +(i*.2)); - glTexCoord2d(1,0);glVertex2f(x ,LAYER0_Y +(i*.2)); - } - glEnd(); - } - glDisable(GL_TEXTURE_2D); + unsigned int i; + glBegin(GL_QUADS); + for(i=0;i +#include SDL_Window *window = NULL; SDL_Surface *renderSurface = NULL; @@ -39,7 +40,7 @@ int main(int argc,char **argv){ std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl; return -1; } - + srand(time(NULL)); glClearColor(.3,.5,.8,0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); @@ -48,10 +49,7 @@ int main(int argc,char **argv){ **** GAMELOOP **** **************************/ - World *w=new World("res/dirt.jpg", - "res/dirt.jpg", - "res/dirt.jpg", - "res/dirt.jpg"); + World *w=new World(2); while(gameRunning){ ui.handleEvents(); // Handle events -- cgit v1.2.3