}
};
+struct Trigger : public Component {
+ Trigger(const std::string& t)
+ : text(t) {}
+ Trigger(XMLElement* imp, XMLElement* def) {
+ fromXML(imp, def);
+ }
+
+ std::string text;
+
+ void fromXML(XMLElement* imp, XMLElement* def) final {
+ (void)imp;
+ (void)def;
+ text = "You got me!";
+ }
+};
+
/**
* SYSTEMS
*/
*/
void takeScreenshot(GLubyte *pixels);
+
+ bool handleGLEvent(SDL_Event& e);
}
#endif // UI_HPP_
Render::render(fps);
SDL_Event e;
- while (SDL_PollEvent(&e))
+ while (SDL_PollEvent(&e)) {
+ ui::handleGLEvent(e);
eventQueue.push_back(e);
+ }
}
// on game end, get back together
fl = (direction.x < 0);
}
- // make the entity wander
- // TODO initialX and range?
- 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) {
+ auto ppos = game::engine.getSystem<PlayerSystem>()->getPosition();
+ if (ppos.x > position.x && ppos.x < position.x + entity.component<Solid>()->width) {
+ if (entity.has_component<Aggro>()) {
auto dim = entity.component<Solid>();
ev.emit<AttackEvent>(vec2(position.x + dim->width, position.y + dim->height),
AttackType::ShortSlash, false);
toFight = entity;
h = 0;
}*/
- } else
- direction.x = (ppos.x > position.x) ? .01 : -.01;
- } else if (entity.has_component<Wander>()) {
+ } else if (entity.has_component<Trigger>()) {
+ static bool triggering = false;
+ if (!triggering) {
+ triggering = true;
+ std::thread([&](entityx::Entity e) {
+ UISystem::fadeToggle();
+ UISystem::waitForCover();
+ UISystem::dialogImportant(e.component<Trigger>()->text);
+ UISystem::waitForDialog();
+ UISystem::fadeToggle();
+ e.destroy();
+ triggering = false;
+ }, entity).detach();
+ }
+ return;
+ }
+ }
+
+ // make the entity wander
+ // TODO initialX and range?
+ if (entity.has_component<Wander>()) {
auto& countdown = entity.component<Wander>()->countdown;
if (countdown > 0) {
fclose(bmp);
}
+
+ bool handleGLEvent(SDL_Event& e) {
+ switch (e.type) {
+ case SDL_MOUSEBUTTONDOWN:
+ if ((UISystem::isDialog() | pageTexReady) && (e.button.button & SDL_BUTTON_RIGHT))
+ UISystem::advanceDialog();
+ return true;
+ break;
+ default:
+ break;
+ }
+
+ return false;
+ }
}
using namespace ui;
case SDL_MOUSEBUTTONDOWN:
ev.emit<MouseClickEvent>(mouse, e.button.button);
- UISystem::advanceDialog();
-
if (UISystem::isDialog() || pageTexReady) {
if ((e.button.button & SDL_BUTTON_RIGHT))
UISystem::advanceDialog();
}
if (!importantText.empty()) {
- putStringCentered(offset, importantText);
+ FontSystem::setFontSize(24);
+ FontSystem::setFontZ(-9.0f);
+ putStringCentered(vec2(offset.x, 400), importantText);
+ FontSystem::setFontZ(-6.0f);
+ FontSystem::setFontSize(16);
}
}
entity.assign<Aggro>(wxml, abcd);
else if (tname == "Animation")
entity.assign<Animate>(wxml, abcd);
+ else if (tname == "Trigger")
+ entity.assign<Trigger>(wxml, abcd);
abcd = abcd->NextSiblingElement();
}
<include file="entities.xml"/>
<World>
- <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
+ <style background="0" bgm="assets/music/town.ogg" folder="assets/style/classic/"/>
<generation width="320"/>
<weather>Sunny</weather>
<link right="!town2.xml"/>
<Physics />
<Name value="SKIRL" />
<Wander />
+ <!--<Aggro arena="arena.xml" />-->
+ <Trigger />
</skirl>
<structure>
<Solid />
<Grounded />
</chest>
+
+<trigger>
+ <Position value="200.0,100.0" />
+ <Direction />
+ <Solid value="1.0,1.0" />
+ <Trigger />
+</trigger>