aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-02-09 20:26:32 -0500
committerClyne Sullivan <tullivan99@gmail.com>2017-02-09 20:26:32 -0500
commit27892bc40122494385bdbe5eb84aee52737f9c13 (patch)
treec8145ac93afbfc4d30e78dea8dc2a5de6e2b0972 /src
parent7f77420e0ea5f1b5a36539b06a1207c98bec1927 (diff)
skirl; angry
Diffstat (limited to 'src')
-rw-r--r--src/components.cpp24
-rw-r--r--src/inventory.cpp9
-rw-r--r--src/particle.cpp4
-rw-r--r--src/quest.cpp15
-rw-r--r--src/world.cpp11
5 files changed, 54 insertions, 9 deletions
diff --git a/src/components.cpp b/src/components.cpp
index 7cb533c..7506d40 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -6,11 +6,13 @@
#include <render.hpp>
#include <ui.hpp>
#include <engine.hpp>
+#include <error.hpp>
#include <world.hpp>
#include <brice.hpp>
#include <quest.hpp>
#include <glm.hpp>
#include <fileio.hpp>
+#include <player.hpp>
#include <atomic>
@@ -45,7 +47,18 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
// make the entity wander
// TODO initialX and range?
- if (entity.has_component<Wander>()) {
+ if (entity.has_component<Aggro>()) {
+ auto ppos = game::engine.getSystem<PlayerSystem>()->getPosition();
+ if (ppos.x > position.x && ppos.x < position.x + entity.component<Solid>()->width) {
+ ui::toggleWhiteFast();
+ ui::waitForCover(); // TODO thread safe call to load world?
+ //game::engine.getSystem<WorldSystem>()->load(entity.component<Aggro>()->arena);
+ ui::toggleWhiteFast();
+ entity.destroy();
+ } else {
+ direction.x = (ppos.x > position.x) ? .05 : -.05;
+ }
+ } else if (entity.has_component<Wander>()) {
auto& countdown = entity.component<Wander>()->countdown;
if (countdown > 0) {
@@ -212,6 +225,15 @@ void DialogSystem::receive(const MouseClickEvent &mce)
game::briceUpdate();
}
+ auto ixml = exml->FirstChildElement("give");
+ if (ixml != nullptr) {
+ do {
+ game::engine.getSystem<InventorySystem>()->add(
+ ixml->StrAttribute("name"), ixml->IntAttribute("count"));
+ ixml = ixml->NextSiblingElement();
+ } while (ixml != nullptr);
+ }
+
auto qxml = exml->FirstChildElement("quest");
if (qxml != nullptr) {
const char *qname;
diff --git a/src/inventory.cpp b/src/inventory.cpp
index fd844f5..f1332f2 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -22,7 +22,7 @@ static bool fullInventory = false;
constexpr int entrySize = 70;
constexpr int hotbarSize = 4;
-constexpr float inventoryZ = -6.0f;
+constexpr float inventoryZ = -5.0f;
constexpr unsigned int rowSize = 8;
static int movingItem = -1;
@@ -100,7 +100,7 @@ void InventorySystem::render(void)
glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, 1);
// draw the item
- if (i.item != nullptr) {
+ if (i.item != nullptr && i.count > 0) {
i.item->sprite.use();
static const GLfloat tex[12] = {0,1,1,1,1,0,1,0,0,0,0,1};
glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
@@ -115,7 +115,7 @@ void InventorySystem::render(void)
if (n == movingItem)
glUniform4f(Render::textShader.uniform[WU_tex_color], .8, .8, 1, .8);
glDrawArrays(GL_TRIANGLES, 0, 6);
- ui::setFontZ(-7.2); // TODO fix z's
+ ui::setFontZ(inventoryZ - 0.3); // TODO fix z's
ui::putText(sta.x, sta.y, std::to_string(i.count).c_str());
ui::setFontZ(-6);
glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, 1);
@@ -144,6 +144,9 @@ void InventorySystem::receive(const MouseClickEvent &mce)
int end = fullInventory ? items.size() : hotbarSize;
movingItem = -1;
for (int i = 0; i < end; i++) {
+ if (items[i].item == nullptr || items[i].count == 0)
+ continue;
+
if (mce.position > items[i].loc && mce.position < items[i].loc + entrySize) {
movingItem = i;
break;
diff --git a/src/particle.cpp b/src/particle.cpp
index 6eeec33..006bc45 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -36,7 +36,7 @@ void ParticleSystem::render(void)
// generate VBO
glGenBuffers(1, &particleVBO);
glBindBuffer(GL_ARRAY_BUFFER, particleVBO);
- glBufferData(GL_ARRAY_BUFFER, maximum * entrySize, nullptr, GL_STREAM_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, maximum * entrySize, nullptr, GL_DYNAMIC_DRAW);
}
// clear dead particles
@@ -46,7 +46,7 @@ void ParticleSystem::render(void)
// copy data into VBO
glBindBuffer(GL_ARRAY_BUFFER, particleVBO);
- for (unsigned int i = 0, offset = 0; i < parts.size() - 1; i++, offset += entrySize) {
+ for (unsigned int i = 0, offset = 0; i < parts.size(); i++, offset += entrySize) {
const auto& p = parts[i];
static const auto& hl = game::HLINE;
GLfloat coords[30] = {
diff --git a/src/quest.cpp b/src/quest.cpp
index 8107eb6..920ac84 100644
--- a/src/quest.cpp
+++ b/src/quest.cpp
@@ -2,7 +2,20 @@
#include <algorithm>
-extern std::vector<std::string> StringTokenizer(const std::string& str, char delim);
+std::vector<std::string> StringTokenizer(const std::string& str, char delim);
+
+std::vector<std::string> split(std::string s, const std::string& delim)
+{
+ std::vector<std::string> res;
+
+ while (!s.empty()) {
+ auto pos = s.find(delim);
+ res.emplace_back(s.substr(0, pos));
+ s = s.substr(pos + 1);
+ }
+
+ return res;
+}
void QuestSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
{
diff --git a/src/world.cpp b/src/world.cpp
index 4f2f99c..8db9344 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -203,20 +203,25 @@ void WorldSystem::load(const std::string& file)
UserError("XML Error: Failed to parse file (not your fault though..?)");
// include headers
+ std::vector<std::string> toAdd;
auto ixml = xmlDoc.FirstChildElement("include");
while (ixml != nullptr) {
auto file = ixml->Attribute("file");
if (file != nullptr) {
DEBUG_printf("Including file: %s\n", file);
- xmlRaw.append(readFile(xmlFolder + file));
+ toAdd.emplace_back(xmlFolder + file);
+ //xmlRaw.append(readFile(xmlFolder + file));
} else {
UserError("XML Error: <include> tag file not given");
}
- break;//ixml = ixml->NextSiblingElement();
+ ixml = ixml->NextSiblingElement("include");
}
+ for (const auto& f : toAdd)
+ xmlRaw.append(readFile(f));
+
if (xmlDoc.Parse(xmlRaw.data()) != XML_NO_ERROR)
UserError("XML Error:");
@@ -385,6 +390,8 @@ void WorldSystem::load(const std::string& file)
entity.assign<Wander>();
} else if (tname == "Hop" ) {
entity.assign<Hop>();
+ } else if (tname == "Aggro" ) {
+ entity.assign<Aggro>(abcd->Attribute("arena"));
} else if (tname == "Animation") {
auto entan = entity.assign<Animate>();
auto animx = abcd->FirstChildElement();