aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog18
-rw-r--r--include/entities.h5
-rw-r--r--include/inventory.h2
-rw-r--r--include/world.h3
-rw-r--r--main.cpp13
-rw-r--r--src/config.cpp30
-rw-r--r--src/entities.cpp67
-rw-r--r--src/gameplay.cpp6
-rw-r--r--src/ui.cpp3
-rw-r--r--src/world.cpp41
10 files changed, 142 insertions, 46 deletions
diff --git a/Changelog b/Changelog
index 582259c..0f4fdcf 100644
--- a/Changelog
+++ b/Changelog
@@ -647,3 +647,21 @@
- began considering unique_ptr's because they're good
- fixed inventory everything
- themes work
+ - pushed template settings.xml
+
+2/11/2016:
+==========
+
+ - fixed text drawing for good
+ - fixed player boundary checks
+ - made importantText passive-able
+ - began work on saving player stats
+ - fixed dialogClick stuffs
+ - added readConfig checks
+ - added background layers and whatnot
+
+2/12/2016:
+==========
+
+ - made saving functionality for player coordinates, inventory, health and current world
+ - addded structured villages
diff --git a/include/entities.h b/include/entities.h
index 05ae64c..926eeae 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -6,6 +6,8 @@
#include <inventory.h>
#include <Texture.h>
+#include <sstream>
+
#define DEBUG
#define NPCp(n) ((NPC *)n)
@@ -175,7 +177,8 @@ public:
Player();
~Player();
- void interact();
+ void save(void);
+ void sspawn(float x,float y);
};
class NPC : public Entity{
diff --git a/include/inventory.h b/include/inventory.h
index af859a5..8225ab2 100644
--- a/include/inventory.h
+++ b/include/inventory.h
@@ -31,10 +31,10 @@ struct item_t{
class Inventory {
private:
- std::vector<item_t> items;
unsigned int size;
int os = 0;
public:
+ std::vector<item_t> items;
unsigned int sel;
bool invOpen = false;
bool invOpening = false;
diff --git a/include/world.h b/include/world.h
index 43da6fc..48ab409 100644
--- a/include/world.h
+++ b/include/world.h
@@ -351,7 +351,7 @@ public:
* playable.
*/
- void setBGM(const char *path);
+ void setBGM(std::string path);
/**
* Sets the worlds style folder
@@ -454,5 +454,6 @@ extern int worldShade;
extern char *currentXML;
World *loadWorldFromXML(const char *path);
+World *loadWorldFromXMLNoSave(const char *path);
#endif // WORLD_H
diff --git a/main.cpp b/main.cpp
index da1790f..19fe8d4 100644
--- a/main.cpp
+++ b/main.cpp
@@ -200,8 +200,6 @@ int main(/*int argc, char *argv[]*/){
gameRunning=false;
- readConfig();
-
/**
* (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
* make openGL calls. Exit if there was an error.
@@ -241,6 +239,12 @@ int main(/*int argc, char *argv[]*/){
// Run Mix_Quit when main returns
atexit(Mix_Quit);
+ /**
+ * Load saved settings into the game (see config/settings.xml)
+ */
+
+ readConfig();
+
/*
* Create a window for SDL to draw to. Most parameters are the default, except for the
* following which are defined in include/common.h:
@@ -382,6 +386,7 @@ int main(/*int argc, char *argv[]*/){
*/
fadeIntensity = 250;
+
initEverything();
if(!currentWorld){
@@ -570,7 +575,7 @@ void render(){
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
- glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1);
+ glOrtho(floor(offset.x-SCREEN_WIDTH/2),floor(offset.x+SCREEN_WIDTH/2),floor(offset.y-SCREEN_HEIGHT/2),floor(offset.y+SCREEN_HEIGHT/2),-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
@@ -729,7 +734,7 @@ void render(){
SDL_GL_SwapWindow(window);
}
-static volatile bool objectInteracting = false;
+static bool objectInteracting = false;
void logic(){
diff --git a/src/config.cpp b/src/config.cpp
index ca6db1b..efa2523 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -9,9 +9,9 @@ extern unsigned int SCREEN_WIDTH;
extern unsigned int SCREEN_HEIGHT;
extern bool FULLSCREEN;
-extern float VOLUME_MASTER;
-extern float VOLUME_MUSIC;
-extern float VOLUME_SFX;
+extern float VOLUME_MASTER;
+extern float VOLUME_MUSIC;
+extern float VOLUME_SFX;
XMLDocument xml;
XMLElement *scr;
@@ -19,6 +19,7 @@ XMLElement *vol;
void readConfig(){
unsigned int uval;
+ float fval;
bool bval;
xml.LoadFile("config/settings.xml");
@@ -36,18 +37,23 @@ void readConfig(){
if(xml.FirstChildElement("hline")->QueryUnsignedAttribute("size",&uval) == XML_NO_ERROR)
HLINE = uval;
else HLINE = 3;
-
- /*SCREEN_WIDTH = scr->UnsignedAttribute("width");
- SCREEN_HEIGHT = scr->UnsignedAttribute("height");
- FULLSCREEN = scr->BoolAttribute("fullscreen");
- HLINE = xml.FirstChildElement("hline")->UnsignedAttribute("size");*/
vol = xml.FirstChildElement("volume");
- VOLUME_MASTER = vol->FirstChildElement("master")->FloatAttribute("volume");
- VOLUME_MUSIC = vol->FirstChildElement("music")->FloatAttribute("volume");
- VOLUME_SFX = vol->FirstChildElement("sfx")->FloatAttribute("volume");
- std::cout<<"Loading font through settings.xml..."<<std::endl;
+ if(vol->FirstChildElement("master")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
+ VOLUME_MASTER = fval;
+ else VOLUME_MASTER = 50;
+ if(vol->FirstChildElement("music")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
+ VOLUME_MUSIC = fval;
+ else VOLUME_MUSIC = 50;
+ if(vol->FirstChildElement("sfx")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
+ VOLUME_SFX = fval;
+ else VOLUME_SFX = 50;
+
+ Mix_Volume(0,VOLUME_MASTER);
+ Mix_Volume(1,VOLUME_SFX);
+ Mix_VolumeMusic(VOLUME_MUSIC);
+
ui::initFonts();
ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
}
diff --git a/src/entities.cpp b/src/entities.cpp
index e020f8b..71a0890 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -332,9 +332,6 @@ NOPE:
if(near)ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
}
-void Player::interact(){
-}
-
/*
* NPC::wander, this makes the npcs wander around the near area
*
@@ -546,3 +543,67 @@ void Mob::wander(int timeRun){
break;
}
}
+
+void Player::save(void){
+ std::string data;
+ std::ofstream out ("xml/main.dat",std::ios::out | std::ios::binary);
+ std::cout<<"Saving player data..."<<std::endl;
+ data.append(std::to_string((int)loc.x) + "\n");
+ data.append(std::to_string((int)loc.y) + "\n");
+ data.append(std::to_string((int)health) + "\n");
+ data.append(std::to_string((int)maxHealth) + "\n");
+
+ data.append(std::to_string((int)inv->items.size()) + "\n");
+ for(auto &i : inv->items)
+ data.append(std::to_string((int)i.count) + "\n" + std::to_string((int)i.id) + "\n");
+
+ data.append((std::string)(currentXML+4) + "\n");
+
+ data.append("dOnE\0");
+ out.write(data.c_str(),data.size());
+ out.close();
+}
+
+void Player::sspawn(float x,float y){
+ unsigned int i;
+ uint count;
+ std::ifstream in ("xml/main.dat",std::ios::in | std::ios::binary);
+ spawn(x,y);
+
+ if(in.good()){
+ std::istringstream data;
+ std::string ddata;
+ std::streampos len;
+
+ in.seekg(0,std::ios::end);
+ len = in.tellg();
+ in.seekg(0,std::ios::beg);
+
+ std::vector<char> buf (len,'\0');
+ in.read(buf.data(),buf.size());
+
+ data.rdbuf()->pubsetbuf(buf.data(),buf.size());
+
+ std::getline(data,ddata);
+ loc.x = std::stoi(ddata);
+ std::getline(data,ddata);
+ loc.y = std::stoi(ddata);
+ std::getline(data,ddata);
+ health = std::stoi(ddata);
+ std::getline(data,ddata);
+ maxHealth = std::stoi(ddata);
+
+ std::getline(data,ddata);
+ for(i = std::stoi(ddata);i;i--){
+ std::getline(data,ddata);
+ count = std::stoi(ddata);
+ std::getline(data,ddata);
+ inv->items.push_back((item_t){count,(uint)std::stoi(ddata)});
+ }
+
+ std::getline(data,ddata);
+ currentWorld = loadWorldFromXMLNoSave(ddata.c_str());
+
+ in.close();
+ }
+}
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index e252c26..4bbc672 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -278,7 +278,7 @@ void initEverything(void){
*/
for(unsigned int i=0;i<xmlFiles.size();i++){
- if(strncmp(xmlFiles[i].c_str(),".",1) && strncmp(xmlFiles[i].c_str(),"..",2)){
+ if(xmlFiles[i] != "." && xmlFiles[i] != ".." && strcmp(xmlFiles[i].c_str()+xmlFiles[i].size()-3,"dat")){
/*
* Read in the XML file.
@@ -307,9 +307,9 @@ void initEverything(void){
/*
* Spawn the player and begin the game.
*/
-
+
player = new Player();
- player->spawn(200,100);
+ player->sspawn(0,100);
currentWorld->bgmPlay(NULL);
atexit(destroyEverything);
diff --git a/src/ui.cpp b/src/ui.cpp
index e6ee988..3d635ab 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -59,7 +59,7 @@ extern Menu* currentMenu;
extern Menu pauseMenu;
-Mix_Chunk *dialogClick;
+static Mix_Chunk *dialogClick;
extern void mainLoop(void);
@@ -1179,6 +1179,7 @@ DONE:
if(SDL_KEY == SDLK_ESCAPE){
//gameRunning = false;
currentMenu = &pauseMenu;
+ player->save();
return;
}
switch(SDL_KEY){
diff --git a/src/world.cpp b/src/world.cpp
index 2012d32..25b7d35 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -329,10 +329,7 @@ void World::update(Player *p,unsigned int delta){
p->loc.y += p->vel.y * delta;
p->loc.x +=(p->vel.x * p->speed) * delta;
- /*if(p->inv->usingi){
- p->inv->useItem();
- }*/
-
+
/*
* Update coordinates of all entities except for structures.
*/
@@ -374,20 +371,20 @@ void World::update(Player *p,unsigned int delta){
}
}
-void World::setBGM(const char *path){
- if(!bgm) delete[] bgm;
- if(path != NULL){
- bgm = new char[strlen(path) + 1];
- strcpy(bgm,path);
- bgmObj = Mix_LoadMUS(bgm);
- }else{
- bgm = new char[1];
- bgm[0] = '\0';
- }
+void World::setBGM(std::string path){
+ bgm = new char[path.size()];
+ strcpy(bgm,path.c_str());
+ bgmObj = Mix_LoadMUS(bgm);
}
void World::bgmPlay(World *prev){
- if(prev && strcmp(bgm,prev->bgm)){
+ if(prev){
+ if(bgm != prev->bgm){
+ Mix_FadeOutMusic(800);
+ Mix_VolumeMusic(50);
+ Mix_PlayMusic(bgmObj,-1); // Loop infinitely
+ }
+ }else{
Mix_FadeOutMusic(800);
Mix_VolumeMusic(50);
Mix_PlayMusic(bgmObj,-1); // Loop infinitely
@@ -1477,6 +1474,15 @@ char *currentXML = NULL;
extern World *currentWorld;
World *loadWorldFromXML(const char *path){
+ if(currentXML){
+ currentWorld->save();
+ delete[] currentXML;
+ }
+
+ return loadWorldFromXMLNoSave(path);
+}
+
+World *loadWorldFromXMLNoSave(const char *path){
XMLDocument xml;
XMLElement *wxml;
@@ -1488,11 +1494,6 @@ World *loadWorldFromXML(const char *path){
unsigned int size = 5 + strlen(path);
- if(currentXML){
- currentWorld->save();
- delete[] currentXML;
- }
-
memset((currentXML = new char[size]),0,size);
strcpy(currentXML,"xml/");
strcat(currentXML,path);