diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-06 08:19:46 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-06 08:19:46 -0500 |
commit | cb55d6e72ae1f48622ffc2a36d7bdb3719355afe (patch) | |
tree | e38b215d2fc45368a76bf9350138046c38afa946 /src/gameplay.cpp | |
parent | f2886601e15f41938c6735feb552e831ffeeefc1 (diff) |
world save/load
Diffstat (limited to 'src/gameplay.cpp')
-rw-r--r-- | src/gameplay.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp index baa91e8..b32d9ee 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -31,14 +31,32 @@ void initEverything(void){ unsigned int i; /* - * Generate a new world. + * World creation: */ World *test=new World(); - test->generate(SCREEN_WIDTH * 2); + + /* + * Load the saved world if it exists, otherwise generate a new one. + */ + + FILE *worldLoad; + if((worldLoad=fopen("world.dat","r"))){ + std::cout<<"Yes"<<std::endl; + char *buf; + unsigned int size; + fseek(worldLoad,0,SEEK_END); + size=ftell(worldLoad); + rewind(worldLoad); + buf=(char *)malloc(size); + fread(buf,1,size,worldLoad); + test->load(buf); + }else{ + test->generate(SCREEN_WIDTH * 2); + test->addHole(100,150); + } + test->addLayer(400); - - test->addHole(100,150); /* * Setup the current world, making the player initially spawn in `test`. |