]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
ui fixes, other stuff
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 27 Apr 2016 12:50:07 +0000 (08:50 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 27 Apr 2016 12:50:07 +0000 (08:50 -0400)
19 files changed:
Changelog
include/common.hpp
include/config.hpp
include/gametime.hpp
include/mob.hpp
include/threadpool.hpp [deleted file]
main.cpp
src/common.cpp
src/config.cpp
src/entities.cpp
src/gameplay.cpp [deleted file]
src/gametime.cpp
src/inventory.cpp
src/mob.cpp
src/threadpool.cpp [deleted file]
src/ui.cpp
src/ui_menu.cpp
src/world.cpp
xml/playerSpawnHill1.xml

index 2f6b9ce1abf2ae83701ba40919b4c88ffdcd420b..5e967269edc75b09f0deb6d3a48acb83f082b238 100644 (file)
--- a/Changelog
+++ b/Changelog
 
        - fixed segfaults in inventory
        - Andy learned how to use GDB
-       - fixed 
+
+4/16/2016-
+4/27/2016:
+==========
+
+       - added action menu
+       - freakin rewrote half the code
+               - redid mobs, moved to separate file
+               - library-ized game time stuff
+               - made the game:: namespace
+               - removed threadpool, gameplay
+               - redoing inventory system
+       - added -g flag
index 5a0fcb26d5522ae2cfb8b7ff2868ff6d2ae811dc..1f7b9fc44cabffcd9f1ca97747ff3d6906280268 100644 (file)
@@ -18,8 +18,7 @@
 #include <thread>
 #include <mutex>
 #include <future>
-#include <math.h>
-#include <threadpool.hpp>
+#include <cmath>
 #include <algorithm>
 
 #define GLEW_STATIC
@@ -153,19 +152,6 @@ typedef col Color;
 
 #define GAME_NAME              "Independent Study v0.7 alpha - NOW WITH lights and snow and stuff"
 
-/**
- * The desired width of the game window.
- */
-
-extern unsigned int SCREEN_WIDTH;
-
-/**
- * The desired height of the game window.
- */
-
-extern unsigned int SCREEN_HEIGHT;
-
-extern bool FULLSCREEN;
 extern bool uiLoop;
 extern std::mutex mtx;
 
@@ -179,13 +165,8 @@ extern std::mutex mtx;
  *
  */
 
-#define HLINES(n) (HLINE * n)
-
-extern unsigned int HLINE;
+#define HLINES(n) (game::HLINE * n)
 
-extern float VOLUME_MASTER;
-extern float VOLUME_MUSIC;
-extern float VOLUME_SFX;
 /**
  * A 'wrapper' for libc's srand(), as we hope to eventually have our own random number
  * generator.
index 8bd0bc9f1c71d6c7483c709cae8a769157c57721..bc9d0525ed84d9d04393387451d7572c3905cf45 100644 (file)
@@ -1,18 +1,25 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
-#include <iostream>
+#include <string>
 
-#include <SDL2/SDL_mixer.h>
+namespace game {
+       extern unsigned int HLINE;
+       extern unsigned int SCREEN_WIDTH;
+       extern unsigned int SCREEN_HEIGHT;
+       extern bool         FULLSCREEN;
 
-#include <tinyxml2.h>
-#include <ui.hpp>
+       namespace config {
+               extern float VOLUME_MASTER;
+               extern float VOLUME_MUSIC;
+               extern float VOLUME_SFX;
 
-
-namespace config {
-    void read(void);
-    void update(void);
-    void save(void);
+               extern std::string xmlFolder;
+               
+               void read(void);
+               void update(void);
+               void save(void);
+       }
 }
 
 #endif //CONFIG_H
index c2991d20f8fba2af44e1e50eb9b7d626b17d9bd6..a809ef9ea9852be0b33e8f5e5970451f11c4fd0e 100644 (file)
@@ -1,16 +1,18 @@
 #ifndef GAMETIME_H_
 #define GAMETIME_H_
 
-namespace gtime {
-    void setTickCount(unsigned int t);
-    unsigned int getTickCount(void);
-    unsigned int getDeltaTime(void);
+namespace game {
+    namespace time {
+        void setTickCount(unsigned int t);
+        unsigned int getTickCount(void);
+        unsigned int getDeltaTime(void);
 
-    void tick(void);
-    void tick(unsigned int ticks);
-    bool tickHasPassed(void);
+        void tick(void);
+        void tick(unsigned int ticks);
+        bool tickHasPassed(void);
 
-    void mainLoopHandler(void);
+        void mainLoopHandler(void);
+    }
 }
 
 #endif // GAMETIME_H_
index 0ed6bc196c4e4801ce3afcc57d9b5f1949679e09..9f006b950c1916743e8c4006654447298707671b 100644 (file)
@@ -76,6 +76,7 @@ public:
 class Trigger : public Mob {
 private:
     std::string id;
+    bool triggered;
 public:
     Trigger(void);
 
diff --git a/include/threadpool.hpp b/include/threadpool.hpp
deleted file mode 100644 (file)
index c341673..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef THREADPOOL_H
-#define THREADPOOL_H
-
-#include <vector>
-#include <queue>
-#include <thread>
-#include <mutex>
-#include <condition_variable>
-#include <iostream>
-#include <unistd.h>
-
-using namespace std;
-
-class ThreadPool
-{
-public:
-
-    // Constructor.
-    ThreadPool(int threads);
-
-    // Destructor.
-    ~ThreadPool();
-
-    // Adds task to a task queue.
-    void Enqueue(function<void()> f);
-
-    // Shut down the pool.
-    void ShutDown();
-
-private:
-    // Thread pool storage.
-    vector<thread> threadPool;
-
-    // Queue to keep track of incoming tasks.
-    queue<function<void()>> tasks;
-
-    // Task queue mutex.
-    mutex tasksMutex;
-
-    // Condition variable.
-    condition_variable condition;
-
-    // Indicates that pool needs to be shut down.
-    bool terminate;
-
-    // Indicates that pool has been terminated.
-    bool stopped;
-
-    // Function that will be invoked by our threads.
-    void Invoke();
-};
-
-#endif //THRE
\ No newline at end of file
index 1753c86be63207b66122f3ca97335c0da8b5b3e6..cd16389f8f03d1f0a8ffbffb83be3c72ecf69688 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,15 +1,16 @@
-/*! @file main.cpp
- *     @brief The file that links everything together for the game to run.
- *     The  main game loop contains all of the global variables the game uses, and it runs the main game loop, the render loop, and the logic loop that control all of the entities.
- */
-
+/* ----------------------------------------------------------------------------
+** The main file, home of the main loop.
+** --------------------------------------------------------------------------*/
+// ...
+/* ----------------------------------------------------------------------------
+** Includes section
+** --------------------------------------------------------------------------*/
+
+// local library includes
 #include <tinyxml2.h>
 using namespace tinyxml2;
 
-/*
- * Game includes
- */
-
+// local game includes
 #include <common.hpp>
 #include <config.hpp>
 #include <entities.hpp>
@@ -17,107 +18,58 @@ using namespace tinyxml2;
 #include <ui.hpp>
 #include <gametime.hpp>
 
+/* ----------------------------------------------------------------------------
+** Variables section
+** --------------------------------------------------------------------------*/
+
+// the current weather, declared in world.cpp
+extern WorldWeather weather;
+
 // SDL's window object
 SDL_Window *window = NULL;
 
 // main loop runs based on this variable's value
-bool gameRunning;
+bool gameRunning = false;
 
 // world objects for the current world and the two that are adjacent
 World *currentWorld        = NULL,
          *currentWorldToLeft  = NULL,
          *currentWorldToRight = NULL;
 
+// the currently used folder to grab XML files
+std::string xmlFolder;
+
+// the current menu
 Menu *currentMenu;
 
 // the player object
 Player *player;
 
-/**
- * TODO
- */
+// shaders for rendering
 GLuint fragShader;
-
-/**
- * TODO
- */
 GLuint shaderProgram;
 
-/**
- *     Threads and various variables to be used when multithreading the game,
- *  mutex will prevent multiple threads from changing the same data,
- *  and the condition_variable will wait for threads to reach the same point
- */
-std::mutex mtx;
-std::condition_variable cv;
-ThreadPool pool(10);
-
-/**
- * TODO
- */
+// keeps a simple palette of colors for single-color draws
 GLuint colorIndex;
 
-/**
- * TODO
- */
+// the mouse's texture
 GLuint mouseTex;
 
-/**
- * Used for texture animation. It is externally referenced by ui.cpp
- * and entities.cpp.
- */
-unsigned int loops = 0;
-
-/**
- * Gives a coordinate based off of the player's location to allow for drawing to
- * be in a constant 'absolute' place on the window.
- */
-
+// the center of the screen
 vec2 offset;
 
-std::string xmlFolder;
-
-extern WorldWeather weather;
-
-unsigned int SCREEN_WIDTH;
-unsigned int SCREEN_HEIGHT;
-unsigned int HLINE;
-bool FULLSCREEN;
-
-float VOLUME_MASTER;
-float VOLUME_MUSIC;
-float VOLUME_SFX;
-
-/**
- * Defined in gameplay.cpp, should result in `currentWorld` containing a pointer
- * to a valid World.
- */
-
-extern void initEverything(void);
-
-/**
- * The game logic function, should handle all logic-related operations for the
- * game.
- */
-
+// handles all logic operations
 void logic(void);
 
-/**
- * The game render function, should handle all drawing to the window.
- */
-
+// handles all rendering operations
 void render(void);
 
-/**
- * The main loop, calls logic(), render(), and does timing operations in the
- * appropriate order.
- */
-
+// takes care of *everything*
 void mainLoop(void);
 
 /*******************************************************************************
- * MAIN ************************************************************************
- *******************************************************************************/
+** MAIN ************************************************************************
+********************************************************************************/
 
 int main(int argc, char *argv[]){
        (void)argc;
@@ -125,148 +77,73 @@ int main(int argc, char *argv[]){
 
        static SDL_GLContext mainGLContext = NULL;
 
-       gameRunning = false;
-
-       /**
-        * (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
-        * make openGL calls. Exit if there was an error.
-        */
-
-       if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0){
-               std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl;
-               return -1;
-       }
+       // attempt to initialize SDL
+       if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
+               UserError(std::string("SDL was not able to initialize! Error: ") + SDL_GetError());
+       atexit(SDL_Quit);
 
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
 
-       // Run SDL_Quit when main returns
-       atexit(SDL_Quit);
-
-       /**
-        * (Attempt to) Initialize SDL_image libraries with IMG_INIT_PNG so that we can load PNG
-        * textures for the entities and stuff.
-        */
-
-       if(!(IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG) & (IMG_INIT_PNG | IMG_INIT_JPG))){
-               std::cout << "Could not init image libraries! Error: " << IMG_GetError() << std::endl;
-               return -1;
-       }
-
-       // Run IMG_Quit when main returns
+       // attempt to initialize SDL_image
+       if (!(IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG) & (IMG_INIT_PNG | IMG_INIT_JPG)))
+               UserError(std::string("Could not init image libraries! Error: ") + IMG_GetError());
        atexit(IMG_Quit);
 
-       /**
-        * (Attempt to) Initialize SDL_mixer libraries for loading and playing music/sound files.
-        */
-
-       if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0){
-               std::cout << "SDL_mixer could not initialize! Error: " << Mix_GetError() << std::endl;
-               return -1;
-       }
-
+       // attempt to initialize SDL_mixer
+       if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
+               UserError(std::string("SDL_mixer could not initialize! Error: ") + Mix_GetError());
        Mix_AllocateChannels(8);
-
-       config::update();
-
-       // Run Mix_Quit when main returns
        atexit(Mix_Quit);
 
