aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--config/items.xml12
-rw-r--r--include/common.hpp7
-rw-r--r--include/inventory.hpp1
-rw-r--r--main.cpp6
-rw-r--r--src/common.cpp8
-rw-r--r--src/config.cpp6
-rw-r--r--src/entities.cpp4
-rw-r--r--src/gameplay.cpp16
-rw-r--r--src/inventory.cpp22
-rw-r--r--src/world.cpp20
-rw-r--r--xml/playerSpawnHill1.xml9
12 files changed, 87 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index c8b09e3..6abc13f 100644
--- a/Makefile
+++ b/Makefile
@@ -34,6 +34,7 @@ clean:
cleandata:
rm -rf xml/*.dat
+ rm -rf storyXML/*.dat
$(EXEC): $(CXXOUTDIR)/$(CXXOBJ) main.cpp
@echo " CXX/LD main"
diff --git a/config/items.xml b/config/items.xml
index b3a10a5..abf522c 100644
--- a/config/items.xml
+++ b/config/items.xml
@@ -4,11 +4,13 @@
<currency name="George Washington" value="25" sprite="assets/items/coin2.png"/>
<currency name="Barack Hussein Obama" value="100" sprite="assets/items/coin3.png"/>
-<item name="Debug" type="Tool" maxStackSize="1" width="1" height="1" sprite="assets/items/ITEM_TEST.png" />
-<item name="Dank MayMay" type="Tool" maxStackSize="420" width="10" height="10" sprite="assets/items/ITEM_TEST.png" />
-<item name="Your Bag" type="Equip" maxStackSize="1" width="5" height="5" sprite="assets/items/ITEM_TEST.png" />
-<item name="Flashlight" type="Tool" maxStackSize="1" width="4" height="8" sprite="assets/items/flashlight_off.png" />
-<item name="Wood Sword" type="Sword" damage="69" maxStackSize="1" width="4" height="10" sprite="assets/items/SWORD_WOOD.png" />
+<item name="Debug" type="Tool" value="10" maxStackSize="1" width="1" height="1" sprite="assets/items/ITEM_TEST.png" />
+<item name="Dank MayMay" type="Tool" value="10" maxStackSize="420" width="10" height="10" sprite="assets/items/ITEM_TEST.png" />
+<item name="Your Bag" type="Equip" value="32" maxStackSize="1" width="5" height="5" sprite="assets/items/ITEM_TEST.png" />
+<item name="Flashlight" type="Tool" value="1" maxStackSize="1" width="4" height="8" sprite="assets/items/flashlight_off.png" />
+<item name="Wood Sword" type="Sword" value="69" maxStackSize="1" width="4" height="10" sprite="assets/items/SWORD_WOOD.png" />
+<item name="Fried Chicken" type="Cooked Food" value="10" maxStackSize="6" width="4" height="6" sprite="assets/items/FOOD_CHICKEN_FRIED.png" />
+
<item name="Wood Sword2" type="Sword" maxStackSize="1" width="4" height="10" sprite="assets/items/SWORD_WOOD.png" />
<item name="Wood Sword3" type="Sword" maxStackSize="1" width="4" height="10" sprite="assets/items/SWORD_WOOD.png" />
<item name="Wood Sword4" type="Sword" maxStackSize="1" width="4" height="10" sprite="assets/items/SWORD_WOOD.png" />
diff --git a/include/common.hpp b/include/common.hpp
index 5159c88..2abd9db 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -35,6 +35,8 @@ typedef unsigned int uint;
#undef near
#endif
+//#define SEGFAULT
+
/**
* This flag lets the compiler know that we want to use shaders.
*/
@@ -157,6 +159,8 @@ extern float VOLUME_SFX;
#define initRand(s) srand(s)
+
+
/**
* A 'wrapper' for libc's rand(), as we hope to eventually have our own random number
* generator.
@@ -176,8 +180,7 @@ extern float VOLUME_SFX;
*/
#define DEBUG_printf( message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__ )
-#define C(x) std::cout << x << std::endl;
-
+void C(std::string m);
/**
* Defines pi for calculations that need it.
*/
diff --git a/include/inventory.hpp b/include/inventory.hpp
index 5336cee..e38f89a 100644
--- a/include/inventory.hpp
+++ b/include/inventory.hpp
@@ -15,6 +15,7 @@ public:
float width;
float height;
int maxStackSize;
+ float attribValue;
std::string texloc;
Texturec *tex;
diff --git a/main.cpp b/main.cpp
index 951304f..95d4e05 100644
--- a/main.cpp
+++ b/main.cpp
@@ -154,6 +154,8 @@ Menu *currentMenu;
Menu optionsMenu;
Menu pauseMenu;
+std::string xmlFolder;
+
extern WorldWeather weather;
extern int fadeIntensity; // ui.cpp
@@ -227,7 +229,7 @@ int main(int argc, char *argv[]){
* textures for the entities and stuff.
*/
- if(!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)){
+ if(!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) | !(IMG_Init(IMG_INIT_JPG) & IMG_INIT_JPG)){
std::cout << "Could not init image libraries! Error: " << IMG_GetError() << std::endl;
return -1;
}
@@ -389,7 +391,9 @@ int main(int argc, char *argv[]){
fadeIntensity = 250;
+ std::cout << "emem" << std::endl;
initEverything();
+ std::cout << "meme" << std::endl;
if(!currentWorld){
std::cout<<"currentWorld == NULL!"<<std::endl;
diff --git a/src/common.cpp b/src/common.cpp
index 10ff64e..50678f1 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -20,6 +20,14 @@ unsigned int millis(void){
#endif // __WIN32__
+void C(std::string m){
+ #ifdef SEGFAULT
+ std::cout << m << std::endl;
+ #else
+ (void)m;
+ #endif
+}
+
void DEBUG_prints(const char* file, int line, const char *s,...){
va_list args;
printf("%s:%d: ",file,line);
diff --git a/src/config.cpp b/src/config.cpp
index 4f4ad89..2ee13d4 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -13,6 +13,8 @@ extern float VOLUME_MASTER;
extern float VOLUME_MUSIC;
extern float VOLUME_SFX;
+extern std::string xmlFolder;
+
XMLDocument xml;
XMLElement *scr;
XMLElement *vol;
@@ -52,6 +54,10 @@ namespace config {
VOLUME_SFX = fval;
else VOLUME_SFX = 50;
+ xmlFolder = xml.FirstChildElement("world")->Attribute("start");
+ if(xmlFolder=="\0")xmlFolder = "xml/";
+ std::cout << "Folder: " << xmlFolder << std::endl;
+
ui::initFonts();
ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
config::update();
diff --git a/src/entities.cpp b/src/entities.cpp
index 6476755..f4e2dd7 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -102,7 +102,7 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o
Player::Player(){ //sets all of the player specific traits on object creation
width = HLINE * 10;
- height = HLINE * 15;
+ height = HLINE * 16;
type = PLAYERT; //set type to player
subtype = 0;
@@ -697,7 +697,7 @@ void Player::save(void){
void Player::sspawn(float x,float y){
unsigned int i;
uint count;
- std::ifstream in ("xml/main.dat",std::ios::in | std::ios::binary);
+ std::ifstream in ("storyXML/main.dat",std::ios::in | std::ios::binary);
spawn(x,y);
if(in.good()){
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index f398ca0..4aa751f 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -13,6 +13,8 @@ extern Menu *currentMenu;
extern Menu pauseMenu;
extern Menu optionsMenu;
+extern std::string xmlFolder;
+
extern void mainLoop(void); // main.cpp
extern std::vector<NPC *> AIpreaddr; // entities.cpp
@@ -209,8 +211,7 @@ CONT:
return 0;
}
-void commonPageFunc( Mob *callee )
-{
+void commonPageFunc( Mob *callee ){
static bool lock = false;
if ( !lock ) {
@@ -272,16 +273,21 @@ void initEverything(void){
* Read the XML directory into an array.
*/
- if(getdir("./xml/",xmlFiles)){
+ C("Scanning XML directory");
+ if(getdir(std::string("./"+xmlFolder).c_str(),xmlFiles)){
std::cout<<"Error reading XML files!!!1"<<std::endl;
abort();
}
+ C("Done scanning XML directory");
/*
* Sort the files alphabetically.
*/
+ C("Sorting XML files alphabetically");
strVectorSortAlpha(&xmlFiles);
+ C("Dpne sorting XML files alphabetically");
+
/*
* Load the first file found as currentWorld.
@@ -293,8 +299,10 @@ void initEverything(void){
/*
* Read in the XML file.
*/
-
+ C("Setting current XML file");
+ std::cout << "File to load: " << xmlFiles[i] << std::endl;
currentWorld = loadWorldFromXML(xmlFiles[i]);
+ C("Done setting current XML file");
break;
}
}
diff --git a/src/inventory.cpp b/src/inventory.cpp
index a2723fb..474a941 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -10,7 +10,7 @@ extern GLuint invUI;
static float hangle = 0.0f;
static bool swing = false;
static vec2 itemLoc;
-static const unsigned int numSlot = 2000;
+static const unsigned char numSlot = 7;
Mix_Chunk* swordSwing;
static std::vector<Item *> itemMap;
@@ -25,9 +25,12 @@ void items(void){
while(exml){
itemMap.push_back(new Item());
+
itemMap.back()->width = exml->FloatAttribute("width") * HLINE;
itemMap.back()->height = exml->FloatAttribute("height") * HLINE;
itemMap.back()->maxStackSize = exml->UnsignedAttribute("maxstack");
+ itemMap.back()->attribValue = exml->FloatAttribute("value");
+
itemMap.back()->name = exml->Attribute("name");
itemMap.back()->type = exml->Attribute("type");
@@ -188,6 +191,7 @@ void Inventory::setSelectionDown(){
}
void Inventory::draw(void){
+ C("Inventory Start Draw");
static unsigned int lop = 0;
static std::vector<int>dfp(numSlot);
static std::vector<Ray>iray(numSlot);
@@ -211,6 +215,7 @@ void Inventory::draw(void){
unsigned int a = 0;
static bool end = false;
static vec2 mouseStart = {0,0};
+ C("End define");
for(auto &r : iray){
r.start.x = player->loc.x + (player->width/2);
@@ -302,6 +307,7 @@ void Inventory::draw(void){
* a = 0
*/
+ C("Start drawing inventory");
if(invOpen){
for(auto &mr : massRay){
@@ -427,6 +433,7 @@ void Inventory::draw(void){
}
a++;
}
+ C("Done drawing standard inv");
}else if(invHover){
static unsigned int highlight = 0;
static unsigned int thing = 0;
@@ -545,6 +552,10 @@ void itemDraw(Player *p,uint id){
}
}
}else hangle = 0.0f;
+ if(p->inv->usingi){
+ p->inv->useItem();
+ std::cout << "using" << std::endl;
+ }
glUseProgram(shaderProgram);
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
@@ -586,6 +597,9 @@ int Inventory::useItem(void){
swing=true;
Mix_PlayChannel(2,swordSwing,0);
}
+ }else if(itemMap[items[sel].id]->type == "Cooked Food"){
+ player->health += itemMap[items[sel].id]->attribValue;
+ usingi = false;
}
}
return 0;
@@ -606,12 +620,6 @@ bool Inventory::detectCollision(vec2 one, vec2 two){
xc += float(i) * cos((hangle+90)*PI/180);
yc += float(i) * sin((hangle+90)*PI/180);
- /*glColor4f(1.0f,1.0f,1.0f,1.0f);
- glBegin(GL_LINES);
- glVertex2f(player->loc.x,player->loc.y+player->height/3);
- glVertex2f(xc,yc);
- glEnd();*/
-
if(xc >= one.x && xc <= two.x){
if(yc >= one.y && yc <= two.y){
return true;
diff --git a/src/world.cpp b/src/world.cpp
index f03606f..8a46e8d 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -37,6 +37,8 @@ extern bool inBattle;
extern unsigned int tickCount; // main.cpp
+extern std::string xmlFolder;
+
int worldShade = 0;
std::string currentXML;
@@ -1086,7 +1088,7 @@ goInsideStructure( Player *p )
if ( b->inside.empty() )
return this;
- inside.push_back(currentXML.c_str() + 4);
+ inside.push_back(currentXML.c_str() + xmlFolder.size());
tmp = loadWorldFromXML( b->inside );
@@ -1098,7 +1100,7 @@ goInsideStructure( Player *p )
}
}
} else {
- current = currentXML.c_str() + 4;
+ current = currentXML.c_str() + xmlFolder.size();
tmp = loadWorldFromXML( inside.back() );
for ( auto &b : tmp->build ) {
if ( current == b->inside ) {
@@ -1191,7 +1193,9 @@ void World::load(void){
std::string save,data,line;
const char *filedata;
- save = (std::string)currentXML + ".dat";
+ //std::cout << "Loading from: " << std::string(currentXML + ".dat") << std::endl;
+ save = std::string(currentXML + ".dat");
+ //std::cout << "save file: " << save << std::endl;
filedata = readFile(save.c_str());
data = filedata;
std::istringstream iss (data);
@@ -1453,8 +1457,12 @@ static bool loadedLeft = false;
static bool loadedRight = false;
World *loadWorldFromXML(std::string path){
+ C("Scanning for save file");
+ std::cout << "Scanning: " << path << std::endl;
if ( !currentXML.empty() )
currentWorld->save();
+ std::cout << "After Scanning: " << path << std::endl;
+ C("Done scanning for save file");
return loadWorldFromXMLNoSave(path);
}
@@ -1496,7 +1504,9 @@ loadWorldFromXMLNoSave( std::string path ) {
if ( path.empty() )
return NULL;
- currentXML = (std::string)"xml/" + path;
+ std::cout << "File path: " << path << std::endl;
+ currentXML = std::string("storyXML/" + path);
+ std::cout << "Full file path: " << currentXML << std::endl;
xml.LoadFile(currentXML.c_str());
wxml = xml.FirstChildElement("World");
@@ -1678,6 +1688,8 @@ loadWorldFromXMLNoSave( std::string path ) {
tmp->load();
}
+ std::cout << "adadadadasdsa" << std::endl;
+
return tmp;
}
diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml
index a67a932..4930f68 100644
--- a/xml/playerSpawnHill1.xml
+++ b/xml/playerSpawnHill1.xml
@@ -13,6 +13,7 @@
<npc name="Ralph" hasDialog="true" />
<npc name="Johnny" hasDialog="false" />
+ <npc name="Big Dave" hasDialog="true"/>
<page x="-200" id="assets/pages/gootaGoFast.png" />
@@ -67,3 +68,11 @@ And it wasn't stormy.
Broooooooooooooo...
</text>
</Dialog>
+
+<Dialog name="Big Dave">
+ <text id="0" pause="true">
+ Here have this sword!
+ <give id="Wood Sword" count="1"/>
+ <give id="Fried Chicken" count="1"/>
+ </text>
+</Dialog>