]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
important textls
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 28 Apr 2017 01:28:33 +0000 (21:28 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 28 Apr 2017 01:28:33 +0000 (21:28 -0400)
assets/music/town.ogg [new file with mode: 0644]
include/components.hpp
include/ui.hpp
main.cpp
src/components.cpp
src/ui.cpp
src/world.cpp
xml/!town.xml
xml/entities.xml

diff --git a/assets/music/town.ogg b/assets/music/town.ogg
new file mode 100644 (file)
index 0000000..0cbe3a7
Binary files /dev/null and b/assets/music/town.ogg differ
index dafb859b3d8248bbfbba448712458aa96d56b4ab..87d4293fbb1ef3ae09714644094a637ab5b08291 100644 (file)
@@ -623,6 +623,22 @@ struct Hit : public Component {
        }
 };
 
+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
  */
index 456c88aed8e827f40ebf0571af0d774774293741..3f0a67ff8b080f7ea68937917fa72e78ff67262c 100644 (file)
@@ -126,6 +126,8 @@ namespace ui {
         */
 
        void takeScreenshot(GLubyte *pixels);
+
+       bool handleGLEvent(SDL_Event& e);
 }
 
 #endif // UI_HPP_
index 967050ced5ade29ccf5d304ae0bc55cb2bc057eb..a934b4041aa623a8d9d6f5248c88b4fd01133e76 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -166,8 +166,10 @@ int main(int argc, char *argv[])
                        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
index d89e195eb90a5eeb705f04429f8afff2758dfe24..dcb1551141baee2911db710ec167630ce84db292 100644 (file)
@@ -50,11 +50,9 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                                        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);
@@ -64,9 +62,27 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                                                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) {
index fc815f235bee76c438d7e4b727dd5d9cbef38619..d14b0a6a49f1d041f1477d3be045998f975e7788 100644 (file)
@@ -618,6 +618,20 @@ namespace ui {
 
                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;
@@ -658,8 +672,6 @@ void InputSystem::receive(const MainSDLEvent& event)
        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();
@@ -974,6 +986,10 @@ void UISystem::render(void)
        }
 
        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);
        }
 }
index 648507a03ad382274e7c1a49a8e32999d48fb1a7..e25170670177d777591db25a39a487ee205c446b 100644 (file)
@@ -389,6 +389,8 @@ void WorldSystem::load(const std::string& file)
                                                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();
                                }
index e3fb946119bef2d65518d204d690f676329e966d..32f696a0f3bd30ad7b40901372f14fcadac0067a 100644 (file)
@@ -2,7 +2,7 @@
 <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"/>
index a1b5f5cb7143bf10b91b659aea3b20eb17a268cf..c557361ab8f4e45499c2a603a101e607a01e19bf 100644 (file)
@@ -67,6 +67,8 @@
        <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>