aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-01-04 08:48:27 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-01-04 08:48:27 -0500
commit65addfa212a2aef2f2d6de3cb49edc99a8f02f59 (patch)
treee47017d9f57b8447ce138fe059bdd7f5e559dacd /src
parent272a152b54a198a84f122ab8bedb1019708b7008 (diff)
save/load tests
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp4
-rw-r--r--src/gameplay.cpp25
-rw-r--r--src/ui.cpp19
-rw-r--r--src/world.cpp37
4 files changed, 67 insertions, 18 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index 3849040..d424aba 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -101,7 +101,7 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation
tex = new Texturec(1,"assets/NPC.png");
inv = new Inventory(NPC_INV_SIZE);
- randDialog = rand() % 12 - 1;
+ randDialog = 6;//rand() % 12 - 1;
}
NPC::~NPC(){
while(!aiFunc.empty()){
@@ -341,7 +341,7 @@ const char *randomDialog[] = {
"How much wood could a woodchuck chuck if a woodchuck could chuck wood?",
"I don\'t think anyone has ever been able to climb up that hill.",
"If you ever see a hole in the ground, watch out; it could mean the end for you.",
- "Did you know this game has over 4000 lines of code? I didn\'t. I didn't even know I was in a game until now...",
+ "Did you know this game has over 5000 lines of code? I didn\'t. I didn't even know I was in a game until now...",
"HELP MY CAPS LOCK IS STUCK",
"You know, if anyone ever asked me who I wanted to be when I grow up, I would say Abby Ross.",
"I want to have the wallpaper in our house changed. It doesn\'t really fit the environment.",
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 7dbe98e..ff77728 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -115,15 +115,21 @@ static World *worldSpawnHill3;
static IndoorWorld *worldSpawnHill2_Building1;
+static World *worldFirstVillage;
/*
* initEverything() start
*/
void destroyEverything(void);
void initEverything(void){
-
+ //static std::ifstream i ("world.dat",std::ifstream::in | std::ifstream::binary);
+
worldSpawnHill1 = new World();
- worldSpawnHill1->generateFunc(400,gen_worldSpawnHill1);
+ /*if(!i.fail()){
+ worldSpawnHill1->load(&i);
+ i.close();
+ }else*/
+ worldSpawnHill1->generateFunc(400,gen_worldSpawnHill1);
worldSpawnHill1->setBackground(BG_FOREST);
worldSpawnHill1->setBGM("assets/music/embark.wav");
worldSpawnHill1->addMob(MS_TRIGGER,0,0,worldSpawnHill1_hillBlock);
@@ -138,12 +144,18 @@ void initEverything(void){
worldSpawnHill3->generateFunc(1000,gen_worldSpawnHill3);
worldSpawnHill3->setBackground(BG_FOREST);
worldSpawnHill3->setBGM("assets/music/ozone.wav");
- worldSpawnHill3->addHole(800,1000);
+
+ worldFirstVillage = new World();
+ worldFirstVillage->generate(1000);
+ worldFirstVillage->setBackground(BG_FOREST);
+ worldFirstVillage->setBGM("assets/music/embark.wav");
worldSpawnHill1->toRight = worldSpawnHill2;
worldSpawnHill2->toLeft = worldSpawnHill1;
worldSpawnHill2->toRight = worldSpawnHill3;
worldSpawnHill3->toLeft = worldSpawnHill2;
+ worldSpawnHill3->toRight = worldFirstVillage;
+ worldFirstVillage->toLeft = worldSpawnHill3;
/*
* Spawn some entities.
@@ -166,6 +178,8 @@ void initEverything(void){
worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill2_Building1);
worldSpawnHill2->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest1,false);
+ worldFirstVillage->addVillage(5,0,0,STRUCTURET,worldSpawnHill2_Building1);
+
player = new Player();
player->spawn(200,100);
@@ -178,6 +192,11 @@ extern std::vector<int (*)(NPC *)> AIpreload;
extern std::vector<NPC *> AIpreaddr;
void destroyEverything(void){
+ static std::ofstream o;
+ o.open("world.dat",std::ifstream::binary);
+ worldSpawnHill1->save(&o);
+ o.close();
+
while(!AIpreload.empty())
AIpreload.pop_back();
while(!AIpreaddr.empty())
diff --git a/src/ui.cpp b/src/ui.cpp
index f73f48a..b827b43 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -95,6 +95,8 @@ namespace ui {
bool dialogImportant = false;
unsigned char dialogOptChosen = 0;
+ unsigned int textWrapLimit = 110;
+
/*
* Current font size. Changing this WILL NOT change the font size, see setFontSize() for
* actual font size changing.
@@ -266,7 +268,13 @@ namespace ui {
*/
do{
- if(s[i]=='\n'){ // Handle newlines
+ if(i && ((i / 110.0) == (i / 110))){
+ yo-=fontSize*1.05;
+ xo=x;
+ if(s[i] == ' ')
+ i++;
+ }
+ if(s[i] == '\n'){
yo-=fontSize*1.05;
xo=x;
}else if(s[i]==' '){ // Handle spaces
@@ -308,12 +316,13 @@ namespace ui {
* Draw a string in a typewriter-esque fashion. Each letter is rendered as calls are made
* to this function. Passing a different string to the function will reset the counters.
*/
-
+
+ static char *ret = NULL;
char *typeOut(char *str){
static unsigned int sinc, // Acts as a delayer for the space between each character.
linc=0, // Contains the number of letters that should be drawn.
size=0; // Contains the full size of the current string.
- static char *ret = NULL;
+ //static char *ret = NULL;
/*
* Create a well-sized buffer if we haven't yet.
@@ -453,6 +462,8 @@ namespace ui {
dialogBoxExists = true;
dialogImportant = false;
+ if(ret)
+ ret[0] = '\0';
}
void waitForDialog(void){
do{
@@ -667,7 +678,6 @@ DONE:
memcpy(&player->loc,&tmppos,sizeof(vec2));
currentWorld = tmp;
toggleBlackFast();
- dialogBoxExists = false;
}
}
break;
@@ -689,7 +699,6 @@ DONE:
memcpy(&player->loc,&tmppos,sizeof(vec2));
currentWorld = tmp;
toggleBlackFast();
- dialogBoxExists = false;
}
}
break;
diff --git a/src/world.cpp b/src/world.cpp
index 5663086..2afbdf5 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -50,6 +50,7 @@ float worldGetYBase(World *w){
}
void World::setBackground(WORLD_BG_TYPE bgt){
+ bgType = bgt;
switch(bgt){
case BG_FOREST:
bgTex = new Texturec(7,bgPaths[0]);
@@ -60,12 +61,28 @@ void World::setBackground(WORLD_BG_TYPE bgt){
}
}
-void World::save(FILE *s){
- fclose(s);
+void World::save(std::ofstream *o){
+ o->write((char *)&lineCount, sizeof(unsigned int));
+ o->write((char *)&line ,lineCount * sizeof(struct line_t));
+ o->write("GG" ,2 * sizeof(char));
+ o->write((char *)&star ,100 * sizeof(vec2));
}
-void World::load(FILE *s){
- fclose(s);
+void World::load(std::ifstream *i){
+ static char end[2];
+
+ i->read((char *)&lineCount,sizeof(unsigned int));
+ line = new struct line_t[lineCount];
+
+ i->read((char *)&line,lineCount * sizeof(struct line_t));
+ i->read(end ,2 * sizeof(char));
+ if(strncmp(end,"GG",2)){
+ std::cout<<"world.dat corrupt"<<std::endl;
+ exit(EXIT_FAILURE);
+ }
+ i->read((char *)&star,100 * sizeof(vec2));
+
+ x_start = 0 - getWidth(this) / 2;
}
World::World(void){
@@ -913,16 +930,20 @@ void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){
entity.push_back(build.back());
}
-void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside){
+void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,World *inside){
std::cout << npcMin << ", " << npcMax << std::endl;
- int xwasd;
+ //int xwasd;
for(int i = 0; i < bCount; i++){
- xwasd = (rand()%(int)x+1000*HLINE);
+ addStructure(t,HOUSE,x_start + (i * 300),100,inside);
+ /*std::cout<<"1\n";
HERE:
+ xwasd = (rand()%(int)x+1000*HLINE);
for(auto &bu : build){
if(xwasd > bu->loc.x && xwasd < bu->loc.x+bu->width)goto HERE;
}
- addStructure(t,HOUSE,xwasd,y,outside);
+ std::cout<<"2\n";
+ addStructure(t,HOUSE,xwasd,y,inside);
+ std::cout<<"3\n";*/
}
}
void World::addMob(int t,float x,float y){