]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
entity stop on talk
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 28 Nov 2016 13:42:05 +0000 (08:42 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 28 Nov 2016 13:42:05 +0000 (08:42 -0500)
include/components.hpp
include/window.hpp
src/components.cpp

index 367b8a3755f1e8038f87484e52be47e65c1d7994..be967c8be79c878b33f7922749f8bd720f834177 100644 (file)
@@ -234,10 +234,11 @@ struct Visible {
 
 struct Dialog {
        Dialog(int idx = 0)
-               : index(idx), rindex((idx == 9999) ? randGet() : idx) {}
+               : index(idx), rindex((idx == 9999) ? randGet() : idx), talking(false) {}
 
        int index;
        int rindex;
+       bool talking;
 };
 
 
index 55cbe1c8b23c33b425402c004adeb0d9493ba053..5cf05ea3f84e3e645065ea0f29e9fe0a2b5ff8fa 100644 (file)
@@ -1,3 +1,8 @@
+/**
+ * @file window.hpp
+ * Provides a system for handling the game's window.
+ */
+
 #ifndef WINDOW_HPP_
 #define WINDOW_HPP_
 
@@ -7,9 +12,22 @@
 
 #include <events.hpp>
 
+/**
+ * @class WindowSystem
+ * Contains everything needed to create and update a window, using SDL.
+ * Also handles window resizing (WIP) and screenshots (WIP).
+ */
 class WindowSystem : public entityx::System<WindowSystem>, public entityx::Receiver<WindowSystem>  {
 private:
+
+       /**
+        * SDL's object for the window.
+        */
     SDL_Window *window;
+
+       /**
+        * An OpenGL context, created when OpenGL is set up for use.
+        */
     SDL_GLContext glContext;
 
 public:
index d9b9b60a6118b0e9d5366f3817d47d71d3d427ca..28358bede5b924e578a8758bc2839b1e66e70ca0 100644 (file)
@@ -18,20 +18,24 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                position.x += direction.x * dt;
                position.y += direction.y * dt;
 
-               if (entity.has_component<Sprite>()) {
-                       auto& fl = entity.component<Sprite>()->faceLeft;
-                       if (direction.x != 0)
-                               fl = (direction.x < 0);
-               }
+               if (entity.has_component<Dialog>() && entity.component<Dialog>()->talking) {
+                       direction.x = 0;
+               } else {
+                       if (entity.has_component<Sprite>()) {
+                               auto& fl = entity.component<Sprite>()->faceLeft;
+                               if (direction.x != 0)
+                                       fl = (direction.x < 0);
+                       }
 
-               if (entity.has_component<Wander>()) {
-                       auto& countdown = entity.component<Wander>()->countdown;
+                       if (entity.has_component<Wander>()) {
+                               auto& countdown = entity.component<Wander>()->countdown;
 
-                       if (countdown > 0) {
-                               countdown--;
-                       } else {
-                               countdown = 5000 + randGet() % 10 * 100;
-                               direction.x = (randGet() % 3 - 1) * 0.02f;
+                               if (countdown > 0) {
+                                       countdown--;
+                               } else {
+                                       countdown = 5000 + randGet() % 10 * 100;
+                                       direction.x = (randGet() % 3 - 1) * 0.02f;
+                               }
                        }
                }
        });
@@ -152,6 +156,9 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog");
                                int newIndex;
 
+                               if (e.has_component<Direction>())
+                                       d.talking = true;
+
                                if (d.index == 9999) {
                                        ui::dialogBox(name.name, "", false, randomDialog[d.rindex % randomDialog.size()]);
                                        ui::waitForDialog();
@@ -170,7 +177,6 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                                game::briceUpdate();
                                        }
 
-
                                        auto cxml = exml->FirstChildElement("content");
                                        const char *content;
                                        if (cxml == nullptr) {
@@ -186,6 +192,8 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                        if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR)
                                                d.index = newIndex;
                                }
+
+                               d.talking = false;
                        }).detach();
 
                        }