aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-03-17 22:17:30 -0400
committerClyne Sullivan <tullivan99@gmail.com>2017-03-17 22:17:30 -0400
commit19ade83b74aa66c80129409d97c2c98fa8b8534c (patch)
treeed8fdfb53a302d1e236cb74b7f0413f83f55020d /include
parentbf01660ab468f49d63a133c28131ab21bba3a1a1 (diff)
bow & arrow draft
Diffstat (limited to 'include')
-rw-r--r--include/inventory.hpp22
-rw-r--r--include/vector2.hpp15
2 files changed, 36 insertions, 1 deletions
diff --git a/include/inventory.hpp b/include/inventory.hpp
index 1052b20..adf16f1 100644
--- a/include/inventory.hpp
+++ b/include/inventory.hpp
@@ -7,6 +7,7 @@
#include <GL/glew.h>
#include <SDL2/SDL_opengl.h>
+#include <SDL2/SDL_mixer.h>
#include <string>
#include <vector>
@@ -28,6 +29,8 @@ struct Item {
int value; /**< The value/worth of the item */
int stackSize; /**< The stack size of the item */
Texture sprite; /**< The texture for the item (in inventory) */
+ Mix_Chunk* sound; /**< The sound to play on item use */
+ int cooldown;
Item(void)
: value(0), stackSize(1) {}
@@ -36,7 +39,7 @@ struct Item {
* Constructs an item from XML.
* @param the xml element (<item />)
*/
- Item(XMLElement *e) {
+ Item(XMLElement* e) {
name = e->StrAttribute("name");
type = e->StrAttribute("type");
@@ -46,6 +49,19 @@ struct Item {
e->QueryIntAttribute("maxStackSize", &stackSize);
sprite = Texture(e->StrAttribute("sprite"));
+
+ if (e->Attribute("sound") != nullptr)
+ sound = Mix_LoadWAV(e->Attribute("sound"));
+ else
+ sound = nullptr;
+
+ cooldown = 250;
+ e->QueryIntAttribute("cooldown", &cooldown);
+ }
+
+ ~Item(void) {
+ if (sound != nullptr)
+ Mix_FreeChunk(sound);
}
};
@@ -128,6 +144,10 @@ public:
* @return true if the operation could be completed
*/
bool take(const std::string& name, int count);
+
+ inline Item getItem(const std::string& s) {
+ return itemList[s];
+ }
};
#endif // INVENTORY_HPP_
diff --git a/include/vector2.hpp b/include/vector2.hpp
index 5671ccd..beb2787 100644
--- a/include/vector2.hpp
+++ b/include/vector2.hpp
@@ -48,6 +48,11 @@ struct vector2 {
return vector2<T>(x - n, y - n);
}
+ vector2<T> operator-=(const vector2<T>& v) {
+ x -= v.x, y -= v.y;
+ return *this;
+ }
+
// multiplication
vector2<T> operator*(const vector2<T>& v) const {
return vector2<T>(x * v.x, y * v.y);
@@ -57,6 +62,11 @@ struct vector2 {
return vector2<T>(x * n, y * n);
}
+ vector2<T> operator*=(const vector2<T>& v) {
+ x *= v.x, y *= v.y;
+ return *this;
+ }
+
vector2<T> operator*=(const T& n) {
x *= n, y *= n;
return *this;
@@ -71,6 +81,11 @@ struct vector2 {
return vector2<T>(x / n, y / n);
}
+ vector2<T> operator/=(const vector2<T>& v) {
+ x /= v.x, y /= v.y;
+ return *this;
+ }
+
vector2<T> operator/=(const T& n) {
x /= n, y /= n;
return *this;