all: SPECIAL:=-ggdb game
-release: SPECIAL = -static
-release: LIBS += -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid
-release: game
-
game: $(EXEC)
clean:
int countdown;
};
+/**
+ * Causes the entity to get mad at the player, charge and fight.
+ */
+struct Aggro {
+ Aggro(const std::string& a)
+ : arena(a) {}
+
+ std::string arena;
+};
+
/**
* SYSTEMS
*/
#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>
// 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) {
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;
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;
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);
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);
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;
// 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
// 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] = {
#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)
{
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:");
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();
<npc name="Bob" hasDialog="true" position="50.0,100.0"/>
<structure type="1" position="300.0,100.0"/>
<structure inside="bobshouse.xml" type="1" position="10.0,100.0"/>
+ <skirl />
</World>
<Dialog name="Bob">
<text id="0" nextid="1" pause="true">
- <give id="Dank MayMay" count="10"/>
+ <give name="Dank MayMay" count="10"/>
<content>
Hey there! The name's Bob. Good to see you've finally woken up from your nap by the cliff there... lol
</content>
</text>
<text id="1" pause="true">
- <quest assign="Check out m'swag, man!" desc="Go inside Bob's house and check out the stuff he has."/>
+ <quest assign="Check out m'swag, man!" desc="Go inside Bob's house and check out the stuff he has.">
+ Debug, 5
+ </quest>
<content>
Looks like you've got yourself pretty empty handed... you know, I have a simple solution for that. Come on inside, I have somethin' to show you.
</content>
<Wander />
</npc>
+<skirl>
+ <Position value="300.0,100.0" />
+ <Visible value="0.2" />
+ <Sprite>
+ <frame>
+ <src limb="0" offset="0,0" size="48,24" drawOffset="0,0">assets/skirl.png</src>
+ </frame>
+ </Sprite>
+ <Direction />
+ <Solid />
+ <Physics />
+ <Name value="SKIRL" />
+ <Wander />
+ <Aggro arena="bobshouse.xml" />
+</skirl>
+
<structure>
<Position value="0.0,100.0" />
<Visible value="0.25" />