diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-19 08:23:11 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-19 08:23:11 -0400 |
commit | b806a2d9bd6932525263a172ea2837eb1a94717d (patch) | |
tree | 5b77d63edebf66df11ae29229eaf4c44223f6f7b /src/world.cpp | |
parent | 1f3fee78514fb097834a2cb4235aaad3bdf639e7 (diff) |
stuff
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 57 |
1 files changed, 44 insertions, 13 deletions
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 <world.h> -#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;i<lineCount-20;i++){ - line[i].y=rand()%5-2+line[i-1].y; - if(line[i].y<30)line[i].y=30; - }*/ + x_start=0-getWidth()/2+GEN_INC/2*HLINE; + behind=infront=NULL; } World::~World(void){ @@ -36,27 +43,42 @@ World::~World(void){ } void World::draw(vec2 *vec){ + static float yoff=50; + static int shade=0; int i,ie,v_offset; - x_start=0-getWidth()/2+GEN_INC/2*HLINE; + if(behind){ + yoff+=50; + shade+=40; + behind->draw(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;i<ie;i++){ - glColor3ub(0,200,0); + line[i].y+=(yoff-50); + safeSetColor(shade,200+shade,shade); glVertex2i(x_start+i*HLINE ,line[i].y); glVertex2i(x_start+i*HLINE+HLINE,line[i].y); glVertex2i(x_start+i*HLINE+HLINE,line[i].y-GRASS_HEIGHT); glVertex2i(x_start+i*HLINE ,line[i].y-GRASS_HEIGHT); - glColor3ub(line[i].color,line[i].color-50,line[i].color-100); + safeSetColor(line[i].color+shade,line[i].color-50+shade,line[i].color-100+shade); glVertex2i(x_start+i*HLINE ,line[i].y-GRASS_HEIGHT); glVertex2i(x_start+i*HLINE+HLINE,line[i].y-GRASS_HEIGHT); glVertex2i(x_start+i*HLINE+HLINE,0); glVertex2i(x_start+i*HLINE ,0); + line[i].y-=(yoff-50); } glEnd(); + if(infront){ + yoff-=50; + shade-=40; + }else{ + yoff=50; + shade=40; + } } void World::detect(vec2 *v,vec2 *vel,const float width){ @@ -73,8 +95,17 @@ void World::detect(vec2 *v,vec2 *vel,const float width){ if(v->x<x_start){ vel->x=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; } |