aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-04-24 09:53:48 -0400
committerClyne Sullivan <tullivan99@gmail.com>2016-04-24 09:53:48 -0400
commit2473bc452959f1c84b03c4b9202d601b3325143d (patch)
treeda66fe0ca2dc01308c7d7e5271090afa25dc99aa /include
parentcc2230e0039f06a7478878adcbc9ef028a223243 (diff)
library-ized ticks
Diffstat (limited to 'include')
-rw-r--r--include/common.hpp16
-rw-r--r--include/entities.hpp50
-rw-r--r--include/gametime.hpp16
-rw-r--r--include/ui.hpp107
-rw-r--r--include/ui_menu.hpp2
5 files changed, 89 insertions, 102 deletions
diff --git a/include/common.hpp b/include/common.hpp
index 9211d56..7f36be2 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -224,22 +224,10 @@ extern float VOLUME_SFX;
#define PI 3.1415926535
-/**
- * References the variable in main.cpp, used for smoother drawing.
- */
-
-extern unsigned int deltaTime;
-
-/**
- * References the variable in main.cpp, used for drawing with the player.
- */
-
+// references the variable in main.cpp, used for drawing with the player
extern vec2 offset;
-/**
- * Counts the number of times logic() (see main.cpp) has been called, for animating
- * sprites.
- */
+// counts the number of times logic() (see main.cpp) has been called, for animating sprites
extern unsigned int loops;
extern GLuint shaderProgram;
diff --git a/include/entities.hpp b/include/entities.hpp
index 460dc93..720141c 100644
--- a/include/entities.hpp
+++ b/include/entities.hpp
@@ -156,61 +156,19 @@ public:
bool bounce;
// creates a particle with the desired characteristics
- Particles(float x, float y, float w, float h, float vx, float vy, Color c, float d){
- loc = vec2 {x, y};
- vel = vec2 {vx, vy};
- width = w;
- height = h;
- color = c;
- duration = d;
- gravity = true;
- fountain = false;
- behind = false;
- bounce = false;
- index = Texture::getIndex(c);
- }
+ Particles(float x, float y, float w, float h, float vx, float vy, Color c, float d);
// allows the particle to be destroyed
~Particles(void){}
// draws the particle
- void draw(void) const {
- glColor3ub(255, 255, 255);
- glBegin(GL_QUADS);
- vec2 tc = vec2 {0.25f * index.x, 0.125f * index.y};
- glTexCoord2f(tc.x, tc.y); glVertex2i(loc.x , loc.y);
- glTexCoord2f(tc.x, tc.y); glVertex2i(loc.x + width, loc.y);
- glTexCoord2f(tc.x, tc.y); glVertex2i(loc.x + width, loc.y + height);
- glTexCoord2f(tc.x, tc.y); glVertex2i(loc.x , loc.y + height);
- glEnd();
- }
+ void draw(void) const;
// updates a particle
- void update(float _gravity, float ground_y) {
- // handle ground collision
- if (loc.y < ground_y) {
- loc.y = ground_y;
-
- // handle bounce
- if (bounce) {
- vel.y *= -0.2f;
- vel.x /= 4.0f;
- } else {
- vel = 0.0f;
- canMove = false;
- }
- }
-
- // handle gravity
- else if (gravity && vel.y > -1.0f) {
- vel.y -= _gravity * deltaTime;
- }
- }
+ void update(float _gravity, float ground_y);
// returns true if the particle should be killed
- bool kill(float delta) {
- return (duration -= delta) <= 0;
- }
+ bool kill(float delta);
};
/**
diff --git a/include/gametime.hpp b/include/gametime.hpp
new file mode 100644
index 0000000..c2991d2
--- /dev/null
+++ b/include/gametime.hpp
@@ -0,0 +1,16 @@
+#ifndef GAMETIME_H_
+#define GAMETIME_H_
+
+namespace gtime {
+ 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 mainLoopHandler(void);
+}
+
+#endif // GAMETIME_H_
diff --git a/include/ui.hpp b/include/ui.hpp
index 477c9c3..9e69497 100644
--- a/include/ui.hpp
+++ b/include/ui.hpp
@@ -1,67 +1,88 @@
-/** @file ui.h
- * @brief Contains functions for handling the user interface.
- */
-
+/* ----------------------------------------------------------------------------
+** The user interface system.
+**
+** This file contains everything user-interface related.
+** --------------------------------------------------------------------------*/
#ifndef UI_H
#define UI_H
-#include <common.hpp>
-#include <inventory.hpp>
+#define DEBUG
+#define SDL_KEY e.key.keysym.sym
+
+/* ----------------------------------------------------------------------------
+** Includes section
+** --------------------------------------------------------------------------*/
+
+// standard library headers
#include <cstdarg>
+#include <cstdint>
+#include <thread>
+// local game headers
+#include <common.hpp>
#include <config.hpp>
-#include <world.hpp>
-
+#include <inventory.hpp>
#include <ui_menu.hpp>
#include <ui_action.hpp>
+#include <world.hpp>
-#include <ft2build.h>
-#include FT_FREETYPE_H
-
+// local library headers
#include <SDL2/SDL_opengl.h>
-#include <thread>
-#define SDL_KEY e.key.keysym.sym
+#include <ft2build.h>
+#include FT_FREETYPE_H
-#define DEBUG
+/* ----------------------------------------------------------------------------
+** Structures section
+** --------------------------------------------------------------------------*/
-typedef struct{
- uint16_t bfType;
- uint32_t bfSize;
- uint16_t bfReserved1, bfReserved2;
- uint32_t bfOffBits; //how many bytes before the image data
-} __attribute__ ((packed)) BITMAPFILEHEADER;
-
-typedef struct{
- uint32_t biSize; //size of header in bytes
- int32_t biWidth;
- int32_t biHeight;
- uint16_t biPlanes;
- uint16_t biBitCount; //how many bits are in a pixel
- uint32_t biCompression;
- uint32_t biSizeImage; //size of image in bytes
- int32_t biXPelsPerMeter;
- int32_t biYPelsPerMeter;
- uint32_t biClrUsed; //how many colors there are
- uint32_t biClrImportant; //important colors
-} __attribute__ ((packed)) BITMAPINFOHEADER;
+/**
+ * Defines the layout of a bitmap (.bmp) file's header.
+ */
+typedef struct {
+ uint16_t bfType;
+ uint32_t bfSize;
+ uint16_t bfReserved1;
+ uint16_t bfReserved2;
+ uint32_t bfOffBits;
+} __attribute__((packed)) BITMAPFILEHEADER;
+
+/**
+ * Defines the layout of a bitmap's info header.
+ */
+typedef struct {
+ uint32_t biSize;
+ int32_t biWidth;
+ int32_t biHeight;
+ uint16_t biPlanes;
+ uint16_t biBitCount;
+ uint32_t biCompression;
+ uint32_t biSizeImage;
+ int32_t biXPelsPerMeter;
+ int32_t biYPelsPerMeter;
+ uint32_t biClrUsed;
+ uint32_t biClrImportant;
+} __attribute__((packed)) BITMAPINFOHEADER;
+
+/* ----------------------------------------------------------------------------
+** The UI namespace
+** --------------------------------------------------------------------------*/
namespace ui {
- /**
- * Contains the coordinates of the mouse inside the window.
- */
-
+ // the pixel-coordinates of the mouse
extern vec2 mouse;
- extern vec2 premouse;
- /*
- * These flags are used elsewhere.
- */
+ // raw mouse values from SDL
+ extern vec2 premouse;
+ // the currently used font size for text rendering
extern unsigned int fontSize;
+ // shows the debug overlay when set to true
extern bool debug;
+
+ // shows tracers when set to true (alongside `debug`)
extern bool posFlag;
extern unsigned char dialogOptChosen;
@@ -130,6 +151,8 @@ namespace ui {
*/
void draw(void);
+ void drawFade(void);
+ void fadeUpdate(void);
void quitGame();
diff --git a/include/ui_menu.hpp b/include/ui_menu.hpp
index f9ce397..1ec7ff3 100644
--- a/include/ui_menu.hpp
+++ b/include/ui_menu.hpp
@@ -67,6 +67,8 @@ namespace ui {
menuItem createParentButton(vec2 l, dim2 d, Color c, const char* t);
menuItem createSlider(vec2 l, dim2 d, Color c, float min, float max, const char* t, float* v);
+ void init(void);
+ void toggle(void);
void draw(void);
}
}