aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-09-28 08:50:24 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-09-28 08:50:24 -0400
commit7125200e83a9255b8da6745b4a457996705bf263 (patch)
tree52d51815c7112f5195326620ef81907f0147c743
parent82727d2d50d6a71cd5e9d5a7c00fa41888a39eb7 (diff)
parent113bb97e4ce7db5bc275e0dccf7c790c86cda5d7 (diff)
improvements ;)
-rw-r--r--include/common.h3
-rw-r--r--include/entities.h5
-rw-r--r--include/ui.h2
-rw-r--r--src/entities.cpp10
-rw-r--r--src/main.cpp4
-rw-r--r--src/ui.cpp11
6 files changed, 25 insertions, 10 deletions
diff --git a/include/common.h b/include/common.h
index aa175bc..922dd59 100644
--- a/include/common.h
+++ b/include/common.h
@@ -10,7 +10,8 @@
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_opengl.h>
-typedef struct { float x; float y; } vec2;
+typedef struct { float x; float y; } vec2;
+enum _TYPE {STRUCTURET = -1, PLAYERT = 0, NPCT = 1};
#include <entities.h>
diff --git a/include/entities.h b/include/entities.h
index 101fc7a..df81ad2 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -9,7 +9,8 @@ public:
float width;
float height;
float speed;
- int type, subtype;
+ int subtype;
+ _TYPE type;
vec2 loc;
vec2 vel;
bool right,left, canMove;
@@ -41,7 +42,7 @@ class Structures : public Entity{
public:
void *inside;
Structures();
- unsigned int spawn(int, float, float);
+ unsigned int spawn(_TYPE, float, float);
};
#endif // ENTITIES_H
diff --git a/include/ui.h b/include/ui.h
index 8341a8c..dbcee35 100644
--- a/include/ui.h
+++ b/include/ui.h
@@ -7,6 +7,8 @@
namespace ui { // Functions are kept in a namespace simply
// for organization
+ extern vec2 mouse;
+
extern bool debug;
extern unsigned int fontSize;
diff --git a/src/entities.cpp b/src/entities.cpp
index 9808086..c341dba 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -36,7 +36,7 @@ Player::Player(){
width = HLINE * 8;
height = HLINE * 12;
speed = 1;
- type = 0;
+ type = PLAYERT;
subtype = 5;
alive = true;
ground = false;
@@ -50,7 +50,7 @@ NPC::NPC(){
width = HLINE * 8;
height = HLINE * 12;
speed = 1;
- type = 1;
+ type = NPCT;
subtype = 0;
alive = true;
canMove = true;
@@ -61,18 +61,18 @@ void NPC::interact(){
}
Structures::Structures(){
- type = -1;
+ type = STRUCTURET;
speed = 0;
alive = true;
}
-unsigned int Structures::spawn(int t, float x, float y){
+unsigned int Structures::spawn(_TYPE t, float x, float y){
loc.x = x;
loc.y = y;
type = t;
/*VILLAGE*/
- if(type == -1){
+ if(type == STRUCTURET){
loc.y=100;
width = 20 * HLINE;
height = 16 * HLINE;
diff --git a/src/main.cpp b/src/main.cpp
index 6a1650b..a7a8991 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -106,7 +106,7 @@ int main(int argc, char *argv[]){
entity[0]=&build[0];
static unsigned int i;
- build[0].spawn(-1,0,10);
+ build[0].spawn(STRUCTURET,0,10);
build[0].inside=iw;
for(i=0;i<entity.size()+1;i++){
entity[i]->inWorld=test;
@@ -194,7 +194,7 @@ void logic(){
ui::handleEvents();
currentWorld->detect(player);
for(int i=0;i<=entity.size();i++){
- if(entity[i]->alive&&entity[i]->type == 1){
+ if(entity[i]->alive&&entity[i]->type == NPCT){
entity[i]->wander(90, &entity[i]->vel);
//std::cout<<"works"<<i<<std::endl;
}
diff --git a/src/ui.cpp b/src/ui.cpp
index 9b3cdff..ababe3e 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -16,6 +16,7 @@ static bool dialogBoxExists=false;
static const char *dialogBoxText=NULL;
namespace ui {
+ vec2 mouse;
bool debug=false;
unsigned int fontSize;
/*
@@ -132,6 +133,13 @@ namespace ui {
case SDL_QUIT:
gameRunning=false;
break;
+ case SDL_MOUSEMOTION:
+ mouse.x=e.motion.x;
+ mouse.y=e.motion.y;
+ break;
+ /*
+ KEYDOWN
+ */
case SDL_KEYDOWN:
if(SDL_KEY==SDLK_ESCAPE)gameRunning=false; // Exit the game with ESC
if(SDL_KEY==SDLK_a){ // Move left
@@ -167,6 +175,9 @@ namespace ui {
}
break;
+ /*
+ KEYUP
+ */
case SDL_KEYUP:
if(SDL_KEY==SDLK_a)player->vel.x=0; // Stop the player if movement keys are released
if(SDL_KEY==SDLK_d)player->vel.x=0;