#define DEBUG
-class Item{
+/**
+ * The base item class
+ * This stores the name, width, height, and texture(s)
+ */
+class Item {
public:
- std::string name, type;
+ // what we want to call each item
+ std::string name;
+
+ // how many pixel tall and white each thing is
+ dim2 dim;
- float width;
- float height;
- int maxStackSize;
- float attribValue;
+ // the total amount of this item each slot can have
+ uint maxStackSize;
- std::string texloc;
+ // the array of textures for each frame of animation
Texturec *tex;
- GLuint rtex()
- {
- return tex->image[0];
- }
+ /**
+ * 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(){}
+};
+
+/**
+ * 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;
+
+//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();
+};
+
+/**
+ * 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:
- float value;
+ // consume food in hand, no chance for de-buff;
+ int useItem();
- GLuint rtex()
- {
- return tex->image[0];
- }
+ Food* clone();
};
-struct item_t{
- uint count;
- uint id;
-} __attribute__((packed));
+/**
+ * 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
unsigned int sel; //what item is currently selected
int os = 0;
public:
- std::vector<item_t> items;
+ std::vector<std::pair<Item*, uint>> Items;
bool invOpen = false; //is the inventory open
bool invOpening = false; //is the opening animation playing
Inventory(unsigned int s); // Creates an inventory of size 's'
~Inventory(void); // Free's allocated memory
+ int useCurrent();
+
int addItem(std::string name,uint count);
int takeItem(std::string name,uint count);
int hasItem(std::string name);
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;
-static std::vector<Item *> itemMap;
-static std::vector<Currency *> currencyMap;
-static GLuint *itemtex;
-void itemDraw(Player *p,uint id);
+static std::vector<NewCurrency *> currencyMap;
+static std::vector<Item *> ItemMap;
-void items(void) {
+
+void itemDraw(Player *p, Item* d);
+
+bool strCaseCmp(std::string one, std::string two)
+{
+ for (auto &s : one) {
+ s = std::tolower(s);
+ }
+ for (auto &t : two) {
+ t = std::tolower(t);
+ }
+
+ if (one == two) return true;
+ return false;
+}
+
+void items(void)
+{
XMLDocument xml;
xml.LoadFile("config/items.xml");
XMLElement *exml = xml.FirstChildElement("item");
XMLElement *cxml = xml.FirstChildElement("currency");
- while (cxml) {
- currencyMap.push_back(new Currency());
-
- currencyMap.back()->width = 7*HLINE;
- currencyMap.back()->height = 7*HLINE;
+ while (cxml) {
- currencyMap.back()->name = cxml->Attribute("name");
- currencyMap.back()->value = cxml->FloatAttribute("value");
+ // NEWEWEWEWEWEWEWEW
+ // TODO
cxml = cxml->NextSiblingElement();
}
while (exml) {
- itemMap.push_back(new Item());
+ std::string name = exml->Attribute("type");
+ // if the type is blank
+ if (strCaseCmp(name, "blank")) {
+
+ ItemMap.push_back(new BaseItem());
+
+ // if the type is a sword
+ } else if (strCaseCmp(name, "sword")) {
+
+ ItemMap.push_back(new Sword());
+
+ // if the type is a bow
+ } else if (strCaseCmp(name, "bow")) {
- 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.push_back(new Bow());
+ // uncooked / raw food
+ } else if (strCaseCmp(name, "rawfood")) {
- itemMap.back()->name = exml->Attribute("name");
- itemMap.back()->type = exml->Attribute("type");
- itemMap.back()->texloc = exml->Attribute("sprite");
+ ItemMap.push_back(new RawFood());
+
+ // cooked food or natural food
+ } else if (strCaseCmp(name, "food") || strCaseCmp(name, "cooked food")) {
+
+ ItemMap.push_back(new Food());
+
+ // if type was not specified make it a base item
+ } else {
+
+ ItemMap.push_back(new BaseItem());
+ }
+
+ // set how much of the item we can stack
+ ItemMap.back()->maxStackSize = exml->UnsignedAttribute("maxStackSize");
+
+ // 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;
+ 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 -1;
}
-int Inventory::takeItem(std::string name,uint count) {
- unsigned int id = 999999;
+int Inventory::takeItem(std::string name, uint count)
+{
- /*
- * Name to ID lookup
- */
+ // returns
+ // 0 = good
+ // -1 = no such item exists
+ // -2 = if item doesnt exist in inventory
+ // postive items = number returned is how many more the item needs
+
+ std::string iden;
- for(unsigned int i=0;i<itemMap.size();i++) {
- if (itemMap[i]->name == name) {
- id = i;
+ for (uint i = 0; i < ItemMap.size(); i++) {
+ if (ItemMap[i]->name == name) {
+ iden = name;
break;
}
}
- if (id == 999999)
- return -1; //if no such item exists
+ if (iden.empty()) {
+ return -1;
+ }
- /*
- * Inventory lookup
- */
+ for (auto &i : Items) {
+ if (i.second && i.first->name == iden) {
+ if (count > i.second) {
+ return (count - i.second);
+ } else {
+ i.second -= count;
- for(unsigned int i=0;i<items.size();i++) {
- if (items[i].id == id) {
- if (count > items[i].count)
- return -(items[i].count - count);
- else{
- items[i].count -= count;
- if (!items[i].count)
- items.erase(items.begin()+i);
}
return 0;
}
}
+
return -2;
}
int Inventory::hasItem(std::string name) {
- unsigned int id = 999999;
- for(unsigned int i=0;i<itemMap.size();i++) {
- if (itemMap[i]->name == name) {
- id = i;
- break;
+ for (auto &i : Items) {
+ if (i.first->name == name) {
+ return i.second;
}
}
- if (id == 999999)
- return 0;
-
- for(auto &i : items) {
- if (i.id == id)
- return i.count;
- }
-
return 0;
}
-
void initInventorySprites(void) {
items();
- itemtex = new GLuint[itemMap.size()];
-
- for(unsigned int i = 0;i<itemMap.size();i++) {
- itemtex[i] = Texture::loadTexture(getItemTexturePath(itemMap[i]->name));
- }
+ // keep
swordSwing = Mix_LoadWAV("assets/sounds/shortSwing.wav");
Mix_Volume(2,100);
}
void destroyInventory(void) {
- while(!itemMap.empty()) {
- delete itemMap.front();
- itemMap.erase(itemMap.begin());
+ // NEWEWEWEWEWEWEWEW
+ while (!ItemMap.empty()) {
+ delete ItemMap.front();
+ ItemMap.erase(std::begin(ItemMap));
}
Mix_FreeChunk(swordSwing);
const char *getItemTexturePath(std::string name){
- for (auto &i : itemMap) {
+ for (auto &i : ItemMap) {
if (i->name == name)
- return i->texloc.c_str();
+ return i->tex->texLoc[0].c_str();
}
return NULL;
}
GLuint getItemTexture(std::string name) {
- for (int i = itemMap.size(); i--;) {
- if (itemMap[i]->name == name)
- return itemtex[i];
+ for (auto &i : ItemMap) {
+ if (i->name == name) {
+ return i->tex->image[0];
+ }
}
- DEBUG_printf("Failed to find texture for item %s!", name.c_str());
return 0;
}
float getItemWidth(std::string name) {
- for(auto &i : itemMap) {
+ for (auto &i : ItemMap) {
if (i->name == name)
- return i->width;
+ return i->dim.x;
}
return 0;
}
float getItemHeight(std::string name) {
- for(auto &i : itemMap) {
+ for (auto &i : ItemMap) {
if (i->name == name)
- return i->height;
+ return i->dim.y;
}
return 0;
}
Inventory::Inventory(unsigned int s) {
sel=0;
size=s;
+
+ Items.resize(size);
+ for (auto &i : Items) {
+ i = make_pair(nullptr, 0);
+ }
}
Inventory::~Inventory(void) {
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();
glVertex2i(mr.x-(itemWide/2)+itemWide,mr.y-(itemWide/2)+itemWide);
glVertex2i(mr.x-(itemWide/2), mr.y-(itemWide/2)+itemWide);
glEnd();
- if (!items.empty() && a+numSlot < items.size() && items[a+numSlot].count) {
+ if (!Items.empty() && a+numSlot < Items.size() && Items[a+numSlot].second) {
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, itemtex[items[a+numSlot].id]);
+ glBindTexture(GL_TEXTURE_2D, Items[a+numSlot].first->tex->image[0]);//itemtex[items[a+numSlot].id]);
glColor4f(1.0f, 1.0f, 1.0f, ((float)massDfp[a]/(float)(massRange?massRange:1))*0.8f);
glBegin(GL_QUADS);
- if (itemMap[items[a+numSlot].id]->height > itemMap[items[a+numSlot].id]->width) {
- glTexCoord2i(0,1);glVertex2i(mr.x-((itemWide/2)*((float)itemMap[items[a+numSlot].id]->width/(float)itemMap[items[a+numSlot].id]->height)), mr.y-(itemWide/2));
- glTexCoord2i(1,1);glVertex2i(mr.x+((itemWide/2)*((float)itemMap[items[a+numSlot].id]->width/(float)itemMap[items[a+numSlot].id]->height)), mr.y-(itemWide/2));
- glTexCoord2i(1,0);glVertex2i(mr.x+((itemWide/2)*((float)itemMap[items[a+numSlot].id]->width/(float)itemMap[items[a+numSlot].id]->height)), mr.y+(itemWide/2));
- glTexCoord2i(0,0);glVertex2i(mr.x-((itemWide/2)*((float)itemMap[items[a+numSlot].id]->width/(float)itemMap[items[a+numSlot].id]->height)), mr.y+(itemWide/2));
+ if (Items[a+numSlot].first->dim.y > Items[a+numSlot].first->dim.x) {
+ glTexCoord2i(0,1);glVertex2i(mr.x-((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)), mr.y-(itemWide/2));
+ glTexCoord2i(1,1);glVertex2i(mr.x+((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)), mr.y-(itemWide/2));
+ glTexCoord2i(1,0);glVertex2i(mr.x+((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)), mr.y+(itemWide/2));
+ glTexCoord2i(0,0);glVertex2i(mr.x-((itemWide/2)*((float)Items[a+numSlot].first->dim.x/(float)Items[a+numSlot].first->dim.y)), mr.y+(itemWide/2));
}else{
- glTexCoord2i(0,1);glVertex2i(mr.x-(itemWide/2),mr.y-(itemWide/2)*((float)itemMap[items[a+numSlot].id]->height/(float)itemMap[items[a+numSlot].id]->width));
- glTexCoord2i(1,1);glVertex2i(mr.x+(itemWide/2),mr.y-(itemWide/2)*((float)itemMap[items[a+numSlot].id]->height/(float)itemMap[items[a+numSlot].id]->width));
- glTexCoord2i(1,0);glVertex2i(mr.x+(itemWide/2),mr.y+(itemWide/2)*((float)itemMap[items[a+numSlot].id]->height/(float)itemMap[items[a+numSlot].id]->width));
- glTexCoord2i(0,0);glVertex2i(mr.x-(itemWide/2),mr.y+(itemWide/2)*((float)itemMap[items[a+numSlot].id]->height/(float)itemMap[items[a+numSlot].id]->width));
+ glTexCoord2i(0,1);glVertex2i(mr.x-(itemWide/2),mr.y-(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x));
+ glTexCoord2i(1,1);glVertex2i(mr.x+(itemWide/2),mr.y-(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x));
+ glTexCoord2i(1,0);glVertex2i(mr.x+(itemWide/2),mr.y+(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x));
+ glTexCoord2i(0,0);glVertex2i(mr.x-(itemWide/2),mr.y+(itemWide/2)*((float)Items[a+numSlot].first->dim.y/(float)Items[a+numSlot].first->dim.x));
}
glEnd();
glDisable(GL_TEXTURE_2D);
ui::setFontColor(255,255,255,((float)massDfp[a]/(float)(massRange?massRange:1))*255);
- ui::putText(mr.x-(itemWide/2)+(itemWide*.85),mr.y-(itemWide/2),"%d",items[a+numSlot].count);
+ ui::putText(mr.x-(itemWide/2)+(itemWide*.85),mr.y-(itemWide/2),"%d",Items[a+numSlot].second);
ui::setFontColor(255,255,255,255);
}
a++;
glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)+itemWide);
glEnd();
- if (!items.empty() && a < numSlot && items[a].count) {
+ if (!Items.empty() && a < numSlot && Items[a].second) {
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, itemtex[items[a].id]);
+ glBindTexture(GL_TEXTURE_2D, Items[a].first->tex->image[0]);//itemtex[items[a].id]);
glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)(range?range:1))*0.8f);
glBegin(GL_QUADS);
- if (itemMap[items[a].id]->height > itemMap[items[a].id]->width) {
- glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)), r.end.y-(itemWide/2));
- glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)), r.end.y-(itemWide/2));
- glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)), r.end.y+(itemWide/2));
- glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)), r.end.y+(itemWide/2));
- }else{
- glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
- glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
- glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
- glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
- }
+ if (Items[a].first->dim.y > Items[a].first->dim.x) {
+ glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)), r.end.y-(itemWide/2));
+ glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)), r.end.y-(itemWide/2));
+ glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)), r.end.y+(itemWide/2));
+ glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)Items[a].first->dim.x/(float)Items[a].first->dim.y)), r.end.y+(itemWide/2));
+ }else{
+ glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),r.end.y-(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x));
+ glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),r.end.y-(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x));
+ glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x));
+ glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),r.end.y+(itemWide/2)*((float)Items[a].first->dim.y/(float)Items[a].first->dim.x));
+ }
glEnd();
glDisable(GL_TEXTURE_2D);
ui::setFontColor(255,255,255,((float)dfp[a]/(float)(range?range:1))*255);
- ui::putStringCentered(r.end.x,r.end.y-(itemWide*.9),itemMap[items[a].id]->name);
- ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",items[a].count);
+ ui::putStringCentered(r.end.x,r.end.y-(itemWide*.9),Items[a].first->name);//itemMap[items[a].id]->name);
+ ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",Items[a].second);
ui::setFontColor(255,255,255,255);
}
a++;
}
C("Done drawing standard inv");
- } else if (invHover) {
+ } /*else if (invHover) {
static unsigned int highlight = 0;
static unsigned int thing = 0;
itemMap[items[highlight].id]->name
);
}
- }
- if (!items.empty() && items.size() > sel && items[sel].count)
- itemDraw(player,items[sel].id);
+ }*/
+ /*if (!items.empty() && items.size() > sel && items[sel].count)
+ itemDraw(player,items[sel].id);*/
+ if (!Items.empty() && Items.size() > sel && Items[sel].second)
+ itemDraw(player, Items[sel].first);
}
-void itemDraw(Player *p,uint id) {
- static unsigned char inc = 0;
+void itemDraw(Player *p, Item *d) {
itemLoc.y = p->loc.y+(p->height/3);
itemLoc.x = p->left?p->loc.x:p->loc.x+p->width;
glPushMatrix();
- if (!id)return;
-
- if (itemMap[id]->type == "Sword") {
- if (p->left) {
- if (hangle < 15) {
- hangle=15.0f;
- p->inv->usingi = false;
- }
- }else{
- if (hangle > -15) {
- hangle=-15.0f;
- p->inv->usingi = false;
- }
- }
- } else
- hangle = 0;
-
- if (p->inv->usingi)
- inc = 10;
-
- if (inc) {
- inc--;
- p->inv->useItem();
- }
-
glUseProgram(shaderProgram);
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glTranslatef(itemLoc.x,itemLoc.y,0);
glRotatef(hangle, 0.0f, 0.0f, 1.0f);
glTranslatef(-itemLoc.x,-itemLoc.y,0);
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,itemtex[id]);
+ glBindTexture(GL_TEXTURE_2D,d->tex->image[0]);
glColor4ub(255,255,255,255);
glBegin(GL_QUADS);
glTexCoord2i(0,1);glVertex2f(itemLoc.x, itemLoc.y);
- glTexCoord2i(1,1);glVertex2f(itemLoc.x+itemMap[id]->width,itemLoc.y);
- glTexCoord2i(1,0);glVertex2f(itemLoc.x+itemMap[id]->width,itemLoc.y+itemMap[id]->height);
- glTexCoord2i(0,0);glVertex2f(itemLoc.x, itemLoc.y+itemMap[id]->height);
+ glTexCoord2i(1,1);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y);
+ glTexCoord2i(1,0);glVertex2f(itemLoc.x+d->dim.x,itemLoc.y+d->dim.y);
+ glTexCoord2i(0,0);glVertex2f(itemLoc.x, itemLoc.y+d->dim.y);
glEnd();
glDisable(GL_TEXTURE_2D);
glTranslatef(player->loc.x*2,0,0);
glUseProgram(0);
}
+/*
+ * This function is used to trigger the player's item's ability.
+ */
int Inventory::useItem(void)
{
- static bool up = false;
-
- if (!invHover) {
- if (itemMap[items[sel].id]->type == "Sword") {
- if (swing) {
- int dir = player->left ? 1 : -1;
-
- if (hangle == 15 * dir) {
- up = true;
- Mix_PlayChannel(2, swordSwing, 0);
- }
-
- if (up)
- hangle += 0.325f * dir * gtime::getDeltaTime();
-
- if (!player->left) {
- if (hangle <= -90)
- hangle = -14;
- } else if (hangle >= 90)
- hangle = 14;
- } else {
- 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;
}
+int Inventory::useCurrent()
+{
+ if(Items[sel].second)
+ return Items[sel].first->useItem();
+ return -1;
+}
+
bool Inventory::detectCollision(vec2 one, vec2 two) {
(void)one;
(void)two;
- float xc, yc;
- float i = 0.0f;
-
- if (items.empty() || !items[sel].count)
- return false;
- if (itemMap[items[sel].id]->type == "Sword") {
- while(i<itemMap[items[sel].id]->height) {
- xc = itemLoc.x; yc = itemLoc.y;
- xc += float(i) * cos((hangle+90)*PI/180);
- yc += float(i) * sin((hangle+90)*PI/180);
-
- if (xc >= one.x && xc <= two.x) {
- if (yc >= one.y && yc <= two.y) {
- return true;
- }
- }
-
- i+=HLINE;
- }
- }
return false;
}