-       /**
-        * Load saved settings into the game (see config/settings.xml)
-        */
-
-       config::read();
-
-       /*
-        *      Create a window for SDL to draw to. Most parameters are the default, except for the
-        *      following which are defined in include/common.h:
-        *
-        *      GAME_NAME               the name of the game that is displayed in the window title bar
-        *      SCREEN_WIDTH    the width of the created window
-        *      SCREEN_HEIGHT   the height of the created window
-        *      FULLSCREEN              makes the window fullscreen
-        *
-        */
-
-       uint32_t SDL_CreateWindowFlags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | (FULLSCREEN ? SDL_WINDOW_FULLSCREEN : 0);
+       // update values by reading the config file (config/settings.xml)
+       game::config::update();
+       game::config::read();
 
+       // create the SDL window object
        window = SDL_CreateWindow(GAME_NAME,
                                                          SDL_WINDOWPOS_UNDEFINED,      // Spawn the window at random (undefined) x and y coordinates
                                                          SDL_WINDOWPOS_UNDEFINED,      //
-                                                         SCREEN_WIDTH,
-                                                         SCREEN_HEIGHT,
-                                                         SDL_CreateWindowFlags
-                                                        );
-
-    /*
-     * Exit if the window cannot be created
-     */
-
-    if(window==NULL){
-               std::cout << "The window failed to generate! SDL_Error: " << SDL_GetError() << std::endl;
-        return -1;
-    }
-
-    /*
-     * Create the SDL OpenGL context. Once created, we are allowed to use OpenGL functions.
-     * Saving this context to mainGLContext does not appear to be necessary as mainGLContext
-     * is never referenced again.
-     */
-
-    if((mainGLContext = SDL_GL_CreateContext(window)) == NULL){
-               std::cout << "The OpenGL context failed to initialize! SDL_Error: " << SDL_GetError() << std::endl;
-        return -1;
-    }
+                                                         game::SCREEN_WIDTH,
+                                                         game::SCREEN_HEIGHT,
+                                                         SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | (game::FULLSCREEN ? SDL_WINDOW_FULLSCREEN : 0)
+                                                         );
 
-       /*
-        * Initialize GLEW libraries, and exit if there was an error.
-        * Not sure what they're for yet.
-        */
+    if (window == NULL)
+               UserError(std::string("The window failed to generate! SDL_Error: ") + SDL_GetError());
 
-       GLenum err;
+    // create the OpenGL object that SDL provides
+    if ((mainGLContext = SDL_GL_CreateContext(window)) == NULL)
+               UserError(std::string("The OpenGL context failed to initialize! SDL_Error: ") + SDL_GetError());
+
+       // initialize GLEW
 #ifndef __WIN32__
        glewExperimental = GL_TRUE;
 #endif
-       if((err=glewInit()) != GLEW_OK){
-               std::cout << "GLEW was not able to initialize! Error: " << glewGetErrorString(err) << std::endl;
-               return -1;
-       }
 
-       /*
-        * Initialize the random number generator. At the moment, initRand is a macro pointing to libc's
-        * srand, and its partner getRand points to rand. This is because having our own random number
-        * generator may be favorable in the future, but at the moment is not implemented.
-        */
+       GLenum err;
+       if ((err = glewInit()) != GLEW_OK)
+               UserError(std::string("GLEW was not able to initialize! Error: ") + reinterpret_cast<const char *>(glewGetErrorString(err)));
 
+       // start the random number generator
        initRand(millis());
 
-       /*
-        * Do some basic setup for openGL. Enable double buffering, switch to by-pixel coordinates,
-        * setup the alpha channel for textures/transparency, and finally hide the system's mouse
-        * cursor so that we may draw our own.
-        */
-
+       // 'basic' OpenGL setup
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-       SDL_GL_SetSwapInterval(0);
-
-       glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
-
+       SDL_GL_SetSwapInterval(0); // v-sync
+       SDL_ShowCursor(SDL_DISABLE); // hide the mouse
+       glViewport(0, 0, game::SCREEN_WIDTH, game::SCREEN_HEIGHT);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glClearColor(1,1,1,1);
 
-       SDL_ShowCursor(SDL_DISABLE);
-
+       // TODO
        Texture::initColorIndex();
 
-       /*
-        * Initializes our shaders so that the game has shadows.
-        */
-
-       std::cout << "Initializing shaders!" << std::endl;
+       // initialize shaders
+       std::cout << "Initializing shaders!\n";
 
        const GLchar *shaderSource = readFile("frig.frag");
-
        GLint bufferln = GL_FALSE;
        int logLength;
 
