aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/common.hpp13
-rw-r--r--include/entities.hpp47
-rw-r--r--include/ui.hpp62
-rw-r--r--include/ui_menu.hpp63
-rw-r--r--include/world.hpp6
5 files changed, 116 insertions, 75 deletions
diff --git a/include/common.hpp b/include/common.hpp
index c9837dd..a62d75a 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -35,6 +35,19 @@ typedef unsigned int uint;
#undef near
#endif
+/**
+ * Defines how many game ticks should occur in one second, affecting how often
+ * game logic is handled.
+ */
+
+#define TICKS_PER_SEC 20
+
+/**
+ * Defines how many milliseconds each game tick will take.
+ */
+
+#define MSEC_PER_TICK ( 1000 / TICKS_PER_SEC )
+
//#define SEGFAULT
/**
diff --git a/include/entities.hpp b/include/entities.hpp
index 3bc2f98..5ab4066 100644
--- a/include/entities.hpp
+++ b/include/entities.hpp
@@ -56,15 +56,7 @@ class Trade{
public:
std::string item[2];
int quantity[2];
- Trade(int qo, const char* o, int qt, const char* t){
- item[0] = o;
- item[1] = t;
-
- quantity[0] = qo;
- quantity[1] = qt;
-
- std::cout << "Trading: " << quantity[0] << " " << item[0] << " for " << quantity[1] << " " << item[1] << std::endl;
- }
+ Trade(int qo, std::string o, int qt, std::string t);
Trade(){}
};
@@ -75,8 +67,7 @@ public:
vec2 loc;
float width;
float height;
- float velx;
- float vely;
+ vec2 vel;
Color color;
vec2 index;
float duration;
@@ -84,25 +75,25 @@ public:
bool fountain;
bool gravity;
bool behind;
+ bool bounce;
Particles(float x, float y, float w, float h, float vx, float vy, Color c, float d){
loc.x = x;
loc.y = y;
+ vel.x = vx;
+ vel.y = vy;
width = w;
height = h;
- velx = vx;
- vely = vy;
color = c;
duration = d;
fountain = false;
gravity = true;
behind = false;
+ bounce = false;
index = Texture::getIndex(c);
}
~Particles(){
-
}
void draw(){
- //glEnable(GL_TEXTURE_2D);
glColor3ub(255,255,255);
glBegin(GL_QUADS);
glTexCoord2f(.25*index.x, .125*index.y); glVertex2i(loc.x, loc.y);
@@ -110,15 +101,23 @@ public:
glTexCoord2f(.25*index.x, .125*index.y); glVertex2i(loc.x + width, loc.y + height);
glTexCoord2f(.25*index.x, .125*index.y); glVertex2i(loc.x, loc.y + width);
glEnd();
- //glDisable(GL_TEXTURE_2D);
- //glUseProgram(0);
+ }
+ void update( float _gravity, float ground_y ) {
+ // handle ground collision
+ if ( loc.y < ground_y ) {
+ loc.y = ground_y;
+ if ( bounce ) {
+ vel.y *= -0.2f;
+ vel.x /= 4;
+ } else {
+ vel.x = vel.y = 0;
+ canMove = false;
+ }
+ } else if ( gravity && vel.y > -1 )
+ vel.y -= _gravity * deltaTime;
}
bool kill(float delta){
- duration -= delta;
- if(duration <= 0.0f){
- return true;
- }
- else return false;
+ return (duration -= delta) <= 0;
}
};
@@ -141,6 +140,8 @@ public:
float speed; // A speed factor for X movement
+ unsigned int hitCooldown;
+
/*
* Movement flags
*/
@@ -229,7 +230,7 @@ public:
virtual void wander(int);
};
-class Merchant : public NPC{
+class Merchant : public NPC {
public:
std::vector<Trade>trade;
uint currTrade;
diff --git a/include/ui.hpp b/include/ui.hpp
index 0142f6f..6fa2451 100644
--- a/include/ui.hpp
+++ b/include/ui.hpp
@@ -11,54 +11,16 @@
#include <config.hpp>
#include <world.hpp>
+#include <ui_menu.hpp>
+
#include <ft2build.h>
#include <SDL2/SDL_opengl.h>
#include <thread>
#include FT_FREETYPE_H
-#define DEBUG
+#define SDL_KEY e.key.keysym.sym
-typedef void(*menuFunc)();
-
-struct menuItem{
- int member;
- union{
- struct{
- vec2 loc;
- dim2 dim;
- Color color;
- const char* text;
- menuFunc func;
- }button;
- struct{
- vec2 loc;
- dim2 dim;
- Color color;
- float minValue;
- float maxValue;
- const char* text;
- float* var;
-
- float sliderLoc;
- }slider;
- };
-};
-
-class Menu{
-public:
- std::vector<menuItem>items;
- Menu *child;
- Menu *parent;
- ~Menu(){
- child = NULL;
- parent = NULL;
- delete child;
- delete parent;
- }
-
- void gotoChild();
- void gotoParent();
-};
+#define DEBUG
typedef uint8_t BYTE;
typedef uint16_t WORD;
@@ -87,15 +49,13 @@ typedef struct{
} __attribute__ ((packed)) BITMAPINFOHEADER;
namespace ui {
- menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f);
- menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t);
- 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);
+
/**
* Contains the coordinates of the mouse inside the window.
*/
extern vec2 mouse;
+ extern vec2 premouse;
/*
* These flags are used elsewhere.
@@ -154,9 +114,11 @@ namespace ui {
void merchantBox();
void closeBox();
void waitForDialog(void);
- bool pageExists( void );
+ bool pageExists( void );
void drawPage( std::string path );
+
+ void dontTypeOut( void );
/*
* Draws a larger string in the center of the screen. Drawing is done inside this function.
*/
@@ -170,12 +132,8 @@ namespace ui {
void draw(void);
-
- /*
- * Draw various menu items
- */
void quitGame();
- void drawMenu(Menu* menu);
+
/*
diff --git a/include/ui_menu.hpp b/include/ui_menu.hpp
new file mode 100644
index 0000000..9a51739
--- /dev/null
+++ b/include/ui_menu.hpp
@@ -0,0 +1,63 @@
+#ifndef UI_MENU_H_
+#define UI_MENU_H_
+
+#include <common.hpp>
+#include <config.hpp>
+
+typedef void (*menuFunc)(void);
+
+struct menuItem {
+ int member;
+ union {
+ struct {
+ vec2 loc;
+ dim2 dim;
+ Color color;
+
+ const char *text;
+ menuFunc func;
+ } button;
+ struct {
+ vec2 loc;
+ dim2 dim;
+ Color color;
+
+ float minValue;
+ float maxValue;
+ float sliderLoc;
+
+ const char *text;
+ float *var;
+ } slider;
+ };
+};
+
+class Menu {
+public:
+ std::vector<menuItem> items;
+ Menu *child, *parent;
+
+ ~Menu() {
+ // TODO you CANNOT delete null pointers!
+ /*child = NULL;
+ parent = NULL;
+ delete child;
+ delete parent;*/
+ }
+
+ void gotoChild(void);
+ void gotoParent(void);
+};
+
+namespace ui {
+ namespace menu {
+ menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f);
+ menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t);
+ 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 draw( void );
+ }
+}
+
+#endif // UI_MENU_H_
diff --git a/include/world.hpp b/include/world.hpp
index 40e4a38..cae3808 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -20,6 +20,12 @@
#define PLAYER_SPEED_CONSTANT 0.15f
/**
+ * Gravity thing
+ */
+
+#define GRAVITY_CONSTANT 0.001f
+
+/**
* Defines how many game ticks it takes for a day to elapse.
*/