From b806a2d9bd6932525263a172ea2837eb1a94717d Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 19 Sep 2015 08:23:11 -0400 Subject: stuff --- include/world.h | 2 ++ src/main.cpp | 1 + src/ui.cpp | 5 +++-- src/world.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++------------- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/include/world.h b/include/world.h index 21d6de8..3b76f19 100644 --- a/include/world.h +++ b/include/world.h @@ -11,9 +11,11 @@ private: } __attribute__ ((packed)) *line; unsigned int lineCount; int x_start; + World *behind,*infront; public: World(unsigned int width); ~World(void); + void addLayer(unsigned int width); void draw(vec2 *vec); void detect(vec2 *v,vec2 *vel,const float width); }; diff --git a/src/main.cpp b/src/main.cpp index 5d578aa..ff36b69 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,6 +71,7 @@ int main(int argc, char *argv[]){ **************************/ World *test=new World(SCREEN_WIDTH/2); + test->addLayer(400); currentWorld=test; player=new Player(); player->spawn(0,100); diff --git a/src/ui.cpp b/src/ui.cpp index d7aabc0..5d3e143 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -89,11 +89,12 @@ namespace ui { case SDL_KEYDOWN: if(SDL_KEY==SDLK_ESCAPE)gameRunning=false; if(SDL_KEY==SDLK_a)player->vel.x=-2; - else if(SDL_KEY==SDLK_d)player->vel.x=2; + if(SDL_KEY==SDLK_d)player->vel.x=2; + if(SDL_KEY==SDLK_SPACE)player->vel.y=2; break; case SDL_KEYUP: if(SDL_KEY==SDLK_a)player->vel.x=0; - else if(SDL_KEY==SDLK_d)player->vel.x=0; + if(SDL_KEY==SDLK_d)player->vel.x=0; break; default: break; diff --git a/src/world.cpp b/src/world.cpp index 12d9591..f22de6c 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1,10 +1,20 @@ #include -#define getWidth() (lineCount*HLINE) +#define getWidth() ((lineCount-GEN_INC)*HLINE) #define GEN_INC 10 #define GRASS_HEIGHT 4 +void safeSetColor(int r,int g,int b){ + if(r>255)r=255; + if(g>255)g=255; + if(b>255)b=255; + if(r<0)r=0; + if(g<0)g=0; + if(b<0)b=0; + glColor3ub(r,g,b); +} + World::World(unsigned int width){ unsigned int i; float inc; @@ -24,11 +34,8 @@ World::World(unsigned int width){ } line[i].color=rand()%20+130; } - /*line[0].y=50; - for(i=1;idraw(vec); + } v_offset=(vec->x-x_start)/HLINE; - i=v_offset-SCREEN_WIDTH/2; + i=v_offset-SCREEN_WIDTH/(yoff/25); if(i<0)i=0; - ie=v_offset+SCREEN_WIDTH/2; + ie=v_offset+SCREEN_WIDTH/(yoff/25); if(ie>lineCount)ie=lineCount; glBegin(GL_QUADS); for(i=i;ixx=0; v->x=x_start+HLINE/2; - }else if(v->x>x_start+getWidth()){ + }else if(v->x+width+HLINE>x_start+getWidth()){ vel->x=0; - v->x=x_start+getWidth()-width-HLINE/2; + v->x=x_start+getWidth()-width-HLINE; + } +} + +void World::addLayer(unsigned int width){ + if(behind){ + behind->addLayer(width); + return; } + behind=new World(width); + behind->infront=this; } -- cgit v1.2.3