@@ -300,52 +177,46 @@ int main(int argc, char *argv[]){
 
        glEnable(GL_MULTISAMPLE);
 
-       /*
-        * Create all the worlds, entities, mobs, and the player. This function is defined in
-        * src/gameplay.cpp
-        */
-
-       initEverything();
-
-       if(!currentWorld){
-               std::cout<<"currentWorld == NULL!"<<std::endl;
-#ifndef __WIN32__
-               system("systemctl poweroff");
-#else
-               system("shutdown -s -t 0");
-#endif // __WIN32__
-               abort();
+       // read in all XML file names in the folder
+       std::vector<std::string> xmlFiles;
+       if (xmlFolder.empty())
+               xmlFolder = "xml/";
+       if (getdir(std::string("./" + xmlFolder).c_str(), xmlFiles))
+               UserError("Error reading XML files!!!");
+
+       // alphabetically sort files
+       strVectorSortAlpha(&xmlFiles);
+
+       // load the first valid XML file for the world
+       for (xf : xmlFiles) {
+               if (xf[0] != '.' && strcmp(&xf[xf.size() - 3], "dat")){
+                       // read it in
+                       std::cout << "File to load: " << xf << '\n';
+                       currentWorld = loadWorldFromXML(xf);
+                       break;
+               }
        }
 
-       /*
-        * Load sprites used in the inventory menu. See src/inventory.cpp
-        */
+       // spawn the player
+       player = new Player();
+       player->sspawn(0,100);
+       ui::menu::init();
+       currentWorld->bgmPlay(NULL);
 
-       mouseTex = Texture::loadTexture("assets/mouse.png");
+       // make sure the world was made
+       if (currentWorld == NULL)
+               UserError("Plot twist: The world never existed...?");
 
+       // load mouse texture, and other inventory textures
+       mouseTex = Texture::loadTexture("assets/mouse.png");
        initInventorySprites();
 
-       /**************************
-       ****     GAMELOOP      ****
-       **************************/
-
-       std::cout << "Num threads: " << std::thread::hardware_concurrency() << std::endl;
-
-       glClearColor(1,1,1,1);
-       //ui::toggleBlackFast();
-
+       // the main loop, in all of its gloriousness..
        gameRunning = true;
        while (gameRunning)
                mainLoop();
 
-       /**************************
-       ****   CLOSE PROGRAM   ****
-       **************************/
-
-    /*
-     * Close the window and free resources
-     */
-
+    // free library resources
     Mix_HaltMusic();
     Mix_CloseAudio();
 
@@ -356,6 +227,12 @@ int main(int argc, char *argv[]){
     SDL_GL_DeleteContext(mainGLContext);
     SDL_DestroyWindow(window);
 
+       // close up the game stuff
+       currentWorld->save();
+       //delete currentWorld;
+       //delete[] currentXML;
+       //aipreload.clear();
+
     return 0; // Calls everything passed to atexit
 }
 
@@ -372,7 +249,7 @@ void mainLoop(void){
        static unsigned int debugDiv=0;                 // A divisor used to update the debug menu if it's open
        World *prev;
 
-       gtime::mainLoopHandler();
+       game::time::mainLoopHandler();
 
        if (currentMenu)
                goto MENU;
@@ -386,16 +263,16 @@ void mainLoop(void){
                ui::dialogBoxExists = false;
        }
 
-       if (gtime::tickHasPassed())
+       if (game::time::tickHasPassed())
                logic();
 
-       currentWorld->update(player, gtime::getDeltaTime());
+       currentWorld->update(player, game::time::getDeltaTime());
        currentWorld->detect(player);
 
        if (++debugDiv == 20) {
                debugDiv=0;
 
-               fps = 1000 / gtime::getDeltaTime();
+               fps = 1000 / game::time::getDeltaTime();
                if (!(debugDiv % 10))
                        debugY = player->loc.y;
        }
@@ -404,74 +281,33 @@ MENU:
 }
 
 void render() {
+       auto SCREEN_WIDTH = game::SCREEN_WIDTH;
+       auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
 
-        /*
-         *     This offset variable is what we use to move the camera and locked
-         *     objects on the screen so they always appear to be in the same relative area
-         */
-
+       // offset should contain the coordinates of the center of the player's view
        offset.x = player->loc.x + player->width/2;
        offset.y = SCREEN_HEIGHT/2;
 
-       /*
-        * If the camera will go off of the left  or right of the screen we want to lock it so we can't
-        * see past the world render
-        */
-
-       if(currentWorld->getTheWidth() < (int)SCREEN_WIDTH){
+       // snap the player's view if we're at a world edge
+       if (currentWorld->getTheWidth() < (int)SCREEN_WIDTH) {
                offset.x = 0;
-       }else{
-               if(player->loc.x - SCREEN_WIDTH/2 < currentWorld->getTheWidth() * -0.5f)
+       } else {
+               if (player->loc.x - SCREEN_WIDTH/2 < currentWorld->getTheWidth() * -0.5f)
                        offset.x = ((currentWorld->getTheWidth() * -0.5f) + SCREEN_WIDTH / 2) + player->width / 2;
-               if(player->loc.x + player->width + SCREEN_WIDTH/2 > currentWorld->getTheWidth() *  0.5f)
+               if (player->loc.x + player->width + SCREEN_WIDTH/2 > currentWorld->getTheWidth() *  0.5f)
                        offset.x = ((currentWorld->getTheWidth() *  0.5f) - SCREEN_WIDTH / 2) - player->width / 2;
        }
 
        if(player->loc.y > SCREEN_HEIGHT/2)
                offset.y = player->loc.y + player->height;
 
-       /*
-        *      These functions run everyloop to update the current stacks presets
-        *
-        *      Matrix  ----    A matrix is a blank "canvas" for the renderer to draw on,
-        *                                      this canvas can be rotated, scales, skewed, etc..
-        *
-        *      Stack   ----    A stack is exactly what it sounds like, it is a stack.. A
-        *                                      stack is a "stack" of matrices for the renderer to draw on.
-        *                                      Each stack can be made up of varying amounts of matricies.
-        *
-        *      glMatrixMode    This changes our current stacks mode so the drawings below
-        *                                      it can take on certain traits.
-        *
-        *      GL_PROJECTION   This is the matrix mode that sets the cameras position,
-        *                                      GL_PROJECTION is made up of a stack with two matrices which
-        *                                      means we can make up to 2 seperate changes to the camera.
-        *
-        *      GL_MODELVIEW    This matrix mode is set to have the dimensions defined above
-        *                                      by GL_PROJECTION so the renderer can draw only what the camera
-        *                                      is looking at. GL_MODELVIEW has a total of 32 matrices on it's
-        *                                      stack, so this way we can make up to 32 matrix changes like,
-        *                                      scaling, rotating, translating, or flipping.
-        *
-        *      glOrtho                 glOrtho sets our ortho, or our cameras resolution. This can also
-        *                                      be used to set the position of the camera on the x and y axis
-        *                                      like we have done. The glOrtho must be set while the stack is in
-        *                                      GL_PROJECTION mode, as this is the mode that gives the
-        *                                      camera properties.
-        *
-        *      glPushMatrix    This creates a "new" matrix. What it really does is pull a matrix
-        *                                      off the bottom of the stack and puts it on the top so the renderer
-        *                                      can draw on it.
-        *
-        *      glLoadIdentity  This scales the current matrix back to the origin so the
-        *                                      translations are seen normally on a stack.
-        */
-
+       // "setup"
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
-       // glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),(offset.y-SCREEN_HEIGHT/2),(offset.y+SCREEN_HEIGHT/2),-1,1);
-       glOrtho(floor(offset.x-SCREEN_WIDTH/2),floor(offset.x+SCREEN_WIDTH/2),floor(offset.y-SCREEN_HEIGHT/2),floor(offset.y+SCREEN_HEIGHT/2),20,-20);
+       glOrtho(floor(offset.x - SCREEN_WIDTH  / 2), floor(offset.x + SCREEN_WIDTH  / 2),
+               floor(offset.y - SCREEN_HEIGHT / 2), floor(offset.y + SCREEN_HEIGHT / 2),
+                       20, -20);
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();
@@ -490,35 +326,17 @@ void render() {
        glPushAttrib(GL_DEPTH_BUFFER_BIT);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-       /**************************
-       **** RENDER STUFF HERE ****
-       **************************/
-
-       /*
-        * Call the world's draw function, drawing the player, the world, the background, and entities. Also
-        * draw the player's inventory if it exists.
-        */
-
-       player->near=true;                      // Draw the player's name
-
+       // draw the world
+       player->near = true; // allow player's name to be drawn
        currentWorld->draw(player);
 
-       /*
-        * Draw the player's inventory.
-        */
-
+       // draw the player's inventory
        player->inv->draw();
 
-       /*
-        * Here we draw a black overlay if it's been requested.
-        */
-
+       // draw the fade overlay
        ui::drawFade();
 
-       /*
-        * Draw UI elements. This includes the player's health bar and the dialog box.
-        */
-
+       // draw ui elements
        ui::draw();
 
        /*
@@ -526,9 +344,7 @@ void render() {
         */
 
        if(ui::debug){
-
-               ui::putText(offset.x-SCREEN_WIDTH/2,
-                                       (offset.y+SCREEN_HEIGHT/2)-ui::fontSize,
+               ui::putText(offset.x-SCREEN_WIDTH/2, (offset.y+SCREEN_HEIGHT/2)-ui::fontSize,
                                        "fps: %d\ngrounded:%d\nresolution: %ux%u\nentity cnt: %d\nloc: (%+.2f, %+.2f)\nticks: %u\nvolume: %f\nweather: %s",
                                        fps,
                                        player->ground,
@@ -537,35 +353,20 @@ void render() {
                                        currentWorld->entity.size(),// Size of entity array
                                        player->loc.x,                          // The player's x coordinate
                                        debugY,                                         // The player's y coordinate
-                                       gtime::getTickCount(),
-                                       VOLUME_MASTER,
+                                       game::time::getTickCount(),
+                                       game::config::VOLUME_MASTER,
                                        getWorldWeatherStr(weather).c_str()
                                        );
 
                if (ui::posFlag) {
                        glBegin(GL_LINES);
-                               /*glColor3ub(255,0,0);
-                               glVertex2i(0,0);
-                               glVertexdw2i(0,SCREEN_HEIGHT);*/
-
-                               /*glColor3ub(255,255,255);
-                               glVertex2i(player->loc.x + player->width/2,0);
-                               glVertex2i(player->loc.x + player->width/2,SCREEN_HEIGHT);
-                               glVertex2i(offset.x - SCREEN_WIDTH / 2, player->loc.y + player->height / 2);
-                               glVertex2i(offset.x + SCREEN_WIDTH / 2, player->loc.y + player->height / 2);*/
-
-                               /*glVertex2i(-SCREEN_WIDTH / 2 + offset.x, player->loc.y);
-                               glVertex2i( SCREEN_WIDTH / 2 + offset.x, player->loc.y);*/
-
                                glColor3ub(100,100,255);
                                for (auto &e : currentWorld->entity) {
                                        glVertex2i(player->loc.x + player->width / 2, player->loc.y + player->height / 2);
                                        glVertex2i(e->loc.x + e->width / 2, e->loc.y + e->height / 2);
                                }
-
                        glEnd();
                }
-
        }
 
        if (currentMenu)
@@ -577,16 +378,13 @@ void render() {
        glBindTexture(GL_TEXTURE_2D, mouseTex);
        glBegin(GL_QUADS);
                glTexCoord2f(0,0);glVertex2i(ui::mouse.x                        ,ui::mouse.y                    );
-               glTexCoord2f(1,0);glVertex2i(ui::mouse.x+HLINE*5        ,ui::mouse.y                    );
-               glTexCoord2f(1,1);glVertex2i(ui::mouse.x+HLINE*5        ,ui::mouse.y-HLINE*5    );
-               glTexCoord2f(0,1);glVertex2i(ui::mouse.x                        ,ui::mouse.y-HLINE*5    );
+               glTexCoord2f(1,0);glVertex2i(ui::mouse.x+HLINES(5)      ,ui::mouse.y                    );
+               glTexCoord2f(1,1);glVertex2i(ui::mouse.x+HLINES(5)      ,ui::mouse.y-HLINES(5)  );
+               glTexCoord2f(0,1);glVertex2i(ui::mouse.x                        ,ui::mouse.y-HLINES(5)  );
        glEnd();
        glDisable(GL_TEXTURE_2D);
 
-       /**************************
-       ****  END RENDERING   ****
-       **************************/
-
+       // wrap up
        glPopMatrix();
        SDL_GL_SwapWindow(window);
 }
@@ -641,41 +439,28 @@ void logic(){
                }
        }
 
-       /*
-        *      Switch between day and night (SUNNY and DARK) if necessary.
-        */
-
-       if (!(gtime::getTickCount() % DAY_CYCLE) || !gtime::getTickCount()){
+       // switch from day to night?
+       auto tickCount = game::time::getTickCount();
+       if (!(tickCount % DAY_CYCLE) || !tickCount){
                if (weather == WorldWeather::Sunny)
                        weather = WorldWeather::Dark;
-               else {
+               else
                        weather = WorldWeather::Sunny;
-                       Mix_Pause(2);
-               }
        }
 
-       /*
-        *      Calculate an in-game shading value (as opposed to GLSL shading).
-       */
-
-       worldShade = 50 * sin((gtime::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
-
-       /*
-        *      Transition to and from black if necessary.
-       */
+       // calculate the world shading value
+       worldShade = 50 * sin((tickCount + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
 
+       // update fades
        ui::fadeUpdate();
 
-       /*
-        * Rain?
-        */
-
+       // create weather particles if necessary
         if (weather == WorldWeather::Rain) {
                 for (unsigned int r = (randGet() % 25) + 11; r--;) {
                         currentWorld->addParticle(randGet() % currentWorld->getTheWidth() - (currentWorld->getTheWidth() / 2),
-                                                                          offset.y + SCREEN_HEIGHT / 2,
-                                                                          HLINE * 1.25,                                                                                // width
-                                                                          HLINE * 1.25,                                                                                // height
+                                                                          offset.y + game::SCREEN_HEIGHT / 2,
+                                                                          HLINES(1.25),                                                                                // width
+                                                                          HLINES(1.25),                                                                                // height
                                                                           randGet() % 7 * .01 * (randGet() % 2 == 0 ? -1 : 1), // vel.x
                                                                           (4 + randGet() % 6) * .05,                                                   // vel.y
                                                                           { 0, 0, 255 },                                                                               // RGB color
@@ -686,9 +471,9 @@ void logic(){
         } else if (weather == WorldWeather::Snowy) {
                 for (unsigned int r = (randGet() % 25) + 11; r--;) {
                         currentWorld->addParticle(randGet() % currentWorld->getTheWidth() - (currentWorld->getTheWidth() / 2),
-                                                                          offset.y + SCREEN_HEIGHT / 2,
-                                                                          HLINE * 1.25,                                                                                // width
-                                                                          HLINE * 1.25,                                                                                // height
+                                                                          offset.y + game::SCREEN_HEIGHT / 2,
+                                                                          HLINES(1.25),                                                                                // width
+                                                                          HLINES(1.25),                                                                                // height
                                                        .0001 + randGet() % 7 * .01 * (randGet() % 2 == 0 ? -1 : 1),    // vel.x
                                                                           (4 + randGet() % 6) * -.03,                                                  // vel.y
                                                                           { 255, 255, 255 },                                                                   // RGB color
@@ -698,11 +483,8 @@ void logic(){
                 }
         }
 
-       /*
-        *      Increment a loop counter used for animating sprites.
-       */
-
-       loops++;
-       gtime::tick();
-       NPCSelected=false;      // See above
+       // increment game ticker
+       game::time::tick();
+       NPCSelected = false;
+       ObjectSelected = false;
 }
index 34b2a613812e070570cb8b6d6e9ee867bc49b8fb..c86454b60130487a8c941d324dd26e2efb67900a 100644 (file)
@@ -1,17 +1,15 @@
+#include <common.hpp>
+
 #include <cstring>
 #include <cstdio>
 #include <chrono>
 
 #ifndef __WIN32__
-#      include <sys/types.h>
-#      include <dirent.h>
-#      include <errno.h>
-#      include <vector>
-#endif // __WIN32__
 
-#include <common.hpp>
-
-#ifndef __WIN32__
+#include <sys/types.h>
+#include <dirent.h>
+#include <errno.h>
+#include <vector>
 
 unsigned int millis(void) {
        std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
@@ -20,37 +18,33 @@ unsigned int millis(void) {
 
 #endif // __WIN32__
 
-void DEBUG_prints(const char* file, int line, const char *s,...) {
+void DEBUG_prints(const char* file, int line, const char *s,...)
+{
        va_list args;
-       printf("%s:%d: ",file,line);
-       va_start(args,s);
-       vprintf(s,args);
+       printf("%s:%d: ", file, line);
+       va_start(args, s);
+       vprintf(s, args);
        va_end(args);
 }
 
-void safeSetColor(int r,int g,int b) { // safeSetColor() is an alternative to directly using glColor3ub() to set
-       if (r>255)r=255;                                                // the color for OpenGL drawing. safeSetColor() checks for values that are
-       if (g>255)g=255;                                                // outside the range of an unsigned character and sets them to a safer value.
-       if (b>255)b=255;
-       if (r<0)r=0;
-       if (g<0)g=0;
-       if (b<0)b=0;
-       glColor3ub(r,g,b);
+void safeSetColor(int r, int g, int b)
+{
+       r = static_cast<int>(fmax(fmin(r, 255), 0));
+       g = static_cast<int>(fmax(fmin(g, 255), 0));
+       b = static_cast<int>(fmax(fmin(b, 255), 0));
+       glColor3ub(r, g, b);
 }
 
 void safeSetColorA(int r,int g,int b,int a) {
-       if (r>255)r=255;
-       if (g>255)g=255;
-       if (b>255)b=255;
-       if (a>255)a=255;
-       if (r<0)r=0;
-       if (g<0)g=0;
-       if (b<0)b=0;
-       if (a<0)a=0;
-       glColor4ub(r,g,b,a);
+       r = static_cast<int>(fmax(fmin(r, 255), 0));
+       g = static_cast<int>(fmax(fmin(g, 255), 0));
+       b = static_cast<int>(fmax(fmin(b, 255), 0));
+       a = static_cast<int>(fmax(fmin(a, 255), 0));
+       glColor4ub(r, g, b, a);
 }
 
-int getdir(std::string dir, std::vector<std::string> &files) {
+int getdir(std::string dir, std::vector<std::string> &files)
+{
     DIR *dp;
     struct dirent *dirp;
     if (!(dp = opendir(dir.c_str()))) {
@@ -63,20 +57,22 @@ int getdir(std::string dir, std::vector<std::string> &files) {
     return 0;
 }
 
-void strVectorSortAlpha(std::vector<std::string> *v) {
+void strVectorSortAlpha(std::vector<std::string> *v)
+{
        static bool change;
-       do{
+       do {
                change = false;
-               for(unsigned int i=0;i<v->size()-1;i++) {
-                       if (v[0][i] > v[0][i+1]) {
-                               std::swap(v[0][i],v[0][i+1]);
+               for (unsigned int i=0; i < v->size() - 1; i++) {
+                       if (v[0][i] > v[0][i + 1]) {
+                               std::swap(v[0][i], v[0][i + 1]);
                                change = true;
                        }
                }
-       }while(change);
+       } while (change);
 }
 
-const char *readFile(const char *path) {
+const char *readFile(const char *path)
+{
        std::ifstream in (path,std::ios::in);
        unsigned int size;
        GLchar *buf;
@@ -94,9 +90,8 @@ const char *readFile(const char *path) {
        return buf;
 }
 
-void
-UserError(std::string reason)
+void UserError(std::string reason)
 {
-    std::cout << "User error: " << reason << "!" << std::endl;
+    std::cout << "User error: " << reason << "!\n";
     abort();
 }
index 752b365c1c3ce38113441d934986dffdb0f245b3..d18016ffaf028adce40ef9ae5feb7304a0e9077b 100644 (file)
@@ -2,82 +2,74 @@
 
 #include <ui.hpp>
 
-using namespace tinyxml2;
-
-extern unsigned int HLINE;
-extern unsigned int SCREEN_WIDTH;
-extern unsigned int SCREEN_HEIGHT;
-extern bool                    FULLSCREEN;
-
-extern float VOLUME_MASTER;
-extern float VOLUME_MUSIC;
-extern float VOLUME_SFX;
-
-extern std::string xmlFolder;
-
-XMLDocument xml;
-XMLElement *scr;
-XMLElement *vol;
-
-namespace config {
-
-       void read(void) {
-               unsigned int uval;
-               float fval;
-               bool bval;
-
-               xml.LoadFile("config/settings.xml");
-               scr = xml.FirstChildElement("screen");
-
-               if (scr->QueryUnsignedAttribute("width",&uval) == XML_NO_ERROR)
-                       SCREEN_WIDTH = uval;
-               else SCREEN_WIDTH = 1280;
-               if (scr->QueryUnsignedAttribute("height",&uval) == XML_NO_ERROR)
-                       SCREEN_HEIGHT = uval;
-               else SCREEN_HEIGHT = 800;
-               if (scr->QueryBoolAttribute("fullscreen",&bval) == XML_NO_ERROR)
-                       FULLSCREEN = bval;
-               else FULLSCREEN = false;
-               if (xml.FirstChildElement("hline")->QueryUnsignedAttribute("size",&uval) == XML_NO_ERROR)
-                       HLINE = uval;
-               else HLINE = 3;
-
-               vol = xml.FirstChildElement("volume");
-
-               if (vol->FirstChildElement("master")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
-                       VOLUME_MASTER = fval;
-               else VOLUME_MASTER = 50;
-               if (vol->FirstChildElement("music")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
-                       VOLUME_MUSIC = fval;
-               else VOLUME_MUSIC = 50;
-               if (vol->FirstChildElement("sfx")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
-                       VOLUME_SFX = fval;
-               else VOLUME_SFX = 50;
-
-               xmlFolder = xml.FirstChildElement("world")->Attribute("start");
-               if (xmlFolder=="\0")xmlFolder = "xml/";
-               std::cout << "Folder: " << xmlFolder << std::endl;
-
-               ui::initFonts();
-               ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
-
-               if (xml.FirstChildElement("debug"))
-                       ui::debug = ui::posFlag = true;
-
-               config::update();
-       }
+#include <SDL2/SDL_mixer.h>
 
-       void update(void) {
-               Mix_Volume(0,VOLUME_MASTER);
-               Mix_Volume(1,VOLUME_SFX * (VOLUME_MASTER/100.0f));
-               Mix_VolumeMusic(VOLUME_MUSIC * (VOLUME_MASTER/100.0f));
-       }
-
-       void save(void) {
-               vol->FirstChildElement("master")->SetAttribute("volume",VOLUME_MASTER);
-               vol->FirstChildElement("music")->SetAttribute("volume",VOLUME_MUSIC);
-               vol->FirstChildElement("sfx")->SetAttribute("volume", VOLUME_SFX);
+#include <tinyxml2.h>
+using namespace tinyxml2;
 
-               xml.SaveFile("config/settings.xml", false);
+namespace game {
+       unsigned int HLINE;
+       unsigned int SCREEN_WIDTH;
+       unsigned int SCREEN_HEIGHT;
+       bool         FULLSCREEN;
+
+       namespace config {
+               static XMLDocument xml;
+               static XMLElement *vol;
+
+               float VOLUME_MASTER;
+               float VOLUME_MUSIC;
+               float VOLUME_SFX;
+
+               std::string xmlFolder;
+
+               void read(void) {
+                       xml.LoadFile("config/settings.xml");
+                       auto exml = xml.FirstChildElement("screen");
+
+                       if (exml->QueryUnsignedAttribute("width", &SCREEN_WIDTH) != XML_NO_ERROR)
+                               SCREEN_WIDTH = 1024;
+                       if (exml->QueryUnsignedAttribute("height", &SCREEN_HEIGHT) != XML_NO_ERROR)
+                               SCREEN_HEIGHT = 768;
+                       if (exml->QueryBoolAttribute("fullscreen", &FULLSCREEN) != XML_NO_ERROR)
+                               FULLSCREEN = false;
+
+                       if (xml.FirstChildElement("hline")->QueryUnsignedAttribute("size", &HLINE) != XML_NO_ERROR)
+                               HLINE = 3;
+
+                       vol = exml = xml.FirstChildElement("volume");
+                       if (exml->FirstChildElement("master")->QueryFloatAttribute("volume", &VOLUME_MASTER) != XML_NO_ERROR)
+                               VOLUME_MASTER = 50;
+                       if (exml->FirstChildElement("music")->QueryFloatAttribute("volume", &VOLUME_MUSIC) != XML_NO_ERROR)
+                               VOLUME_MUSIC = 50;
+                       if (exml->FirstChildElement("sfx")->QueryFloatAttribute("volume", &VOLUME_SFX) != XML_NO_ERROR)
+                               VOLUME_SFX = 50;
+
+                       xmlFolder = xml.FirstChildElement("world")->StrAttribute("start");
+                       if (xmlFolder.empty())
+                               xmlFolder = "xml/";
+
+                       ui::initFonts();
+                       ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
+
+                       if (xml.FirstChildElement("debug"))
+                               ui::debug = ui::posFlag = true;
+
+                       config::update();
+               }
+
+               void update(void) {
+                       Mix_Volume(0, VOLUME_MASTER);
+                       Mix_Volume(1, VOLUME_SFX * (VOLUME_MASTER / 100.0f));
+                       Mix_VolumeMusic(VOLUME_MUSIC * (VOLUME_MASTER / 100.0f));
+               }
+
+               void save(void) {
+                       vol->FirstChildElement("master")->SetAttribute("volume", VOLUME_MASTER);
+                       vol->FirstChildElement("music")->SetAttribute("volume", VOLUME_MUSIC);
+                       vol->FirstChildElement("sfx")->SetAttribute("volume", VOLUME_SFX);
+
+                       xml.SaveFile("config/settings.xml", false);
+               }
        }
 }
index 6f94bc2564c94dd59e84b770aa21eb5f60a23d5a..ee26438d1871afdc7249c734deb588677308d482 100644 (file)
@@ -154,8 +154,8 @@ void Entity::moveTo(float dest_x)
 }
 
 Player::Player(){ //sets all of the player specific traits on object creation
-       width = HLINE * 10;
-       height = HLINE * 16;
+       width = HLINES(10);
+       height = HLINES(16);
 
        type = PLAYERT; //set type to player
        subtype = 0;
@@ -181,8 +181,8 @@ Player::~Player() {
 }
 
 NPC::NPC() {   //sets all of the NPC specific traits on object creation
-       width = HLINE * 10;
-       height = HLINE * 16;
+       width = HLINES(10);
+       height = HLINES(16);
 
        type    = NPCT; //sets type to npc
        subtype = 0;
@@ -207,8 +207,8 @@ NPC::~NPC()
 }
 
 Merchant::Merchant() { //sets all of the Merchant specific traits on object creation
-       width = HLINE * 10;
-       height = HLINE * 16;
+       width = HLINES(10);
+       height = HLINES(16);
 
        type    = MERCHT; //sets type to merchant
        subtype = 0;
@@ -304,7 +304,7 @@ void Object::reloadTexture(void) {
 }
 
 bool Entity::isNear(Entity e) {
-       return pow(e.loc.x - loc.x, 2) + pow(e.loc.y - loc.y, 2) <= pow(40 * HLINE, 2);
+       return pow(e.loc.x - loc.x, 2) + pow(e.loc.y - loc.y, 2) <= pow(HLINES(40), 2);
 }
 
 void NPC::drawThingy(void) const
@@ -342,7 +342,7 @@ void Entity::draw(void)
        switch(type) {
        case PLAYERT:
                static int texState = 0;
-               if (speed && !(loops % ((2.0f/speed) < 1 ? 1 : (int)((float)2.0f/(float)speed)))) {
+               if (speed && !(game::time::getTickCount() % ((2.0f/speed) < 1 ? 1 : (int)((float)2.0f/(float)speed)))) {
                        if (++texState==9)texState=1;
                        glActiveTexture(GL_TEXTURE0);
                        tex->bind(texState);
@@ -389,10 +389,10 @@ NOPE:
        glMatrixMode(GL_MODELVIEW);
        glPopMatrix();
        if (near && type != MOBT)
-               ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
+               ui::putStringCentered(loc.x + width / 2, loc.y - ui::fontSize - game::HLINE / 2, name);
        if (health != maxHealth) {
-               glColor3ub(150,0,0); glRectf(loc.x, loc.y + height, loc.x + width, loc.y + height + HLINE * 2);
-               glColor3ub(255,0,0); glRectf(loc.x, loc.y + height, loc.x + width * (health / maxHealth), loc.y + height + HLINE * 2);
+               glColor3ub(150,0,0); glRectf(loc.x, loc.y + height, loc.x + width, loc.y + height + HLINES(2));
+               glColor3ub(255,0,0); glRectf(loc.x, loc.y + height, loc.x + width * (health / maxHealth), loc.y + height + HLINES(2));
        }
 }
 
@@ -412,16 +412,16 @@ wander(int timeRun)
                hitCooldown--;
 
        if (targetx != 0.9112001f) {
-               if (loc.x > targetx + HLINE * 5)
-                       vel.x = -0.018 * HLINE;
-               else if (loc.x < targetx - HLINE * 5)
-                       vel.x = 0.018 * HLINE;
+               if (loc.x > targetx + HLINES(5))
+                       vel.x = HLINES(-0.018);
+               else if (loc.x < targetx - HLINES(5))
+                       vel.x = HLINES(0.018);
                else
                        targetx = 0.9112001f;
        } else if (ticksToUse == 0) {
                ticksToUse = timeRun;
 
-               vel.x = .008 * HLINE;
+               vel.x = HLINES(0.008);
                direction = (getRand() % 3 - 1);
 
                if (direction == 0)
@@ -448,6 +448,15 @@ extern int commonAIFunc(NPC *speaker);
 
 void NPC::interact() { //have the npc's interact back to the player
        std::thread([this]{
+               std::vector<XMLElement *> dopt;
+               XMLDocument xml;
+               XMLElement *exml,*oxml;
+
+               static unsigned int oldidx = 9999;
+               std::string nname;
+               unsigned int idx;
+               bool stop;
+
                loc.y += 5;
 
                canMove=false;
@@ -455,14 +464,144 @@ void NPC::interact() { //have the npc's interact back to the player
                right = !left;
 
                if (dialogCount && dialogIndex != 9999) {
-                       if (!commonAIFunc(this))
-                               dialogCount--;
+                       // load the XML file and find the dialog tags
+                       xml.LoadFile(currentXML.c_str());
+COMMONAIFUNC:
+                       idx = 0;
+                       stop = false;
+                       exml = xml.FirstChildElement("Dialog");
+
+                       // search for the dialog block associated with this npc
+                       while (exml->StrAttribute("name") != name)
+                               exml = exml->NextSiblingElement();
+
+                       // search for the desired text block
+                       exml = exml->FirstChildElement();
+                       do {
+                               if (std::string("text") == exml->Name() && exml->UnsignedAttribute("id") == (unsigned)dialogIndex)
+                                       break;
+                       } while ((exml = exml->NextSiblingElement()));
+
+                       // handle quest tags
+                       if ((oxml = exml->FirstChildElement("quest"))) {
+                               std::string qname;
+
+                               // iterate through all quest tags
+                               do {
+                                       // assign quest
+                                       if (!(qname = oxml->StrAttribute("assign")).empty())
+                                               player->qh.assign(qname, "None", std::string(oxml->GetText())); // TODO add descriptions
+
+                                       // check / finish quest
+                                       else if (!(qname = oxml->StrAttribute("check")).empty()) {
+                                               if (player->qh.hasQuest(qname) && player->qh.finish(qname)) {
+                                                       // QuestHandler::finish() did all the work..
+                                                       break;
+                                               } else {
+                                                       // run error dialog
+                                                       oldidx = dialogIndex;
+                                                       dialogIndex = oxml->UnsignedAttribute("fail");
+                                                       goto COMMONAIFUNC;
+                                               }
+                                       }
+                               } while((oxml = oxml->NextSiblingElement()));
+                       }
+
+                       // handle give tags
+                       if ((oxml = exml->FirstChildElement("give"))) {
+                               do player->inv->addItem(oxml->Attribute("id"), oxml->UnsignedAttribute("count"));
+                               while ((oxml = oxml->NextSiblingElement()));
+                       }
+
+                       // handle take tags
+                       if ((oxml = exml->FirstChildElement("take"))) {
+                               do player->inv->takeItem(oxml->Attribute("id"), oxml->UnsignedAttribute("count"));
+                               while ((oxml = oxml->NextSiblingElement()));
+                       }
+
+                       // handle movement directs
+                       if ((oxml = exml->FirstChildElement("gotox")))
+                               moveTo(std::stoi(oxml->GetText()));
+
+                       // handle dialog options
+                       if ((oxml = exml->FirstChildElement("option"))) {
+                               std::string optstr;
+
+                               // convert option strings to a colon-separated format
+                               do {
+                                       // append the next option
+                                       optstr.append(std::string(":") + oxml->Attribute("text"));
+
+                                       // save the associated XMLElement
+                                       dopt.push_back(oxml);
+                               } while ((oxml = oxml->NextSiblingElement()));
+
+                               // run the dialog stuff
+                               ui::dialogBox(name, optstr, false, exml->GetText() + 1);
+                               ui::waitForDialog();
+
+                               if (ui::dialogOptChosen)
+                                       exml = dopt[ui::dialogOptChosen - 1];
+
+                               dopt.clear();
+                       }
+
+                       // optionless dialog
+                       else {
+                               ui::dialogBox(name, "", false, exml->GetText());
+                               ui::waitForDialog();
+                       }
+
+                       // trigger other npcs if desired
+                       if (!(nname = exml->StrAttribute("call")).empty()) {
+                               NPC *n = *std::find_if(std::begin(currentWorld->npc), std::end(currentWorld->npc), [nname](NPC *npc) {
+                                       return (npc->name == nname);
+                               });
+
+                               if (exml->QueryUnsignedAttribute("callid", &idx) == XML_NO_ERROR) {
+                                       n->dialogIndex = idx;
+                                       n->addAIFunc(false);
+                               }
+                       }
+
+                       // handle potential following dialogs
+                       if ((idx = exml->UnsignedAttribute("nextid"))) {
+                               dialogIndex = idx;
+
+                               // stop talking
+                               if (exml->QueryBoolAttribute("stop", &stop) == XML_NO_ERROR && stop) {
+                                       dialogIndex = 9999;
+                                       dialogCount--;
+                               }
+
+                               // pause, allow player to click npc to continue
+                               else if (exml->QueryBoolAttribute("pause", &stop) == XML_NO_ERROR && stop) {
+                                       //return 1;
+                               }
+
+                               // instantly continue
+                               else {
+                                       goto COMMONAIFUNC;
+                               }
+                       }
+
+                       // stop talking
+                       else {
+                               // error text?
+                               if (oldidx != 9999) {
+                                       dialogIndex = oldidx;
+                                       oldidx = 9999;
+                               } else {
+                                       dialogIndex = 9999;
+                                       dialogCount--;
+                               }
+                       }
                } else {
                        ui::dialogBox(name, "", false, randomDialog[randDialog]);
                }
 
                ui::waitForDialog();
-               canMove=true;
+               canMove = true;
        }).detach();
 }
 
@@ -475,7 +614,7 @@ void Merchant::wander(int timeRun) {
        if (ticksToUse == 0) {
                ticksToUse = timeRun;
 
-               vel.x = .008 * HLINE;
+               vel.x = HLINES(0.008);
                direction = (getRand() % 3 - 1);
 
                if (direction == 0)
@@ -487,12 +626,12 @@ void Merchant::wander(int timeRun) {
        if (vel.x < 0)
                currentWorld->goWorldLeft(this);
        if (inside != nullptr) {
-               loc.y = inside->loc.y + HLINE * 2;
+               loc.y = inside->loc.y + HLINES(2);
                vel.y = GRAVITY_CONSTANT * 5;
-               if (loc.x <= inside->loc.x + HLINE * 5)
-                       loc.x = inside->loc.x + HLINE * 5;
-               else if (loc.x + width >= inside->loc.x + inside->width - HLINE * 5)
-                       loc.x = inside->loc.x + inside->width - width - HLINE * 5;
+               if (loc.x <= inside->loc.x + HLINES(5))
+                       loc.x = inside->loc.x + HLINES(5);
+               else if (loc.x + width >= inside->loc.x + inside->width - HLINES(5))
+                       loc.x = inside->loc.x + inside->width - width - HLINES(5);
        }
        ticksToUse--;
 }
@@ -668,7 +807,7 @@ void Particles::update(float _gravity, float ground_y)
 
        // handle gravity
        else if (gravity && vel.y > -1.0f) {
-               vel.y -= _gravity * gtime::getDeltaTime();
+               vel.y -= _gravity * game::time::getDeltaTime();
        }
 }
 
@@ -685,7 +824,7 @@ void Player::save(void) {
        data.append(std::to_string((int)loc.y) + "\n");
        data.append(std::to_string((int)health) + "\n");
        data.append(std::to_string((int)maxHealth) + "\n");
-       data.append(std::to_string((int)gtime::getTickCount()) + "\n");
+       data.append(std::to_string((int)game::time::getTickCount()) + "\n");
 
        data.append(std::to_string((int)inv->items.size()) + "\n");
        for(auto &i : inv->items)
@@ -727,7 +866,7 @@ void Player::sspawn(float x,float y) {
                std::getline(data,ddata);
                maxHealth = std::stoi(ddata);
                std::getline(data,ddata);
-               gtime::tick(std::stoi(ddata));
+               game::time::tick(std::stoi(ddata));
 
                std::getline(data,ddata);
                for(i = std::stoi(ddata);i;i--) {
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
deleted file mode 100644 (file)
index 7ffb1f2..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-#include <common.hpp>
-#include <entities.hpp>
-#include <world.hpp>
-#include <ui.hpp>
-
-#include <tinyxml2.h>
-using namespace tinyxml2;
-
-extern Player  *player;                                                // main.cpp
-extern World   *currentWorld;                                  // main.cpp
-
-extern Menu   pauseMenu;
-extern Menu   optionsMenu;
-
-extern std::string xmlFolder;
-
-extern std::vector<NPC *> aipreload;
-
-extern void mainLoop(void);                                            // main.cpp
-
-std::vector<XMLElement *> dopt;
-
-void destroyEverything(void);
-
-int commonAIFunc(NPC *speaker)
-{
-       XMLDocument xml;
-       XMLElement *exml,*oxml;
-
-       static unsigned int oldidx = 9999;
-
-       std::string name;
-       unsigned int idx = 0;
-       bool stop = false;
-
-       // load the XML file and find the dialog tags
-       xml.LoadFile(currentXML.c_str());
-       exml = xml.FirstChildElement("Dialog");
-
-       // search for the dialog block associated with this npc
-       while (exml->StrAttribute("name") != speaker->name)
-               exml = exml->NextSiblingElement();
-
-       // search for the desired text block
-       exml = exml->FirstChildElement();
-       std::cout << speaker->dialogIndex << '\n';
-       do {
-               if (std::string("text") == exml->Name() && exml->UnsignedAttribute("id") == (unsigned)speaker->dialogIndex)
-                       break;
-       } while ((exml = exml->NextSiblingElement()));
-
-       // handle quest tags
-       if ((oxml = exml->FirstChildElement("quest"))) {
-               std::string qname;
-
-               // iterate through all quest tags
-               do {
-                       // assign quest
-                       if (!(qname = oxml->StrAttribute("assign")).empty())
-                               player->qh.assign(qname, "None", std::string(oxml->GetText())); // TODO add descriptions
-
-                       // check / finish quest
-                       else if (!(qname = oxml->StrAttribute("check")).empty()) {
-                               if (player->qh.hasQuest(qname) && player->qh.finish(qname)) {
-                                       // QuestHandler::finish() did all the work..
-                                       break;
-                               } else {
-                                       // run error dialog
-                                       oldidx = speaker->dialogIndex;
-                                       speaker->dialogIndex = oxml->UnsignedAttribute("fail");
-                                       return commonAIFunc(speaker);
-                               }
-                       }
-               } while((oxml = oxml->NextSiblingElement()));
-       }
-
-       // handle give tags
-       if ((oxml = exml->FirstChildElement("give"))) {
-               do player->inv->addItem(oxml->Attribute("id"), oxml->UnsignedAttribute("count"));
-               while ((oxml = oxml->NextSiblingElement()));
-       }
-
-       // handle take tags
-       if ((oxml = exml->FirstChildElement("take"))) {
-               do player->inv->takeItem(oxml->Attribute("id"), oxml->UnsignedAttribute("count"));
-               while ((oxml = oxml->NextSiblingElement()));
-       }
-
-       // handle movement directs
-       if ((oxml = exml->FirstChildElement("gotox")))
-               speaker->moveTo(std::stoi(oxml->GetText()));
-
-       // handle dialog options
-       if ((oxml = exml->FirstChildElement("option"))) {
-               std::string optstr;
-
-               // convert option strings to a colon-separated format
-               do {
-                       // append the next option
-                       optstr.append(std::string(":") + oxml->Attribute("text"));
-
-                       // save the associated XMLElement
-                       dopt.push_back(oxml);
-               } while ((oxml = oxml->NextSiblingElement()));
-
-               // run the dialog stuff
-               ui::dialogBox(speaker->name, optstr, false, exml->GetText() + 1);
-               ui::waitForDialog();
-
-               if (ui::dialogOptChosen)
-                       exml = dopt[ui::dialogOptChosen - 1];
-
-               dopt.clear();
-       }
-
-       // optionless dialog
-       else {
-               ui::dialogBox(speaker->name, "", false, exml->GetText());
-               ui::waitForDialog();
-       }
-
-       // trigger other npcs if desired
-       if (!(name = exml->StrAttribute("call")).empty()) {
-               NPC *n = *std::find_if(std::begin(currentWorld->npc), std::end(currentWorld->npc), [name](NPC *npc) {
-                       return (npc->name == name);
-               });
-
-               if (exml->QueryUnsignedAttribute("callid", &idx) == XML_NO_ERROR) {
-                       n->dialogIndex = idx;
-                       n->addAIFunc(false);
-               }
-       }
-
-       // handle potential following dialogs
-       if ((idx = exml->UnsignedAttribute("nextid"))) {
-               speaker->dialogIndex = idx;
-
-               // stop talking
-               if (exml->QueryBoolAttribute("stop", &stop) == XML_NO_ERROR && stop) {
-                       speaker->dialogIndex = 9999;
-                       return 0;
-               }
-
-               // pause, allow player to click npc to continue
-               else if (exml->QueryBoolAttribute("pause", &stop) == XML_NO_ERROR && stop) {
-                       return 1;
-               }
-
-               // instantly continue
-               else {
-                       return commonAIFunc(speaker);
-               }
-       }
-
-       // stop talking
-       else {
-               // error text?
-               if (oldidx != 9999) {
-                       speaker->dialogIndex = oldidx;
-                       oldidx = 9999;
-                       return 1;
-               } else {
-                       speaker->dialogIndex = 9999;
-                       return 0;
-               }
-       }
-
-       return 0;
-}
-
-void initEverything(void) {
-       std::vector<std::string> xmlFiles;
-       XMLDocument xml;
-
-       /*
-        * Read the XML directory into an array.
-        */
-
-       if (getdir(std::string("./" + xmlFolder).c_str(), xmlFiles))
-               UserError("Error reading XML files!!!");
-
-       /*
-        * Sort the files alphabetically.
-        */
-
-       strVectorSortAlpha(&xmlFiles);
-
-       /*
-        * Load the first file found as currentWorld.
-        */
-
-       for (xf : xmlFiles) { //unsigned int i=0;i<xmlFiles.size();i++){
-               if (xf[0] != '.' && strcmp(&xf[xf.size() - 3], "dat")){
-                       // read the xml file
-                       std::cout << "File to load: " << xf << std::endl;
-                       currentWorld = loadWorldFromXML(xf);
-                       break;
-               }
-       }
-
-       /*
-        * Spawn the player and begin the game.
-        */
-
-       player = new Player();
-       player->sspawn(0,100);
-
-       ui::menu::init();
-
-       currentWorld->bgmPlay(NULL);
-       atexit(destroyEverything);
-}
-
-void destroyEverything(void) {
-       currentWorld->save();
-       //delete currentWorld;
-       //delete[] currentXML;
-
-       aipreload.clear();
-}
index be63885a21ab074f84e4f4f01e3146eb7615cd10..598cd4fc1dd43221719f62c9e86ba8766e9d5232 100644 (file)
@@ -9,42 +9,44 @@ static unsigned int deltaTime = 1;
 static unsigned int currentTime = 0;
 static unsigned int prevTime, prevPrevTime;
 
-namespace gtime {
-    void setTickCount(unsigned int t) {
-        tickCount = t;
-    }
-
-    unsigned int getTickCount(void) {
-        return tickCount;
-    }
-
-    unsigned int getDeltaTime(void) {
-        return deltaTime;
-    }
-
-    void tick(void) {
-        tickCount++;
-    }
-
-    void tick(unsigned int ticks) {
-        tickCount += ticks;
-    }
-
-    void mainLoopHandler(void) {
-       if (!currentTime)
-               currentTime = prevTime = millis();
-
-       currentTime = millis();
-       deltaTime       = currentTime - prevTime;
-       prevTime        = currentTime;
-    }
-
-    bool tickHasPassed(void) {
-        if (prevPrevTime + MSEC_PER_TICK <= currentTime) {
-               prevPrevTime = currentTime;
-            return true;
-       }
-
-        return false;
+namespace game {
+    namespace time {
+        void setTickCount(unsigned int t) {
+            tickCount = t;
+        }
+
+        unsigned int getTickCount(void) {
+            return tickCount;
+        }
+
+        unsigned int getDeltaTime(void) {
+            return (deltaTime > 0) ? deltaTime : 1;
+        }
+
+        void tick(void) {
+            tickCount++;
+        }
+
+        void tick(unsigned int ticks) {
+            tickCount += ticks;
+        }
+
+        void mainLoopHandler(void) {
+               if (!currentTime)
+                       currentTime = prevTime = millis();
+
+               currentTime = millis();
+               deltaTime       = currentTime - prevTime;
+               prevTime        = currentTime;
+        }
+
+        bool tickHasPassed(void) {
+            if (prevPrevTime + MSEC_PER_TICK <= currentTime) {
+                       prevPrevTime = currentTime;
+                return true;
+               }
+
+            return false;
+        }
     }
 }
index f8b8c3e36c2ef529c073b6ff551ab37a9e78dfa6..07ce3773c3abbd95cd0deb2b0053845b122adde3 100644 (file)
@@ -43,8 +43,8 @@ void initInventorySprites(void) {
                itemMap.back()->name = exml->StrAttribute("name");
                itemMap.back()->type = exml->StrAttribute("type");
                itemMap.back()->texloc = exml->StrAttribute("sprite");
-               itemMap.back()->width  = exml->FloatAttribute("width") * HLINE;
-               itemMap.back()->height = exml->FloatAttribute("height") * HLINE;
+               itemMap.back()->width  = HLINES(exml->FloatAttribute("width"));
+               itemMap.back()->height = HLINES(exml->FloatAttribute("height"));
                itemMap.back()->maxStackSize = exml->UnsignedAttribute("maxstack");
                itemMap.back()->attribValue = exml->FloatAttribute("value");
                itemMap.back()->tex = new Texturec({ itemMap.back()->texloc });
@@ -219,7 +219,7 @@ void Inventory::draw(void) {
        static vec2 mouseStart = {0,0};
        C("End define");
 
-       auto deltaTime = gtime::getDeltaTime();
+       auto deltaTime = game::time::getDeltaTime();
 
        for (auto &r : iray) {
                r.start.x = player->loc.x + (player->width  / 2);
@@ -228,15 +228,15 @@ void Inventory::draw(void) {
        } a = 0;
 
        for (auto &cr : curRay) {
-               cr.start.x = (offset.x + SCREEN_WIDTH / 2);
+               cr.start.x = (offset.x + game::SCREEN_WIDTH / 2);
                cr.start.y =  offset.y - (a * itemWide * 1.5f);
                curCurCoord[a++] = cr.start;
        } a = 0;
 
        for (int r = 0; r < 4; r++) {
                for (int c = 0; c < 8; c++) {
-                       massRay[a].x = ((offset.x - SCREEN_WIDTH  / 2) + itemWide) + c * itemWide * 1.5f;
-                       massRay[a].y = ((offset.y + SCREEN_HEIGHT / 2) - itemWide * 1.5f) - r * itemWide * 1.5f;
+                       massRay[a].x = ((offset.x - game::SCREEN_WIDTH  / 2) + itemWide) + c * itemWide * 1.5f;
+                       massRay[a].y = ((offset.y + game::SCREEN_HEIGHT / 2) - itemWide * 1.5f) - r * itemWide * 1.5f;
                        a++;
                }
        } a = 0;
@@ -594,7 +594,7 @@ int Inventory::useItem(void)
                                }
 
                                if (up)
-                                       hangle += 0.325f * dir * gtime::getDeltaTime();
+                                       hangle += 0.325f * dir * game::time::getDeltaTime();
 
                                if (!player->left) {
                                        if (hangle <= -90)
@@ -633,7 +633,7 @@ bool Inventory::detectCollision(vec2 one, vec2 two) {
                                }
                        }
 
-                       i+=HLINE;
+                       i += game::HLINE;
                }
        }
        return false;
index ea97474095ac14b5d8345764bdae44294e2155e8..c7832095f1cef0a6e3861bb39a3ecfe722617e77 100644 (file)
@@ -16,10 +16,11 @@ void Page::act(void)
 {
     if (player->loc.x > loc.x - 100 && player->loc.x < loc.x + 100 && isInside(ui::mouse) &&
         (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT))) {
-        std::cout << "Hey\n";
-        ui::drawPage(pageTexPath);
-        ui::waitForDialog();
-        die();
+        std::thread([this](void){
+            ui::drawPage(pageTexPath);
+            ui::waitForDialog();
+            die();
+        }).detach();
     }
 }
 
@@ -132,7 +133,7 @@ Bird::Bird(void)
 void Bird::act(void)
 {
     static bool direction = false;
-    auto deltaTime = gtime::getDeltaTime();
+    auto deltaTime = game::time::getDeltaTime();
     if (!--actCounter) {
         actCounter = actCounterInitial;
         direction ^= 1;
@@ -172,13 +173,20 @@ Trigger::Trigger(void)
     width = HLINES(20);
     height = 2000;
     tex = new Texturec(0);
+    triggered = false;
 }
 
 void Trigger::act(void)
 {
     auto c = player->loc.x + player->width / 2;
-    if (c > loc.x && c < loc.x + width) {
+    static bool running = false;
+
+    if (triggered) {
+        die();
+    } else if (!running && c > loc.x && c < loc.x + width) {
         std::thread([&]{
+            running = true;
+
             XMLDocument xml;
             XMLElement *exml;
 
@@ -203,7 +211,9 @@ void Trigger::act(void)
             }
 
             ui::toggleBlackFast();
-            die();
+
+            triggered = true;
+            running = false;
         }).detach();
     }
 }
diff --git a/src/threadpool.cpp b/src/threadpool.cpp
deleted file mode 100644 (file)
index c4f1c4a..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-#include <threadpool.hpp>
-
-/**
- * Stolen from some guy.
- */
-
-// Constructor.
-ThreadPool::ThreadPool(int threads) :
-       terminate(false),
-       stopped(false)
-{
-       // Create number of required threads and add them to the thread pool vector.
-    for(int i = 0; i < threads; i++)
-    {
-       threadPool.emplace_back(thread(&ThreadPool::Invoke, this));
-    }
-}
-
-void ThreadPool::Enqueue(function<void()> f)
-{
-       // Scope based locking.
-       {
-               // Put unique lock on task mutex.
-               unique_lock<mutex> lock(tasksMutex);
-
-               // Push task into queue.
-               tasks.push(f);
-       }
-
-       // Wake up one thread.
-       condition.notify_one();
-}
-
-void ThreadPool::Invoke() {
-
-       function<void()> task;
-       while(true)
-       {
-               // Scope based locking.
-               {
-                       // Put unique lock on task mutex.
-                       unique_lock<mutex> lock(tasksMutex);
-
-                       // Wait until queue is not empty or termination signal is sent.
-                       condition.wait(lock, [this]{ return !tasks.empty() || terminate; });
-
-                       // If termination signal received and queue is empty then exit else continue clearing the queue.
-                       if (terminate && tasks.empty())
-                       {
-                               return;
-                       }
-
-                       // Get next task in the queue.
-                       task = tasks.front();
-
-                       // Remove it from the queue.
-                       tasks.pop();
-               }
-
-               // Execute the task.
-               task();
-       }
-}
-
-void ThreadPool::ShutDown()
-{
-       // Scope based locking.
-       {
-               // Put unique lock on task mutex.
-               unique_lock<mutex> lock(tasksMutex);
-
-               // Set termination flag to true.
-               terminate = true;
-       }
-
-       // Wake up all threads.
-       condition.notify_all();
-
-       // Join all threads.
-       for(thread &thread : threadPool)
-       {
-               thread.join();
-       }
-
-       // Empty workers vector.
-       threadPool.empty();
-
-       // Indicate that the pool has been shut down.
-       stopped = true;
-}
-
-// Destructor.
-ThreadPool::~ThreadPool()
-{
-       if (!stopped)
-       {
-               ShutDown();
-       }
-}
index 654820d76ffb48f416ee04413db3d17ecb9a8d36..8e9cd1d414e9b69668d38498a6e5d8e3e43782c0 100644 (file)
@@ -411,7 +411,7 @@ namespace ui {
                                                        linc=0, //      Contains the number of letters that should be drawn.
                                                        size=0; //      Contains the full size of the current string.
 
-               auto tickCount = gtime::getTickCount();
+               auto tickCount = game::time::getTickCount();
 
                // reset values if a new string is being passed.
                if (!linc || ret.substr(0, linc) != str.substr(0, linc)) {
@@ -561,8 +561,7 @@ namespace ui {
        }
 
        void waitForCover(void) {
-               while (fadeIntensity < 255)
-                       mainLoop();
+               while (fadeIntensity < 255);
                fadeIntensity = 255;
        }
 
@@ -573,33 +572,31 @@ namespace ui {
 
        void importantText(const char *text,...) {
                va_list textArgs;
-               char *printfbuf;
+               std::unique_ptr<char[]> printfbuf (new char[512]);
 
                dialogBoxText.clear();
 
-               printfbuf = new char[ 512 ];
                va_start(textArgs,text);
-               vsnprintf(printfbuf,512,text,textArgs);
+               vsnprintf(printfbuf.get(),512,text,textArgs);
                va_end(textArgs);
-               dialogBoxText = printfbuf;
-               delete[] printfbuf;
+               dialogBoxText = printfbuf.get();
 
                dialogBoxExists = true;
                dialogImportant = true;
+               dialogPassive = false;
+               dialogPassiveTime = 0;
        }
 
        void passiveImportantText(int duration, const char *text, ...) {
                va_list textArgs;
-               char *printfbuf;
+               std::unique_ptr<char[]> printfbuf (new char[512]);
 
                dialogBoxText.clear();
 
-               printfbuf = new char[ 512 ];
                va_start(textArgs,text);
-               vsnprintf(printfbuf,512,text,textArgs);
+               vsnprintf(printfbuf.get(),512,text,textArgs);
                va_end(textArgs);
-               dialogBoxText = printfbuf;
-               delete[] printfbuf;
+               dialogBoxText = printfbuf.get();
 
                dialogBoxExists = true;
                dialogImportant = true;
@@ -634,8 +631,11 @@ namespace ui {
                float x,y,tmp;
                std::string rtext;
 
+               auto SCREEN_WIDTH = game::SCREEN_WIDTH;
+               auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+
                // will return if not toggled
-               action::draw(vec2 {player->loc.x + player->width / 2, player->loc.y + player->height + HLINE});
+               action::draw(vec2 {player->loc.x + player->width / 2, player->loc.y + player->height + game::HLINE});
 
                if (pageTexReady) {
                        glEnable(GL_TEXTURE_2D);
@@ -649,32 +649,32 @@ namespace ui {
                        glDisable(GL_TEXTURE_2D);
 
                } else if (dialogBoxExists) {
-
-                       rtext=typeOut(dialogBoxText);
+                       rtext = typeOut(dialogBoxText);
 
                        if (dialogImportant) {
                                setFontColor(255,255,255);
                                if (dialogPassive) {
-                                       dialogPassiveTime -= gtime::getDeltaTime();
+                                       dialogPassiveTime -= game::time::getDeltaTime();
                                        if (dialogPassiveTime < 0) {
                                                dialogPassive = false;
                                                dialogImportant = false;
                                                dialogBoxExists = false;
                                        }
                                }
+
                                if (fadeIntensity == 255 || dialogPassive) {
                                        setFontSize(24);
                                        putStringCentered(offset.x,offset.y,rtext);
                                        setFontSize(16);
                                }
                        }else if (dialogMerchant) {
-                               x=offset.x-SCREEN_WIDTH/6;
-                               y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
+                               x = offset.x - SCREEN_WIDTH / 6;
+                               y = (offset.y + SCREEN_HEIGHT / 2) - HLINES(8);
 
                                drawBox(vec2 {x, y}, vec2 {x + SCREEN_WIDTH / 3, y - SCREEN_HEIGHT * 0.6f});
 
                                // draw typeOut'd text
-                               putString(x + HLINE, y - fontSize - HLINE, (rtext = typeOut(dialogBoxText)));
+                               putString(x + game::HLINE, y - fontSize - game::HLINE, (rtext = typeOut(dialogBoxText)));
 
                                std::string itemString1 = std::to_string(merchTrade.quantity[0]) + "x",
                                            itemString2 = std::to_string(merchTrade.quantity[1]) + "x";
@@ -736,7 +736,7 @@ namespace ui {
                                        setFontColor(255, 255, 255);
 
                                        // draw option
-                                       dialogOptText[i].second.y = y - SCREEN_HEIGHT / 2 - (fontSize + HLINE) * (i + 1);
+                                       dialogOptText[i].second.y = y - SCREEN_HEIGHT / 2 - (fontSize + game::HLINE) * (i + 1);
                                        tmp = putStringCentered(offset.x, dialogOptText[i].second.y, dialogOptText[i].first);
 
                                        // get coordinate information on option
@@ -754,21 +754,20 @@ namespace ui {
                                setFontColor(255, 255, 255);
                        } else { //normal dialog box
 
-                               x = offset.x - SCREEN_WIDTH / 2  + HLINE * 8;
-                               y = offset.y + SCREEN_HEIGHT / 2 - HLINE * 8;
+                               x = offset.x - SCREEN_WIDTH / 2  + HLINES(8);
+                               y = offset.y + SCREEN_HEIGHT / 2 - HLINES(8);
 
-                               drawBox(vec2 {x, y}, vec2 {x + SCREEN_WIDTH - HLINE * 16, y - SCREEN_HEIGHT / 4});
+                               drawBox(vec2 {x, y}, vec2 {x + SCREEN_WIDTH - HLINES(16), y - SCREEN_HEIGHT / 4});
 
                                rtext = typeOut(dialogBoxText);
-
-                               putString(x+HLINE,y-fontSize-HLINE,rtext);
+                               putString(x + game::HLINE, y - fontSize - game::HLINE, rtext);
 
                                for(i=0;i<dialogOptText.size();i++) {
                                        setFontColor(255,255,255);
                                        tmp = putStringCentered(offset.x,dialogOptText[i].second.y,dialogOptText[i].first);
                                        dialogOptText[i].second.z = offset.x + tmp;
                                        dialogOptText[i].second.x = offset.x - tmp;
-                                       dialogOptText[i].second.y = y - SCREEN_HEIGHT / 4 + (fontSize + HLINE) * (i + 1);
+                                       dialogOptText[i].second.y = y - SCREEN_HEIGHT / 4 + (fontSize + game::HLINE) * (i + 1);
                                        if (mouse.x > dialogOptText[i].second.x &&
                                           mouse.x < dialogOptText[i].second.z &&
                                           mouse.y > dialogOptText[i].second.y &&
@@ -844,8 +843,8 @@ namespace ui {
                dialogBoxExists = false;
                currentMenu = NULL;
                gameRunning = false;
-               config::update();
-               config::save();
+               game::config::update();
+               game::config::save();
        }
 
        void closeBox() {
@@ -856,6 +855,9 @@ namespace ui {
        void dialogAdvance(void) {
                unsigned char i;
 
+               dialogPassive = false;
+               dialogPassiveTime = 0;
+
                if (pageTex) {
                        glDeleteTextures(1, &pageTex);
                        pageTex = 0;
@@ -898,9 +900,6 @@ EXIT:
                //if (!dialogMerchant)closeBox();
                dialogBoxExists = false;
                dialogMerchant = false;
-               dialogPassive = false;
-
-               //DONE:
 
                // handle important text
                if (dialogImportant) {
@@ -913,6 +912,10 @@ EXIT:
                static bool left=true,right=false;
                static int heyOhLetsGo = 0;
                static int mouseWheelUpCount = 0, mouseWheelDownCount = 0;
+
+               auto SCREEN_WIDTH = game::SCREEN_WIDTH;
+               auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+
                World *tmp;
                vec2 oldpos,tmppos;
                SDL_Event e;
@@ -1001,7 +1004,7 @@ EXIT:
                                // space - make player jump
                                if (SDL_KEY == SDLK_SPACE) {
                                        if (player->ground) {
-                                               player->loc.y += HLINE * 2;
+                                               player->loc.y += HLINES(2);
                                                player->vel.y = .4;
                                                player->ground = false;
                                        }
@@ -1012,7 +1015,7 @@ EXIT:
                                        tmp = currentWorld;
                                        switch(SDL_KEY) {
                                        case SDLK_t:
-                                               gtime::tick(50);
+                                               game::time::tick(50);
                                                break;
                                        case SDLK_a:
                                                if (fadeEnable)break;
@@ -1090,12 +1093,12 @@ EXIT:
 
                                                // start hover counter?
                                                if (!heyOhLetsGo) {
-                                                       heyOhLetsGo = loops;
+                                                       heyOhLetsGo = game::time::getTickCount();
                                                        player->inv->mouseSel = false;
                                                }
 
                                                // run hover thing
-                                               if (loops - heyOhLetsGo >= 2 && !(player->inv->invOpen) && !(player->inv->selected)) {
+                                               if (game::time::getTickCount() - heyOhLetsGo >= 2 && !(player->inv->invOpen) && !(player->inv->selected)) {
                                                        player->inv->invHover = true;
 
                                                        // enable action ui
@@ -1232,6 +1235,9 @@ EXIT:
        }
 
        void drawFade(void) {
+               auto SCREEN_WIDTH = game::SCREEN_WIDTH;
+               auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+
                if (!fadeIntensity) {
                        if (fontSize != 16)
                                setFontSize(16);
@@ -1292,6 +1298,9 @@ EXIT:
        }
 
     void takeScreenshot(GLubyte* pixels) {
+               auto SCREEN_WIDTH = game::SCREEN_WIDTH;
+               auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+
                std::vector<GLubyte> bgr (SCREEN_WIDTH * SCREEN_HEIGHT * 3, 0);
 
                for(uint x = 0; x < SCREEN_WIDTH*SCREEN_HEIGHT*3; x+=3) {
index 0c7a6d8373fec3b5edf7522d713541a55f53d850..09b09c814a00f0683d52d00eba91f7229db61ed6 100644 (file)
@@ -11,7 +11,7 @@ void Menu::gotoParent(void)
 {
        if (!parent) {
                currentMenu = nullptr;
-               config::update();
+               game::config::update();
        } else {
                currentMenu = parent;
        }
@@ -90,9 +90,9 @@ namespace ui {
                        pauseMenu.items.push_back(ui::menu::createButton({-256/2,-300},{256,75},{0.0f,0.0f,0.0f}, "Segfault", segFault));
                        pauseMenu.child = &optionsMenu;
 
-                       optionsMenu.items.push_back(ui::menu::createSlider({0-(float)SCREEN_WIDTH/4,0-(512/2)}, {50,512}, {0.0f, 0.0f, 0.0f}, 0, 100, "Master", &VOLUME_MASTER));
-                       optionsMenu.items.push_back(ui::menu::createSlider({-200,100}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "Music", &VOLUME_MUSIC));
-                       optionsMenu.items.push_back(ui::menu::createSlider({-200,000}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "SFX", &VOLUME_SFX));
+                       optionsMenu.items.push_back(ui::menu::createSlider({0-static_cast<float>(game::SCREEN_WIDTH)/4,0-(512/2)}, {50,512}, {0.0f, 0.0f, 0.0f}, 0, 100, "Master", &game::config::VOLUME_MASTER));
+                       optionsMenu.items.push_back(ui::menu::createSlider({-200,100}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "Music", &game::config::VOLUME_MUSIC));
+                       optionsMenu.items.push_back(ui::menu::createSlider({-200,000}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "SFX", &game::config::VOLUME_SFX));
                        optionsMenu.parent = &pauseMenu;
                }
 
@@ -101,10 +101,13 @@ namespace ui {
                }
 
         void draw(void) {
+                       auto SCREEN_WIDTH = game::SCREEN_WIDTH;
+                       auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+
             SDL_Event e;
 
             setFontSize(24);
-            config::update();
+            game::config::update();
 
             mouse.x = ui::premouse.x+offset.x-(SCREEN_WIDTH/2);
             mouse.y = (offset.y+SCREEN_HEIGHT/2)-ui::premouse.y;
index 785b2b41a2764fe21aef51efc50bdd42d9083e7a..ab2c908885fc83c17333b179e2911b7033379d5f 100644 (file)
@@ -219,13 +219,13 @@ generate(int width)
     }
 
     // define x-coordinate of world's leftmost 'line'
-    worldStart = (width - GROUND_HILLINESS) * HLINE / 2 * -1;
+    worldStart = (width - GROUND_HILLINESS) * game::HLINE / 2 * -1;
 
     // create empty star array, should be filled here as well...
        star = std::vector<vec2> (100, vec2 { 0, 400 });
        for (auto &s : star) {
                s.x = (getRand() % (-worldStart * 2)) + worldStart;
-               s.y = (getRand() % SCREEN_HEIGHT) + 100;
+               s.y = (getRand() % game::SCREEN_HEIGHT) + 100;
        }
 }
 
@@ -237,6 +237,10 @@ generate(int width)
 void World::
 draw(Player *p)
 {
+    auto SCREEN_WIDTH = game::SCREEN_WIDTH;
+       auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+    auto HLINE = game::HLINE;
+
     const ivec2 backgroundOffset = ivec2 {
         static_cast<int>(SCREEN_WIDTH) / 2, static_cast<int>(SCREEN_HEIGHT) / 2
     };
@@ -542,7 +546,7 @@ singleDetect(Entity *e)
        unsigned int i;
        int l;
 
-    auto deltaTime = gtime::getDeltaTime();
+    auto deltaTime = game::time::getDeltaTime();
 
        // kill dead entities
        if (!e->isAlive()) {
@@ -593,7 +597,7 @@ singleDetect(Entity *e)
         e->handleHits();
 
                // calculate the line that this entity is currently standing on
-               l = static_cast<int>(fmax((e->loc.x + e->width / 2 - worldStart) / HLINE, 0));
+               l = static_cast<int>(fmax((e->loc.x + e->width / 2 - worldStart) / game::HLINE, 0));
                l = static_cast<int>(fmin(l, lineCount - 1));
 
                // if the entity is under the world/line, pop it back to the surface
@@ -626,10 +630,10 @@ singleDetect(Entity *e)
                // insure that the entity doesn't fall off either edge of the world.
                if (e->loc.x < worldStart) {
                        e->vel.x = 0;
-                       e->loc.x = worldStart + HLINE / 2;
-               } else if (e->loc.x + e->width + HLINE > worldStart + worldStart * -2) {
+                       e->loc.x = worldStart + game::HLINE / 2;
+               } else if (e->loc.x + e->width + game::HLINE > worldStart + worldStart * -2) {
                        e->vel.x = 0;
-                       e->loc.x = worldStart + worldStart * -2 - e->width - HLINE;
+                       e->loc.x = worldStart + worldStart * -2 - e->width - game::HLINE;
                }
        }
 }
@@ -656,7 +660,7 @@ detect(Player *p)
     // handle particles
        for (auto &part : particles) {
                // get particle's current world line
-               l = (int)fmax((part.loc.x + part.width / 2 - worldStart) / HLINE, 0);
+               l = (int)fmax((part.loc.x + part.width / 2 - worldStart) / game::HLINE, 0);
         l = (int)fmin(lineCount - 1, l);
                part.update(GRAVITY_CONSTANT, worldData[l].groundHeight);
        }
@@ -666,10 +670,10 @@ detect(Player *p)
                switch (b->bsubtype) {
                case FOUNTAIN:
                        for (unsigned int r = (randGet() % 25) + 11; r--;) {
-                               addParticle(randGet() % HLINE * 3 + b->loc.x + b->width / 2,    // x
+                               addParticle(randGet() % HLINES(3) + b->loc.x + b->width / 2,    // x
                                                        b->loc.y + b->height,                                                           // y
-                                                       HLINE * 1.25,                                                                           // width
-                                                       HLINE * 1.25,                                                                           // height
+                                                       HLINES(1.25),                                                                           // width
+                                                       HLINES(1.25),                                                                           // height
                                                        randGet() % 7 * .01 * (randGet() % 2 == 0 ? -1 : 1),    // vel.x
                                                        (4 + randGet() % 6) * .05,                                                      // vel.y
                                                        { 0, 0, 255 },                                                                          // RGB color
@@ -681,9 +685,9 @@ detect(Player *p)
                case FIRE_PIT:
                        for(unsigned int r = (randGet() % 20) + 11; r--;) {
                                addParticle(randGet() % (int)(b->width / 2) + b->loc.x + b->width / 4,  // x
-                                                       b->loc.y + 3 * HLINE,                                                                           // y
-                                                       HLINE,                                                                                                          // width
-                                                       HLINE,                                                                                                          // height
+                                                       b->loc.y + HLINES(3),                                                                           // y
+                                                       game::HLINE,                                                                                            // width
+                                                       game::HLINE,                                                                                            // height
                                                        randGet() % 3 * .01 * (randGet() % 2 == 0 ? -1 : 1),            // vel.x
                                                        (4 + randGet() % 6) * .005,                                                                     // vel.y
                                                        { 255, 0, 0 },                                                                                          // RGB color
@@ -700,11 +704,13 @@ detect(Player *p)
 
        // draws the village welcome message if the player enters the village bounds
        for (auto &v : village) {
-               if (p->loc.x > v.start.x && p->loc.x < v.end.x && !v.in) {
-                       ui::passiveImportantText(5000, "Welcome to %s", v.name.c_str());
-                       v.in = true;
-               } else {
-                       v.in = false;
+               if (p->loc.x > v.start.x && p->loc.x < v.end.x) {
+            if (!v.in) {
+                           ui::passiveImportantText(5000, "Welcome to %s", v.name.c_str());
+                           v.in = true;
+                   }
+        } else {
+            v.in = false;
         }
        }
 }
@@ -1042,12 +1048,12 @@ goWorldLeft(Player *p)
        World *tmp;
 
     // check if player is at world edge
-       if (!toLeft.empty() && p->loc.x < worldStart + HLINE * 15.0f) {
+       if (!toLeft.empty() && p->loc.x < worldStart + HLINES(15)) {
         // load world (`toLeft` conditional confirms existance)
            tmp = loadWorldFromPtr(currentWorldToLeft);
 
         // adjust player location
-               p->loc.x = tmp->worldStart + HLINE * 20;
+               p->loc.x = tmp->worldStart + HLINES(20);
                p->loc.y = tmp->worldData[tmp->lineCount - 1].groundHeight;
 
                return tmp;
@@ -1064,10 +1070,10 @@ goWorldRight(Player *p)
 {
        World *tmp;
 
-       if (!toRight.empty() && p->loc.x + p->width > -worldStart - HLINE * 15) {
+       if (!toRight.empty() && p->loc.x + p->width > -worldStart - HLINES(15)) {
                tmp = loadWorldFromPtr(currentWorldToRight);
 
-               p->loc.x = tmp->worldStart - HLINE * -15.0f;
+               p->loc.x = tmp->worldStart - HLINES(-15.0);
                p->loc.y = GROUND_HEIGHT_MINIMUM;
 
                return tmp;
@@ -1083,7 +1089,7 @@ bool World::
 goWorldLeft(NPC *e)
 {
        // check if entity is at world edge
-       if(!toLeft.empty() && e->loc.x < worldStart + HLINE * 15.0f) {
+       if(!toLeft.empty() && e->loc.x < worldStart + HLINES(15)) {
         currentWorldToLeft->addNPC(e->loc.x,e->loc.y);
         e->die();
 
@@ -1361,22 +1367,22 @@ singleDetect(Entity *e)
     }
 
     if (e->vel.y > -2)
-        e->vel.y -= GRAVITY_CONSTANT * gtime::getDeltaTime();
+        e->vel.y -= GRAVITY_CONSTANT * game::time::getDeltaTime();
 
     if (e->ground) {
         e->loc.y = ceil(e->loc.y);
         e->vel.y = 0;
     }
 
-    start = worldStart + fstart[floornum] * HLINE;
-    end = start + floor[floornum].size() * HLINE;
+    start = worldStart + HLINES(fstart[floornum]);
+    end = start + HLINES(floor[floornum].size());
 
     if (e->loc.x < start) {
         e->vel.x = 0;
-        e->loc.x = start + HLINE / 2;
-    } else if (e->loc.x + e->width + HLINE > end) {
+        e->loc.x = start + game::HLINE / 2;
+    } else if (e->loc.x + e->width + game::HLINE > end) {
         e->vel.x = 0;
-        e->loc.x = end - e->width - HLINE;
+        e->loc.x = end - e->width - game::HLINE;
     }
 
 }
@@ -1387,6 +1393,10 @@ draw(Player *p)
        unsigned int i,f;
        int x;
 
+    auto SCREEN_WIDTH = game::SCREEN_WIDTH;
+    auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+    auto HLINE = game::HLINE;
+
     // draw lights
     for (auto &l : light) {
         if (l.belongsTo) {
@@ -1459,7 +1469,7 @@ draw(Player *p)
         for (f = 0; f < floor.size(); f++) {
             i = 0;
                for (h : floor[f]) {
-                       x = worldStart + fstart[f] * HLINE + (i * HLINE);
+                       x = worldStart + fstart[f] * HLINE + HLINES(i);
                        glVertex2i(x        , h            );
                        glVertex2i(x + HLINE, h            );
                        glVertex2i(x + HLINE, h - INDOOR_FLOOR_THICKNESS);
@@ -1515,7 +1525,7 @@ World *Arena::exitArena(Player *p) {
        World *tmp;
        if (!mmob->isAlive() &&
         p->loc.x + p->width / 2 > mob[0]->loc.x &&
-           p->loc.x + p->width / 2 < mob[0]->loc.x + HLINE * 12) {
+           p->loc.x + p->width / 2 < mob[0]->loc.x + HLINES(12)) {
            tmp = battleNest.front();
                battleNest.erase(battleNest.begin());
 
@@ -1530,9 +1540,9 @@ World *Arena::exitArena(Player *p) {
                mmob->die();
 
                return tmp;
-       }else{
-               return this;
        }
+
+    return this;
 }
 
 std::string getWorldWeatherStr(WorldWeather ww)
@@ -1690,21 +1700,7 @@ loadWorldFromXMLNoSave(std::string path) {
             }
                }
 
-        /**
-         * MOBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
-         * BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
-         * BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
-
-         else if (name == "trigger") {
-            tmp->addMob(MS_TRIGGER, wxml->FloatAttribute("x"), 0, commonTriggerFunc);
-            tmp->getLastMob()->heyid = wxml->Attribute("id");
-        } else if (name == "page") {
-            tmp->addMob(MS_PAGE, wxml->FloatAttribute("x"), 0, commonPageFunc);
-            tmp->getLastMob()->heyid = wxml->Attribute("id");
-        }
-
-         */
-
+        // mob creation
          else if (name == "rabbit") {
              tmp->addMob(new Rabbit(), vec2 {0, 0});
              tmp->getLastMob()->createFromXML(wxml);
@@ -1722,36 +1718,6 @@ loadWorldFromXMLNoSave(std::string path) {
              tmp->getLastMob()->createFromXML(wxml);
          }
 
-
-
-
-        /*else if (name == "mob") {
-
-
-
-            // type info
-            if (wxml->QueryUnsignedAttribute("type", &flooor) != XML_NO_ERROR)
-                UserError("XML Error: Invalid type value in <mob> in " + currentXML + "!");
-
-            // spawn at coordinate if desired
-                       if (wxml->QueryFloatAttribute("x", &spawnx) == XML_NO_ERROR)
-                               tmp->addMob(flooor, spawnx, wxml->FloatAttribute("y"));
-                       else
-                               tmp->addMob(flooor, 0, 100);
-
-            // aggressive tag
-                       if (wxml->QueryBoolAttribute("aggressive", &dialog) == XML_NO_ERROR)
-                               tmp->getLastMob()->aggressive = dialog;
-
-            // indoor spawning floor selection
-            if (Indoor && wxml->QueryUnsignedAttribute("floor", &flooor) == XML_NO_ERROR)
-                Indoorp(tmp)->moveToFloor(tmp->npc.back(), flooor);
-
-            // custom health value
-            if (wxml->QueryFloatAttribute("health", &spawnx) == XML_NO_ERROR)
-                tmp->getLastMob()->health = tmp->getLastMob()->maxHealth = spawnx;
-               }*/
-
         // npc creation
         else if (name == "npc") {
                        const char *npcname;
@@ -1796,7 +1762,7 @@ loadWorldFromXMLNoSave(std::string path) {
                } else if (name == "hill") {
                        tmp->addHill(ivec2 { wxml->IntAttribute("peakx"), wxml->IntAttribute("peaky") }, wxml->UnsignedAttribute("width"));
                } else if (name == "time") {
-            gtime::setTickCount(std::stoi(wxml->GetText()));
+            game::time::setTickCount(std::stoi(wxml->GetText()));
         } else if (Indoor && name == "floor") {
             if (wxml->QueryFloatAttribute("start",&spawnx) == XML_NO_ERROR)
                 Indoorp(tmp)->addFloor(wxml->UnsignedAttribute("width"), spawnx);
index e8e95d2e8f4e59f78bfe59b3139427e9c1038b4b..d4691a583f6e42ee50a9f6b572ac3a864b11facf 100644 (file)
@@ -10,7 +10,7 @@
        <rabbit x="300" aggressive="true" health="100" />
        <bird />
 
-       <!--<trigger x="-300" id="Test" />-->
+       <trigger x="-300" id="Test" />
 
        <npc name="Ralph" hasDialog="true" x="300" />
        <npc name="Johnny" hasDialog="false" x="300" />