aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/attack.hpp6
-rw-r--r--include/components.hpp25
-rw-r--r--include/config.hpp2
-rw-r--r--include/font.hpp56
-rw-r--r--include/player.hpp2
-rw-r--r--include/ui.hpp132
-rw-r--r--include/ui_quest.hpp8
-rw-r--r--include/vector2.hpp10
-rw-r--r--include/world.hpp49
9 files changed, 178 insertions, 112 deletions
diff --git a/include/attack.hpp b/include/attack.hpp
index 027b93f..0ab5138 100644
--- a/include/attack.hpp
+++ b/include/attack.hpp
@@ -10,15 +10,15 @@
enum class AttackType : char {
ShortSlash,
LongSlash,
- SmallBoom
};
struct AttackEvent {
- AttackEvent(vec2 p, AttackType at, int pow = 10)
- : pos(p), type(at), power(pow) {}
+ AttackEvent(vec2 p, AttackType at, bool fp, int pow = 10)
+ : pos(p), type(at), fromplayer(fp), power(pow) {}
vec2 pos;
AttackType type;
+ bool fromplayer;
int power;
};
diff --git a/include/components.hpp b/include/components.hpp
index fe56a88..87d4293 100644
--- a/include/components.hpp
+++ b/include/components.hpp
@@ -98,7 +98,7 @@ struct Physics : public Component {
* Constructor that sets the gravity constant, if not specified it becomes 0.
* @param g The non default gravity constant.
*/
- Physics(float g = 1.0f): g(g) {}
+ Physics(float g = 0.2f): g(g) {}
Physics(XMLElement* imp, XMLElement* def) {
fromXML(imp, def);
}
@@ -108,7 +108,7 @@ struct Physics : public Component {
void fromXML(XMLElement* imp, XMLElement* def) final {
if (imp->QueryFloatAttribute("gravity", &g) != XML_NO_ERROR) {
if (def->QueryFloatAttribute("value", &g) != XML_NO_ERROR)
- g = 1.0f;
+ g = 0.2f;
}
}
};
@@ -611,10 +611,11 @@ struct Aggro : public Component {
};
struct Hit : public Component {
- Hit(int d)
- : damage(d) {}
+ Hit(int d, bool p = false)
+ : damage(d), pierce(p) {}
int damage;
+ bool pierce;
void fromXML(XMLElement* imp, XMLElement* def) final {
(void)imp;
@@ -622,6 +623,22 @@ struct Hit : public Component {
}
};
+struct Trigger : public Component {
+ Trigger(const std::string& t)
+ : text(t) {}
+ Trigger(XMLElement* imp, XMLElement* def) {
+ fromXML(imp, def);
+ }
+
+ std::string text;
+
+ void fromXML(XMLElement* imp, XMLElement* def) final {
+ (void)imp;
+ (void)def;
+ text = "You got me!";
+ }
+};
+
/**
* SYSTEMS
*/
diff --git a/include/config.hpp b/include/config.hpp
index 13596ff..305f61e 100644
--- a/include/config.hpp
+++ b/include/config.hpp
@@ -52,6 +52,8 @@ namespace game {
* The path of the folder to load world XML files from.
*/
extern std::string xmlFolder;
+
+ extern std::string fontFamily;
/**
* Reads the settings file (config/settings.xml) into the game.
diff --git a/include/font.hpp b/include/font.hpp
new file mode 100644
index 0000000..a520c15
--- /dev/null
+++ b/include/font.hpp
@@ -0,0 +1,56 @@
+#ifndef FONT_HPP_
+#define FONT_HPP_
+
+#include <vector>
+#include <map>
+
+#include <color.hpp>
+#include <render.hpp>
+#include <vector2.hpp>
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+struct FT_Info {
+ vec2 wh;
+ vec2 bl;
+ vec2 ad;
+ GLuint tex;
+
+ FT_Info(void)
+ : tex(0) {}
+};
+
+class FontSystem {
+private:
+ static FT_Library ftLibrary;
+ static FT_Face ftFace;
+
+ static std::string fontFamily;
+ static std::map<int, std::vector<FT_Info>> fontData;
+
+ static int currentSize;
+ static Color currentColor;
+ static float currentZ;
+
+public:
+ ~FontSystem(void) {
+ FT_Done_Face(ftFace);
+ FT_Done_FreeType(ftLibrary);
+ }
+
+ static void init(const std::string& ttf);
+ static void setFontSize(int size);
+ static void setFontColor(float r, float g, float b);
+ static void setFontZ(float z = -8.0f);
+
+ static vec2 putChar(float xx, float yy, char c);
+
+ static inline int getSize(void)
+ { return currentSize; }
+
+ static inline auto& getFont(void)
+ { return fontData.at(currentSize); }
+};
+
+#endif // FONT_HPP_
diff --git a/include/player.hpp b/include/player.hpp
index 2c65717..efac984 100644
--- a/include/player.hpp
+++ b/include/player.hpp
@@ -15,7 +15,7 @@
/**
* The constant velocity the player is given when moved with the arrow keys.
*/
-constexpr const float PLAYER_SPEED_CONSTANT = 0.15f;
+constexpr const float PLAYER_SPEED_CONSTANT = 0.03f;
/**
* @class PlayerSystem
diff --git a/include/ui.hpp b/include/ui.hpp
index ac415f5..3f0a67f 100644
--- a/include/ui.hpp
+++ b/include/ui.hpp
@@ -32,118 +32,102 @@ public:
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
};
-namespace ui {
+struct OptionDim {
+ float x;
+ float y;
+ float width;
+};
- extern bool fadeEnable;
- extern int fadeIntensity;
+using DialogOption = std::pair<OptionDim, std::string>;
- // the pixel-coordinates of the mouse
- extern vec2 mouse;
+class UISystem : public entityx::System<UISystem> {
+private:
+ static bool fadeEnable;
+ static bool fadeFast;
+ static int fadeIntensity;
- // raw mouse values from SDL
- extern vec2 premouse;
+ static std::string dialogText;
+ static std::string importantText;
+ static std::vector<DialogOption> dialogOptions;
+ static int dialogOptionResult;
- // the currently used font size for text rendering
- extern unsigned int fontSize;
+public:
+ UISystem(void) {}
- // shows the debug overlay when set to true
- extern bool debug;
+ void update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt) override;
- // shows tracers when set to true (alongside `debug`)
- extern bool posFlag;
+ static void render(void);
- extern unsigned char dialogOptChosen;
- extern bool dialogBoxExists;
- extern bool dialogImportant;
- extern bool dialogPassive;
+ /***
+ * Fade library
+ */
- extern unsigned int textWrapLimit;
- extern int fontTransInv;
+ static void fadeToggle(void);
+ static void fadeToggleFast(void);
+ static void waitForCover(void);
+ static void waitForUncover(void);
- /*
- * Initializes the FreeType system.
- */
- void initFonts(void);
- void initSounds(void);
+ static inline bool isFading(void)
+ { return fadeIntensity != 0; }
- void destroyFonts(void);
+ static inline bool isDialog(void)
+ { return !dialogText.empty() || !importantText.empty(); }
- /*
- * Sets the current font/font size.
- */
+ /**
+ * Text library
+ */
- void setFontFace(const char *ttf);
- void setFontSize(unsigned int size);
- void setFontColor(int r, int g, int b, int a);
- void setFontZ(float z);
+ static void putText(const vec2& p, const std::string& s, ...);
+ static void putString(const vec2& p, const std::string& s, float wrap = 0.12345f);
+ static float putStringCentered(const vec2& p, const std::string& s, bool print = true);
- /*
- * Draw a centered string.
- */
+ static void dialogBox(const std::string& n, const std::string& s, ...);
+ static void dialogAddOption(const std::string& o);
+ static void dialogImportant(const std::string& s);
- float putStringCentered(const float x,const float y,std::string s);
+ static void waitForDialog(void);
+ static void advanceDialog(void);
+ static int getDialogResult(void);
+};
- /*
- * Draws a formatted string at the given coordinates.
- */
+namespace ui {
+ // the pixel-coordinates of the mouse
+ extern vec2 mouse;
- float putText(const float x,const float y,const char *str,...);
+ // raw mouse values from SDL
+ extern vec2 premouse;
- /**
- * This function is a facility for logic events to draw text; the text
- * will be prepared then drawn in the render loop.
- */
- void putTextL(vec2 c,const char *str, ...);
+ // shows the debug overlay when set to true
+ extern bool debug;
- /*
- * Creates a dialogBox text string (format: `name`: `text`). This function simply sets up
- * variables that are drawn in ui::draw(). When the dialog box exists player control is
- * limited until a right click is given, closing the box.
- */
+ // shows tracers when set to true (alongside `debug`)
+ extern bool posFlag;
+
+ void initSounds(void);
- void drawBox(vec2 c1, vec2 c2);
void drawNiceBox(vec2 c1, vec2 c2, float z);
void drawNiceBoxColor(vec2 c1, vec2 c2, float z, Color c);
- void dialogBox(std::string name, std::string opt, bool passive, std::string text, ...);
- void closeBox();
- void waitForDialog(void);
bool pageExists(void);
void drawPage(const GLuint& tex);
- void dontTypeOut(void);
- /*
- * Draws a larger string in the center of the screen. Drawing is done inside this function.
- */
-
- void importantText(const char *text,...);
- void passiveImportantText(int duration,const char *text,...);
+ //void importantText(const char *text,...);
+ //void passiveImportantText(int duration,const char *text,...);
/*
* Draw various UI elements (dialogBox, player health)
*/
void draw(void);
- void drawFade(void);
- void fadeUpdate(void);
-
- /*
- * Toggle the black overlay thing.
- */
-
- void toggleBlack(void);
- void toggleBlackFast(void);
- void toggleWhite(void);
- void toggleWhiteFast(void);
- void waitForCover(void);
- void waitForUncover(void);
/*
* Takes a screenshot of the game
*/
void takeScreenshot(GLubyte *pixels);
+
+ bool handleGLEvent(SDL_Event& e);
}
#endif // UI_HPP_
diff --git a/include/ui_quest.hpp b/include/ui_quest.hpp
index a46483a..d9d1708 100644
--- a/include/ui_quest.hpp
+++ b/include/ui_quest.hpp
@@ -27,19 +27,19 @@ namespace ui {
* Draws the quest UI to the screen, if enabled.
*/
void draw(void) {
- static unsigned int textWrap = 40;
+// static unsigned int textWrap = 40;
if (!_toggle)
return;
- std::swap(textWrap, ui::textWrapLimit);
+// std::swap(textWrap, ui::textWrapLimit);
float top_y = offset.y + 200;
ui::drawNiceBox(vec2 {offset.x - 200, top_y },
vec2 {offset.x + 200, offset.y - 200 },
-0.7f);
- ui::putStringCentered(offset.x, top_y - 40, "Current Quests:");
+ UISystem::putStringCentered(vec2(offset.x, top_y - 40), "Current Quests:");
/*auto y = top_y - 100;
const auto x = offset.x - 180;
@@ -50,7 +50,7 @@ namespace ui {
y -= 40;
}*/
- std::swap(textWrap, ui::textWrapLimit);
+// std::swap(textWrap, ui::textWrapLimit);
}
}
}
diff --git a/include/vector2.hpp b/include/vector2.hpp
index beb2787..77ee7e7 100644
--- a/include/vector2.hpp
+++ b/include/vector2.hpp
@@ -35,10 +35,20 @@ struct vector2 {
return vector2<T>(x + v.x, y + v.y);
}
+ template<typename T2>
+ vector2<T> operator+(const vector2<T2>& v) const {
+ return vector2<T>(x + v.x, y + v.y);
+ }
+
vector2<T> operator+(const T& n) const {
return vector2<T>(x + n, y + n);
}
+ vector2<T> operator+=(const vector2<T>& v) {
+ x += v.x, y += v.y;
+ return *this;
+ }
+
// subtraction
vector2<T> operator-(const vector2<T>& v) const {
return vector2<T>(x - v.x, y - v.y);
diff --git a/include/world.hpp b/include/world.hpp
index e47f78f..163676d 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -108,36 +108,38 @@ private:
/**
* The world's data.
*/
- WorldData2 world;
+ static WorldData2 world;
/**
* SDL's object for handling the background music.
*/
- Mix_Music *bgmObj;
- std::string bgmCurrent;
+ static Mix_Music *bgmObj;
+ static std::string bgmCurrent;
/**
* Paths of files to get stylized textures from.
*/
- std::vector<std::string> bgFiles;
+ static std::vector<std::string> bgFiles;
/**
* Allows for iteration between background textures, for rendering.
*/
- TextureIterator bgTex;
+ static TextureIterator bgTex;
/**
* An object to handle and parse world XML files.
*/
- XMLDocument xmlDoc;
+ static XMLDocument xmlDoc;
/**
* The file path to the currently loaded world.
*/
- std::string currentXMLFile;
+ static std::string currentXMLFile;
+
+ static std::vector<vec2> stars;
public:
- std::thread thAmbient;
+ static std::thread thAmbient;
explicit WorldSystem(void);
~WorldSystem(void);
@@ -146,37 +148,32 @@ public:
ev.subscribe<BGMToggleEvent>(*this);
}
- inline XMLDocument* getXML(void)
+ static inline XMLDocument* getXML(void)
{ return &xmlDoc; }
- inline float getWidth(void) const
+ static inline float getWidth(void) //const
{ return world.startX * -2.0f; }
- float isAboveGround(const vec2& p) const;
+ static inline const std::string& getXMLFile(void) //const
+ { return currentXMLFile; }
- void receive(const BGMToggleEvent &bte);
+ static float isAboveGround(const vec2& p); //const;
+ void receive(const BGMToggleEvent &bte);
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
- void render(void);
+ static void render(void);
- inline const std::string& getXMLFile(void) const
- { return currentXMLFile; }
void detect(entityx::TimeDelta dt);
- void goWorldLeft(Position& p);
- void goWorldRight(Position& p, Solid &d);
- void goWorldPortal(Position& p);
-
- // worlddata2 stuff
- WorldData2 worldData;
+ static void goWorldLeft(Position& p);
+ static void goWorldRight(Position& p, Solid &d);
+ static void goWorldPortal(Position& p);
- void generate(int width = 0);
- //void addHole(const unsigned int& start, const unsigned int& end);
- //void addHill(const ivec2& peak, const unsigned int& width);
+ static void generate(int width = 0);
- bool save(void);
- void load(const std::string& file);
+ static bool save(void);
+ static void load(const std::string& file);
void fight(entityx::Entity entity);
};