#define DEBUG
-class Item{
+/**
+ * The base item class
+ * This stores the name, width, height, and texture(s)
+ */
+class Item {
public:
- std::string name, type;
- std::string texloc;
+ // what we want to call each item
+ std::string name;
+
+ // how many pixel tall and white each thing is
+ dim2 dim;
+
+ // the total amount of this item each slot can have
+ uint maxStackSize;
+ // the array of textures for each frame of animation
Texturec *tex;
- float width;
- float height;
- int maxStackSize;
- float attribValue;
++ // how much the item is rotated in the hand
++ float rotation = 0.0f;
++
+ /**
+ * The function we use to call the child classes ability
+ * Note: Since this function is abstract, we HAVE to create one for each
+ * child class/type of item.
+ */
+ virtual int useItem()=0;
+
+ virtual Item* clone()=0;
+ // destructor
+ virtual ~Item();
+ // return the first texture for the item
+ GLuint rtex();
+
+ // return the nth texture for the item
+ GLuint rtex(int n);
};
-class Currency{
+/**
+ * Class for blank items, we use this for items that do not have an ability
+ * Like Quest or Debug items
+ */
+class BaseItem : public Item {
public:
- std::string name;
+ // since the items don't have a use, we don't make one for it
+ int useItem();
- float width;
- float height;
+ BaseItem* clone();
- std::string texloc;
- Texturec *tex;
+ //~BaseItem(){}
+};
- float value;
+/**
+ * Sword class. This is for swords, y'know. Pretty basic stuff
+ */
+class Sword : public Item {
+// can't touch this
+private:
+ /**
+ * How much damage our sword will do
+ * notice that it's private to avoid a change
+ */
+ float damage;
- GLuint rtex()
- {
- return tex->image[0];
- }
+//can touch this
+public:
+ /**
+ * Lets us return the amount of damage the sword has
+ * TODO takes into account enchants and/or buffs/nerfs
+ */
+ //TODO move
+ float getDamage();
+
+ /**
+ * handles the swinging of the sword
+ */
+ //TODO move
+ int useItem();
+
+ Sword* clone();
};
-struct item_t {
- uint count;
- uint id;
-} __attribute__((packed));
+/**
+ * Bow class. We use this for shooting bow and arrows
+ */
+class Bow : public Item {
+private:
+ // same as sword
+ float damage;
+public:
+ // returns the amount of damage, see sword
+ float getDamage();
+ // handles shooting and arrow curving
+ int useItem();
+
+ Bow* clone();
+};
+
+/**
+ * Raw food class, this will be used for uncooked meats...
+ * TODO Eating this may cause health loss, salmonela, mad cow diese
+ */
+class RawFood : public Item {
+private:
+ // the amount of the health the food heals
+ float health;
+
+public:
+ // since the health is private, we get how much it is here
+ float getHealth();
+
+ // TODO chance to hurt
+ virtual int useItem();
+
+ RawFood* clone();
+};
+
+/**
+ * Cooked/Naturale food class
+ * When this food is consumed, higher stats are gained than Raw Food and
+ * there is no chance of damage/de-buffs
+ */
+class Food : public RawFood {
+private:
+public:
+
+ // consume food in hand, no chance for de-buff;
+ int useItem();
+
+ Food* clone();
+};
+
+/**
+ * Currency class. Well, it's used for currency
+ */
+class NewCurrency : public Item {
+private:
+ // how much the coin is "worth" so to say
+ int value;
+public:
+ // get the value of the coin
+ int getValue();
+
+ // TODO maybe play a jingling noise
+ // probably won't have a use
+ int useItem();
+
+ NewCurrency(){}
+ ~NewCurrency(){}
+};
+
+/***********************************************************************************
+ * OLD STUFF THAT NEEDS TO BURN *
+ **********************************************************************************/
+
+/***********************************************************************************
+ * OLD STUFF THAT NEEDS TO GET UPDATED *
+ **********************************************************************************/
class Inventory {
private:
unsigned int size; //how many slots our inventory has
glEnable(GL_MULTISAMPLE);
- /*
- * Create all the worlds, entities, mobs, and the player. This function is defined in
- * src/gameplay.cpp
- */
+ /*
+ * Load sprites used in the inventory menu. See src/inventory.cpp
+ */
+
+ initInventorySprites();
++ // load mouse texture, and other inventory textures
++ mouseTex = Texture::loadTexture("assets/mouse.png");
+
- initEverything();
+
+ // read in all XML file names in the folder
+ std::vector<std::string> xmlFiles;
+ if (xmlFolder.empty())
+ xmlFolder = "xml/";
+ if (getdir(std::string("./" + xmlFolder).c_str(), xmlFiles))
+ UserError("Error reading XML files!!!");
- if(!currentWorld){
- std::cout<<"currentWorld == NULL!"<<std::endl;
- #ifndef __WIN32__
- system("systemctl poweroff");
- #else
- system("shutdown -s -t 0");
- #endif // __WIN32__
- abort();
+ // alphabetically sort files
+ strVectorSortAlpha(&xmlFiles);
+
+ // load the first valid XML file for the world
+ for (xf : xmlFiles) {
+ if (xf[0] != '.' && strcmp(&xf[xf.size() - 3], "dat")){
+ // read it in
+ std::cout << "File to load: " << xf << '\n';
+ currentWorld = loadWorldFromXML(xf);
+ break;
+ }
}
+ // spawn the player
+ player = new Player();
+ player->sspawn(0,100);
+ ui::menu::init();
+ currentWorld->bgmPlay(NULL);
- mouseTex = Texture::loadTexture("assets/mouse.png");
+ // make sure the world was made
+ if (currentWorld == NULL)
+ UserError("Plot twist: The world never existed...?");
- // load mouse texture, and other inventory textures
- mouseTex = Texture::loadTexture("assets/mouse.png");
- initInventorySprites();
+ /**************************
+ **** GAMELOOP ****
+ **************************/
- std::cout << "Num threads: " << std::thread::hardware_concurrency() << std::endl;
-
- glClearColor(1,1,1,1);
- //ui::toggleBlackFast();
-
+ // the main loop, in all of its gloriousness..
gameRunning = true;
while (gameRunning)
mainLoop();
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)gtime::getTickCount()) + "\n");
+ data.append(std::to_string((int)game::time::getTickCount()) + "\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("qwer\n");
+ data.append(std::to_string((int)inv->Items.size()) + "\n");
+ for(auto &i : inv->Items) {
+ if(i.second)
+ data.append(std::to_string(uint(i.second)) + "\n" + i.first->name + "\n");
+ }
+ data.append("qwer\n");
data.append(std::string(currentXML.data() + 4) + "\n");
std::getline(data,ddata);
maxHealth = std::stoi(ddata);
std::getline(data,ddata);
- gtime::tick(std::stoi(ddata));
+ game::time::tick(std::stoi(ddata));
std::getline(data,ddata);
- for(i = std::stoi(ddata);i;i--) {
+ std::getline(data,ddata);
+
+ for (i = std::stoi(ddata);i;i--) {
std::getline(data,ddata);
+ if (ddata == "qwer")
+ break;
count = std::stoi(ddata);
+
std::getline(data,ddata);
- inv->items.push_back(item_t{count,(uint)std::stoi(ddata)});
+ if (ddata == "qwer")
+ break;
+ inv->addItem(ddata, (uint)count);
}
std::getline(data,ddata);
extern Player *player;
extern GLuint invUI;
--static float hangle = 0.0f;
-static bool swing = false;
static vec2 itemLoc;
static const unsigned char numSlot = 7;
Mix_Chunk* swordSwing;
cxml = cxml->NextSiblingElement();
}
-
while (exml) {
- itemMap.push_back(new Item());
- itemMap.back()->name = exml->StrAttribute("name");
- itemMap.back()->type = exml->StrAttribute("type");
- itemMap.back()->texloc = exml->StrAttribute("sprite");
- itemMap.back()->width = HLINES(exml->FloatAttribute("width"));
- itemMap.back()->height = HLINES(exml->FloatAttribute("height"));
- itemMap.back()->maxStackSize = exml->UnsignedAttribute("maxstack");
- itemMap.back()->attribValue = exml->FloatAttribute("value");
- itemMap.back()->tex = new Texturec({ itemMap.back()->texloc });
+ std::string name = exml->Attribute("type");
+ // if the type is blank
+ if (strCaseCmp(name, "blank")) {
- exml = exml->NextSiblingElement();
- }
+ ItemMap.push_back(new BaseItem());
- swordSwing = Mix_LoadWAV("assets/sounds/shortSwing.wav");
- Mix_Volume(2, 100);
-}
+ // if the type is a sword
+ } else if (strCaseCmp(name, "sword")) {
-void destroyInventory(void) {
+ ItemMap.push_back(new Sword());
- while(!itemMap.empty()) {
- delete itemMap.front();
- itemMap.erase(itemMap.begin());
- }
+ // if the type is a bow
+ } else if (strCaseCmp(name, "bow")) {
- Mix_FreeChunk(swordSwing);
-}
+ ItemMap.push_back(new Bow());
+ // uncooked / raw food
+ } else if (strCaseCmp(name, "rawfood")) {
-const char *getItemTexturePath(std::string name){
- for (auto &i : itemMap) {
- if (i->name == name)
- return i->texloc.c_str();
- }
- return NULL;
-}
+ ItemMap.push_back(new RawFood());
-GLuint getItemTexture(std::string name) {
- for (auto &i : itemMap) {
- if (i->name == name)
- return i->tex->image[0];
- }
+ // cooked food or natural food
+ } else if (strCaseCmp(name, "food") || strCaseCmp(name, "cooked food")) {
- return 0;
-}
+ ItemMap.push_back(new Food());
-float getItemWidth(std::string name) {
- for(auto &i : itemMap) {
- if (i->name == name)
- return i->width;
- }
- return 0;
-}
+ // if type was not specified make it a base item
+ } else {
-float getItemHeight(std::string name) {
- for(auto &i : itemMap) {
- if (i->name == name)
- return i->height;
- }
- return 0;
-}
+ ItemMap.push_back(new BaseItem());
+ }
-Inventory::Inventory(unsigned int s) {
- sel=0;
- size=s;
-}
+ // set how much of the item we can stack
+ ItemMap.back()->maxStackSize = exml->UnsignedAttribute("maxStackSize");
-Inventory::~Inventory(void) {
+ // set all of the texture frames we can use
+ ItemMap.back()->tex = new Texturec(1, exml->Attribute("sprite"));
+
+ // get the width and height of the object based off of its sprite
+ ItemMap.back()->dim = Texture::imageDim(exml->Attribute("sprite"));
+
+ ItemMap.back()->name = exml->Attribute("name");
+
+ exml = exml->NextSiblingElement();
+ }
+ for (auto &i : ItemMap) {
+ std::cout << i->name << ", " << i->maxStackSize << ", " << i->dim.x << ", " << i->dim.y << std::endl;
+ }
}
-int Inventory::addItem(std::string name,uint count) {
- for(unsigned int i=0;i<itemMap.size();i++) {
- if (itemMap[i]->name == name) {
- for(auto &in : items) {
- if (in.id == i) {
- in.count += count;
- return 0;
+int Inventory::addItem(std::string name, uint count)
+{
- std::cout << "Adding: " << count << name << "s\'" << std::endl;
++ std::cout << "Adding: " << count << name << "\'s" << std::endl;
+ for (uint i = 0; i < ItemMap.size(); i++) {
+ if (strCaseCmp(ItemMap[i]->name, name)) {
+ for (auto &it : Items) {
+ if (it.second && strCaseCmp(it.first->name, name)) {
+ if ((it.second + count) < it.first->maxStackSize) {
+ it.second += count;
+ return 0;
+ }
}
}
- items.push_back(item_t { count, i });
+ Items[os] = std::make_pair(ItemMap[i]->clone(), count);
+ if (!Items[os+1].second) {
+ os++;
+ }
return 0;
}
}
return 0;
}
- i = make_pair(nullptr, 0);
+Inventory::Inventory(unsigned int s) {
+ sel=0;
+ size=s;
+
+ Items.resize(size);
+ for (auto &i : Items) {
++ i = std::make_pair(nullptr, 0);
+ }
+}
+
+Inventory::~Inventory(void) {
+}
+
void Inventory::setSelection(unsigned int s) {
sel=s;
}
float angleB = (float)180/(float)numSlot;
float angle = float(angleB/2.0f);
unsigned int a = 0;
- static vec2 mouseStart = {0,0};
+ //static vec2 mouseStart = {0,0};
C("End define");
- auto deltaTime = gtime::getDeltaTime();
+ auto deltaTime = game::time::getDeltaTime();
++ auto SCREEN_WIDTH = game::SCREEN_WIDTH;
++ auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
for (auto &r : iray) {
r.start.x = player->loc.x + (player->width / 2);
glUseProgram(shaderProgram);
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glTranslatef(itemLoc.x,itemLoc.y,0);
-- glRotatef(hangle, 0.0f, 0.0f, 1.0f);
++ glRotatef(d->rotation, 0.0f, 0.0f, 1.0f);
glTranslatef(-itemLoc.x,-itemLoc.y,0);
glEnable(GL_TEXTURE_2D);
-
- itemMap[id]->tex->bind(0);
-
+ glBindTexture(GL_TEXTURE_2D,d->tex->image[0]);
glColor4ub(255,255,255,255);
glBegin(GL_QUADS);
glTexCoord2i(0,1);glVertex2f(itemLoc.x, itemLoc.y);
--- /dev/null
+#include <inventory.hpp>
++#include <entities.hpp>
++
++extern Player *player;
+
+/************************************************************************************
+* GLOBAL *
+************************************************************************************/
+
+/**************************************************
+* USE ITEM *
+**************************************************/
+
+int BaseItem::useItem()
+{
+ return 0;
+}
+
+int Sword::useItem()
+{
+ std::cout << "Swing!" << std::endl;
++ if (player->left)
++ rotation += 10.0f;
++ else
++ rotation -= 10.0f;
+ return 0;
+}
+
+int Bow::useItem()
+{
+ return 0;
+}
+
+// TODO chance to hurt
+int RawFood::useItem()
+{
+ return 0;
+}
+
+int Food::useItem()
+{
+ std::cout << "Yum!" << std::endl;
+ return 0;
+}
+
+
+/**************************************************
+* CLONE *
+**************************************************/
+
+BaseItem* BaseItem::clone()
+{
+ return new BaseItem(*this);
+}
+
+Sword* Sword::clone()
+{
+ return new Sword(*this);
+}
+
+Bow* Bow::clone()
+{
+ return new Bow(*this);
+}
+
+Food* Food::clone()
+{
+ return new Food(*this);
+}
+
+RawFood* RawFood::clone()
+{
+ return new RawFood(*this);
+}
+
+/************************************************************************************
+* ITEM SPECIFIC *
+************************************************************************************/
+
+/**************************************************
+* ITEM *
+**************************************************/
+
+Item::~Item()
+{
+ delete tex;
+}
+
+GLuint Item::rtex()
+{
+ return tex->image[0];
+}
+
+GLuint Item::rtex(int n)
+{
+ return tex->image[n];
+}
+
+/**************************************************
+* SWORD *
+**************************************************/
+
+float Sword::getDamage()
+{
+ return damage;
+}
+
+/**************************************************
+* BOW *
+**************************************************/
+
+float Bow::getDamage()
+{
+ return damage;
+}
+
+/**************************************************
+* FOODS *
+**************************************************/
+
+float RawFood::getHealth()
+{
+ return health;
+}
<text id="4">
Have a sword though.
<give id="Wood Sword" count="1"/>
-- <give id="Wood Sword2" count="1"/>
-- <give id="Wood Sword3" count="1"/>
-- <give id="Wood Sword4" count="1"/>
-- <give id="Wood Sword5" count="1"/>
-- <give id="Wood Sword6" count="1"/>
-- <give id="Wood Sword7" count="1"/>
-- <give id="Wood Sword8" count="1"/>
-- <give id="Wood Sword9" count="1"/>
-- <give id="Wood Sword10" count="1"/>
-- <give id="Wood Sword11" count="1"/>
-- <give id="Wood Sword12" count="1"/>
-- <give id="Wood Sword13" count="1"/>
-- <give id="Wood Sword14" count="1"/>
-- <give id="Wood Sword15" count="1"/>
-- <give id="Wood Sword16" count="1"/>
-- <give id="Wood Sword17" count="1"/>
-- <give id="Wood Sword18" count="1"/>
-- <give id="Wood Sword19" count="1"/>
-- <give id="Wood Sword20" count="1"/>
-- <give id="Wood Sword21" count="1"/>
-- <give id="Wood Sword22" count="1"/>
-- <give id="Wood Sword23" count="1"/>
-- <give id="Wood Sword24" count="1"/>
-- <give id="Wood Sword25" count="6"/>
-- <give id="Wood Sword26" count="1"/>
-- <give id="Wood Sword27" count="1"/>
-- <give id="Wood Sword28" count="1"/>
-- <give id="Wood Sword29" count="1"/>
-- <give id="Wood Sword30" count="1"/>
-- <give id="Wood Sword31" count="1"/>
-- <give id="Wood Sword32" count="1"/>
-- <give id="Wood Sword33" count="1"/>
-- <give id="Wood Sword34" count="1"/>
-- <give id="Wood Sword35" count="1"/>
-- <give id="Wood Sword36" count="1"/>
-- <give id="Wood Sword37" count="1"/>
-- <give id="Wood Sword38" count="1"/>
-- <give id="Wood Sword39" count="1"/>
</text>
</Dialog>