#define goWorldLeft(w) if(w->toLeft){w=w->toLeft;}\r
#define goWorldRight(w) if(w->toRight){w=w->toRight;}\r
\r
+#define LAYER_SCALE 1\r
+\r
class World {\r
private:\r
struct line_t {\r
double start; // Where to change to dirt, going down (y)\r
} __attribute__ ((packed)) *line;\r
unsigned int lineCount;\r
+ bool root;\r
public:\r
+ World *behind,*infront;\r
World *toLeft,*toRight;\r
World(void);\r
World(const float width,World *l,World *r);\r
float getWidth(void);\r
void saveToFile(FILE *f,World *parent);\r
void loadFromFile(FILE *f,World *parent);\r
+ void addLayer(void);\r
+ void setRoot(void);\r
};\r
\r
#endif // WORLD_H
World::World(void){\r
line=NULL;\r
lineCount=0;\r
- toLeft=toRight=NULL;\r
+ toLeft=toRight=behind=infront=NULL;\r
+ root=false;\r
}\r
World::World(const float width,World *l,World *r){\r
unsigned int i;\r
}\r
toLeft=l;\r
toRight=r;\r
+ behind=infront=NULL;\r
+ root=false;\r
if(toLeft){\r
if(toLeft->toRight){\r
std::cout<<"There's already a world to the left!"<<std::endl;\r
}\r
}\r
}\r
+static float hline=HLINE;\r
+static float back=0;\r
void World::draw(void){\r
unsigned int i;\r
+ if(behind){\r
+ hline/=1.5;\r
+ back+=.2;\r
+ behind->draw();\r
+ }\r
+ if(root){\r
+ hline=HLINE;\r
+ back=0;\r
+ }\r
glBegin(GL_QUADS);\r
for(i=0;i<lineCount-10;i++){\r
glColor3ub(0,255,0);\r
- glVertex2f((HLINE*i)-1 ,line[i].start);\r
- glVertex2f((HLINE*i)-1+HLINE,line[i].start);\r
- glVertex2f((HLINE*i)-1+HLINE,line[i].start-HLINE*2);\r
- glVertex2f((HLINE*i)-1 ,line[i].start-HLINE*2);\r
+ glVertex2f((hline*i)-1 ,line[i].start+back);\r
+ glVertex2f((hline*i)-1+hline,line[i].start+back);\r
+ glVertex2f((hline*i)-1+hline,line[i].start-hline*2+back);\r
+ glVertex2f((hline*i)-1 ,line[i].start-hline*2+back);\r
glColor3ub(150,100,50);\r
- glVertex2f((HLINE*i)-1 ,line[i].start-HLINE*2);\r
- glVertex2f((HLINE*i)-1+HLINE,line[i].start-HLINE*2);\r
- glVertex2f((HLINE*i)-1+HLINE,-1);\r
- glVertex2f((HLINE*i)-1 ,-1);\r
+ glVertex2f((hline*i)-1 ,line[i].start-hline*2+back);\r
+ glVertex2f((hline*i)-1+hline,line[i].start-hline*2+back);\r
+ glVertex2f((hline*i)-1+hline,-1+back);\r
+ glVertex2f((hline*i)-1 ,-1+back);\r
}\r
glEnd();\r
}\r
void World::detect(vec2 *v,const float width){\r
unsigned int i;\r
+ // hey\r
for(i=0;i<lineCount-10;i++){\r
if(v->y<line[i].start){\r
if(v->x>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){\r
v->y=line[i].start;\r
return;\r
- //v->x=(HLINE*i)-1+HLINE;\r
}else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){\r
v->y=line[i].start;\r
return;\r
- //v->x=(HLINE*i)-1-width;\r
}\r
}else if(v->y>line[i].start+HLINE/4){\r
v->y-=HLINE/8;\r
toRight->loadFromFile(f,toRight);\r
}\r
}\r
-\r
+void World::addLayer(void){\r
+ if(behind){\r
+ behind->addLayer();\r
+ }else{\r
+ behind=new World((lineCount-1)*HLINE+LAYER_SCALE,NULL,NULL);\r
+ behind->infront=this;\r
+ }\r
+}\r
+void World::setRoot(void){\r
+ root=true;\r
+}\r