<!--##########-->
<!-- WEAPONS -->
-<item name="Wood Sword" type="Sword" damage="3" maxStackSize="1" sprite="assets/items/SWORD_WOOD.png" />
+<item name="Wood Sword" type="Sword" damage="3" maxStackSize="1" sound="assets/sounds/longSwing.wav" sprite="assets/items/SWORD_WOOD.png" />
<item name="Hunters Bow" type="Bow" damage="2" maxStackSize="1" sprite="assets/items/bow.png"/>
-<item name="Crude Arrow" type="Arrow" damage="1" maxStackSize="99" sprite="assets/items/arrow_crude.png"/>
+<item name="Arrow" type="Arrow" damage="1" maxStackSize="99" sprite="assets/items/arrow_crude.png"/>
<!-- UTILITIES -->
<!--<item name="Rusty Lantern" type="Light" radius="150" color="255|255|255" sprite="assets/items/rusty_lantern.png"/>-->
#include <GL/glew.h>
#include <SDL2/SDL_opengl.h>
+#include <SDL2/SDL_mixer.h>
#include <string>
#include <vector>
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) {}
* Constructs an item from XML.
* @param the xml element (<item />)
*/
- Item(XMLElement *e) {
+ Item(XMLElement* e) {
name = e->StrAttribute("name");
type = e->StrAttribute("type");
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);
}
};
* @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_
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);
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;
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;
/////////////////////////////
- game::engine.getSystem<InventorySystem>()->add("Wood Sword", 9);
+ game::engine.getSystem<InventorySystem>()->add("Wood Sword", 1);
+ game::engine.getSystem<InventorySystem>()->add("Hunters Bow", 1);
+ game::engine.getSystem<InventorySystem>()->add("Arrow", 40);
std::list<SDL_Event> eventQueue;
for (const auto& a : attacks) {
switch (a.type) {
case AttackType::ShortSlash:
+ case AttackType::LongSlash:
en.each<Position, Solid, Health>(
[&a](entityx::Entity e, Position& pos, Solid& dim, Health& h) {
(void)e;
}
);
break;
- case AttackType::LongSlash:
- break;
default:
break;
}
// make the entity wander
// TODO initialX and range?
- if (entity.has_component<Aggro>()) {
+ if (0 && entity.has_component<Aggro>()) {
auto ppos = game::engine.getSystem<PlayerSystem>()->getPosition();
if (ppos.x > position.x && ppos.x < position.x + entity.component<Solid>()->width) {
auto& h = entity.component<Health>()->health;
void PlayerSystem::receive(const UseItemEvent& uie)
{
- if (uie.item->type == "Sword") {
- auto loc = getPosition();
- auto &solid = *player.component<Solid>().get();
- loc.x += solid.width / 2, loc.y += solid.height / 2;
- game::events.emit<AttackEvent>(loc, AttackType::ShortSlash);
+ static std::atomic_bool cool (true);
+
+ if (cool.load()) {
+ if (uie.item->sound != nullptr)
+ Mix_PlayChannel(0, uie.item->sound, 0);
+
+ if (uie.item->type == "Sword") {
+ auto loc = getPosition();
+ auto &solid = *player.component<Solid>().get();
+ loc.x += solid.width / 2, loc.y += solid.height / 2;
+ game::events.emit<AttackEvent>(loc, AttackType::ShortSlash);
+ } else if (uie.item->type == "Bow") {
+ if (game::engine.getSystem<InventorySystem>()->take("Arrow", 1)) {
+ auto e = game::entities.create();
+ auto pos = getPosition();
+ e.assign<Position>(pos.x, pos.y + 10);
+
+ auto angle = std::atan2(uie.curs.y - pos.y, uie.curs.x - pos.x);
+ e.assign<Direction>(1 * std::cos(angle), 1 * std::sin(angle));
+
+ e.assign<Visible>(-5);
+ e.assign<Physics>();
+ auto sprite = e.assign<Sprite>();
+ auto tex = game::engine.getSystem<InventorySystem>()->getItem("Arrow");
+ sprite->addSpriteSegment(SpriteData(tex.sprite), 0);
+ auto dim = HLINES(sprite->getSpriteSize());
+ e.assign<Solid>(dim.x, dim.y);
+ }
+ }
+
+ /*cool.store(false);
+ std::thread([&](void) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(uie.item->cooldown));
+ cool.store(true);
+ }).detach();*/
}
}
fadeWhite = true;
fadeFast = true;
- Mix_PlayChannel(1, battleStart, 0);
+ //Mix_PlayChannel(1, battleStart, 0);
}
void takeScreenshot(GLubyte* pixels) {