diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-21 21:52:28 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-21 21:52:28 -0400 |
commit | b3e625cf2e6fea860fc669f3a2a46cf96a01da0f (patch) | |
tree | bc01dccc2e7f148b3c291eb4e145c9263aeaa20d /src/world.cpp | |
parent | 1118f22a60dffeb204ec4845d009cf057b51f088 (diff) |
added/fixed world linking
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 88 |
1 files changed, 66 insertions, 22 deletions
diff --git a/src/world.cpp b/src/world.cpp index d7aece1..d05d5c1 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1,6 +1,6 @@ #include <world.h> -#define getWidth() ((lineCount-GEN_INC)*HLINE) +#define getWidth(w) ((w->lineCount-GEN_INC)*HLINE) #define GEN_INC 10 #define GRASS_HEIGHT 4 @@ -34,8 +34,9 @@ World::World(unsigned int width){ } line[i].color=rand()%20+130; } - x_start=0-getWidth()/2+GEN_INC/2*HLINE; + x_start=0-getWidth(this)/2+GEN_INC/2*HLINE; behind=infront=NULL; + toLeft=toRight=NULL; } World::~World(void){ @@ -45,36 +46,47 @@ World::~World(void){ void World::draw(vec2 *vec){ static float yoff=50; static int shade=0; - int i,ie,v_offset; - if(behind){ + static World *root,*current; + int i,ie,v_offset,cx_start; + struct line_t *cline; + root=current=this; +LOOP1: + if(current->behind){ yoff+=50; shade+=40; - behind->draw(vec); + current=current->behind; + goto LOOP1; } - v_offset=(vec->x-x_start)/HLINE; +LOOP2: + v_offset=(vec->x-current->x_start)/HLINE; i=v_offset-SCREEN_WIDTH/(yoff/25); if(i<0)i=0; ie=v_offset+SCREEN_WIDTH/(yoff/25); - if(ie>lineCount)ie=lineCount; + if(ie>current->lineCount)ie=current->lineCount; + //std::cout<<v_offset<<" "<<i<<" "<<ie<<yoff<<std::endl; + cline=current->line; + cx_start=current->x_start; glBegin(GL_QUADS); - for(i=i;i<ie;i++){ - line[i].y+=(yoff-50); + for(i=i;i<ie-GEN_INC;i++){ + cline[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); - 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); + glVertex2i(cx_start+i*HLINE ,cline[i].y); + glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y); + glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT); + glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT); + safeSetColor(cline[i].color+shade,cline[i].color-50+shade,cline[i].color-100+shade); + glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT); + glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT); + glVertex2i(cx_start+i*HLINE+HLINE,0); + glVertex2i(cx_start+i*HLINE ,0); + cline[i].y-=(yoff-50); } glEnd(); - if(infront){ + if(current->infront){ yoff-=50; shade-=40; + current=current->infront; + goto LOOP2; }else{ yoff=50; shade=40; @@ -95,9 +107,9 @@ 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+width+HLINE>x_start+getWidth()){ + }else if(v->x+width+HLINE>x_start+getWidth(this)){ vel->x=0; - v->x=x_start+getWidth()-width-HLINE; + v->x=x_start+getWidth(this)-width-HLINE; } } @@ -109,3 +121,35 @@ void World::addLayer(unsigned int width){ behind=new World(width); behind->infront=this; } + +World *World::goWorldLeft(vec2 *loc,const float width){ + if(toLeft&&loc->x<x_start+HLINE*10){ + loc->x=toLeft->x_start+getWidth(toLeft)-HLINE*10; + loc->y=toLeft->line[0].y; + return toLeft; + } + return this; +} + +World *World::goWorldRight(vec2 *loc,const float width){ + if(toRight&&loc->x+width>x_start+getWidth(this)-HLINE*10){ + loc->x=toRight->x_start+HLINE*10; + loc->y=toRight->line[toRight->lineCount-GEN_INC-1].y; + return toRight; + } + return this; +} + +World *World::goWorldBack(vec2 *loc,const float width){ + if(behind&&loc->x>(int)(0-getWidth(behind)/2)&&loc->x<getWidth(behind)/2){ + return behind; + } + return this; +} + +World *World::goWorldFront(vec2 *loc,const float width){ + if(infront&&loc->x>(int)(0-getWidth(infront)/2)&&loc->x<getWidth(infront)/2){ + return infront; + } + return this; +} |