diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/common.hpp | 27 | ||||
-rw-r--r-- | include/config.hpp | 25 | ||||
-rw-r--r-- | include/entities.hpp | 41 | ||||
-rw-r--r-- | include/gametime.hpp | 18 | ||||
-rw-r--r-- | include/inventory.hpp | 3 | ||||
-rw-r--r-- | include/mob.hpp | 88 | ||||
-rw-r--r-- | include/threadpool.hpp | 53 | ||||
-rw-r--r-- | include/ui.hpp | 2 | ||||
-rw-r--r-- | include/world.hpp | 9 |
9 files changed, 134 insertions, 132 deletions
diff --git a/include/common.hpp b/include/common.hpp index 7f36be2..1f7b9fc 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -18,8 +18,7 @@ #include <thread> #include <mutex> #include <future> -#include <math.h> -#include <threadpool.hpp> +#include <cmath> #include <algorithm> #define GLEW_STATIC @@ -103,6 +102,10 @@ struct _vec2 { x = y = n; return *this; } + template<typename T> + const _vec2 operator+(const T &n) { + return _vec2 {x + n, y + n}; + } }; typedef struct _vec2 vec2; @@ -149,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; @@ -175,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. diff --git a/include/config.hpp b/include/config.hpp index 8bd0bc9..bc9d052 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -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 diff --git a/include/entities.hpp b/include/entities.hpp index 864c863..567380a 100644 --- a/include/entities.hpp +++ b/include/entities.hpp @@ -42,19 +42,6 @@ enum GENDER{ }; /** - * An enumerator for mob types.. 'species'. - * The subtype of a Mob will affect what texture is used to draw it as well as - * how the Mob will behave. - */ -enum MOB_SUB { - MS_RABBIT = 1, /**< rabbits */ - MS_BIRD, /**< birds */ - MS_TRIGGER, /**< triggers, used to cue cutscenes */ - MS_DOOR, /**< doors, for exiting arenas */ - MS_PAGE /**< pages, cues page overlay */ -}; - -/** * An enumerator for strcture types. * The subtype of a structure will affect how it is drawn and how it functions. */ @@ -190,9 +177,6 @@ protected: // if set false, entity will be destroyed bool alive; - // if not null, the entity will move towards this one - Entity *followee; - // TODO float targetx; @@ -259,6 +243,7 @@ public: // allows the entity to wander, according to what class is deriving this. virtual void wander(int){} + virtual void wander(void){} // allows the entity to interact with the player virtual void interact(void){} @@ -360,19 +345,6 @@ public: void wander(int); }; -class Mob : public Entity{ -public: - bool aggressive; - double init_y; - void (*hey)(Mob *callee); - std::string heyid; - - Mob(int); - ~Mob(); - - void wander(int); -}; - class Object : public Entity{ private: std::string iname; @@ -424,13 +396,10 @@ public: void makeFlame(void){ flame = true; } - - void follow(Entity *f){ - following = f; - belongsTo = true; - } }; +#include <mob.hpp> + constexpr Object *Objectp(Entity *e) { return (Object *)e; } @@ -443,8 +412,8 @@ constexpr Structures *Structurep(Entity *e) { return (Structures *)e; } -constexpr Mob *Mobp(Entity *e) { - return (Mob *)e; +constexpr Merchant *Merchantp(Entity *e) { + return (Merchant *)e; } #endif // ENTITIES_H diff --git a/include/gametime.hpp b/include/gametime.hpp index c2991d2..a809ef9 100644 --- a/include/gametime.hpp +++ b/include/gametime.hpp @@ -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_ diff --git a/include/inventory.hpp b/include/inventory.hpp index a568faf..a41d4d4 100644 --- a/include/inventory.hpp +++ b/include/inventory.hpp @@ -26,6 +26,9 @@ public: // the array of textures for each frame of animation Texturec *tex; + // how much the item is rotated in the hand + float rotation = 0.0f; + /** * The function we use to call the child classes ability * Note: Since this function is abstract, we HAVE to create one for each diff --git a/include/mob.hpp b/include/mob.hpp new file mode 100644 index 0000000..9f006b9 --- /dev/null +++ b/include/mob.hpp @@ -0,0 +1,88 @@ +#ifndef MOB_H_ +#define MOB_H_ + +#include <common.hpp> +#include <entities.hpp> +#include <gametime.hpp> +#include <ui.hpp> + +// local library headers +#include <tinyxml2.h> +using namespace tinyxml2; + +extern Player *player; +extern std::string currentXML; + +class Mob : public Entity { +protected: + unsigned int actCounter; + unsigned int actCounterInitial; +public: + bool aggressive; + std::string heyid; + + ~Mob(void); + + void wander(void); + virtual void act(void) =0; + virtual bool bindTex(void) =0; + virtual void createFromXML(const XMLElement *e) =0; +}; + +constexpr Mob *Mobp(Entity *e) { + return (Mob *)e; +} + +class Page : public Mob { +private: + std::string pageTexPath; +public: + Page(void); + + void act(void); + bool bindTex(void); + void createFromXML(const XMLElement *e); +}; + +class Door : public Mob { +public: + Door(void); + + void act(void); + bool bindTex(void); + void createFromXML(const XMLElement *e); +}; + +class Rabbit : public Mob { +public: + Rabbit(void); + + void act(void); + bool bindTex(void); + void createFromXML(const XMLElement *e); +}; + +class Bird : public Mob { +private: + float initialY; +public: + Bird(void); + + void act(void); + bool bindTex(void); + void createFromXML(const XMLElement *e); +}; + +class Trigger : public Mob { +private: + std::string id; + bool triggered; +public: + Trigger(void); + + void act(void); + bool bindTex(void); + void createFromXML(const XMLElement *e); +}; + +#endif // MOB_H_ diff --git a/include/threadpool.hpp b/include/threadpool.hpp deleted file mode 100644 index c341673..0000000 --- a/include/threadpool.hpp +++ /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 diff --git a/include/ui.hpp b/include/ui.hpp index 9e69497..7cee885 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -21,10 +21,10 @@ // local game headers #include <common.hpp> #include <config.hpp> +#include <entities.hpp> #include <inventory.hpp> #include <ui_menu.hpp> #include <ui_action.hpp> -#include <world.hpp> // local library headers #include <SDL2/SDL_opengl.h> diff --git a/include/world.hpp b/include/world.hpp index c6eaf06..b99e9ab 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -159,7 +159,7 @@ public: virtual ~World(void); // generates a world of the specified width - void generate(unsigned int width); + void generate(int width); // draws everything to the screen virtual void draw(Player *p); @@ -220,7 +220,7 @@ public: bool goWorldLeft(NPC *e); // attempts to enter a structure that the player would be standing in front of - World *goInsideStructure(Player *p); + std::pair<World *, float> goInsideStructure(Player *p); // adds a hole at the specified start and end x-coordinates void addHole(unsigned int start,unsigned int end); @@ -233,8 +233,9 @@ public: void addMerchant(float x, float y, bool housed); - void addMob(int type, float x, float y); - void addMob(int type, float x, float y, void (*hey)(Mob *)); + //void addMob(int type, float x, float y); + //void addMob(int type, float x, float y, void (*hey)(Mob *)); + void addMob(Mob *m, vec2 coord); void addNPC(float x, float y); |