struct line_t {\r
// x = 2.0 (window width) / HLINES\r
double start; // Where to change to dirt, going down (y)\r
- } *line;\r
+ } __attribute__ ((packed)) *line;\r
unsigned int lineCount;\r
public:\r
World *toLeft,*toRight;\r
void draw(void);\r
void detect(vec2 *v,const float width);\r
float getWidth(void);\r
+ void saveToFile(FILE *f,World *parent);\r
+ void loadFromFile(FILE *f,World *parent);\r
};\r
\r
#endif // WORLD_H
#include <World.h>\r
+#include <cstdio>\r
\r
World::World(void){\r
line=NULL;\r
}\r
glEnd();\r
}\r
-#include <stdio.h>\r
void World::detect(vec2 *v,const float width){\r
unsigned int i;\r
for(i=0;i<lineCount;i++){\r
float World::getWidth(void){\r
return (lineCount-1)*HLINE;\r
}\r
+void World::saveToFile(FILE *f,World *parent){\r
+ fwrite(&lineCount,sizeof(unsigned int) ,1 ,f);\r
+ fwrite(&line ,sizeof(struct line_t),lineCount,f);\r
+ if(toLeft!=NULL&&toLeft!=parent->toLeft){\r
+ toLeft->saveToFile(f,toLeft);\r
+ }\r
+ if(toRight!=NULL&&toRight!=parent->toRight){\r
+ toRight->saveToFile(f,toRight);\r
+ }\r
+}\r
+void World::loadFromFile(FILE *f,World *parent){\r
+ fread(&lineCount,sizeof(unsigned int) ,1 ,f);\r
+ line=(struct line_t *)malloc(lineCount*sizeof(struct line_t *));\r
+ fread(&line ,sizeof(struct line_t),lineCount,f);\r
+ if(toLeft!=NULL&&toLeft!=parent->toLeft){\r
+ toLeft->loadFromFile(f,toLeft);\r
+ }\r
+ std::cout<<toRight<<" "<<parent->toRight<<std::endl;\r
+ if(toRight!=NULL&&toRight!=parent->toRight){\r
+ puts("A");\r
+ toRight->loadFromFile(f,toRight);\r
+ }\r
+}\r
+\r
#include <common.h>
+#include <cstdio>
#include <ctime>
#define TICKS_PER_SEC 20
entit1 = &player;
entit1->spawn(0, 0);
- World *w=NULL;
- World *w2=new World(4,w,NULL);
+ // Generate the world
+ World *w=NULL,*w2=NULL;
+ w2=new World(4,w,NULL);
w=new World(2,NULL,w2);
+
currentWorld=w;
+ // Save the world if necessary
+ /*static FILE *f=fopen("world.dat","r");
+ if(f==NULL){
+ f=fopen("world.dat","w");
+ if(f!=NULL){
+ currentWorld->saveToFile(f,currentWorld);
+ fclose(f);
+ }else{
+ std::cout<<"Error! Couldn\'t save the world!"<<std::endl;
+ }
+ }else{
+ currentWorld->loadFromFile(f,currentWorld);
+ fclose(f);
+ }*/
+
float gw;
while(gameRunning){