#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>
float width;
float height;
float speed;
- int type, subtype;
+ int subtype;
+ _TYPE type;
vec2 loc;
vec2 vel;
bool right,left, canMove;
};
class Structures : public Entity{
public:
- World *inside;
+ void *inside;
Structures();
- unsigned int spawn(int, float, float);
+ unsigned int spawn(_TYPE, float, float);
};
#endif // ENTITIES_H
namespace ui { // Functions are kept in a namespace simply
// for organization
+ extern vec2 mouse;
+
extern bool debug;
extern unsigned int fontSize;
width = HLINE * 8;
height = HLINE * 12;
speed = 1;
- type = 0;
+ type = PLAYERT;
subtype = 5;
alive = true;
ground = false;
width = HLINE * 8;
height = HLINE * 12;
speed = 1;
- type = 1;
+ type = NPCT;
subtype = 0;
alive = true;
canMove = true;
}
Structures::Structures(){
- type = -1;
+ type = STRUCTURET;
speed = 0;
}
-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){
width = 4 * HLINE;
height = 4 * HLINE;
entity[0]=&build[0];
static unsigned int i;
- build[0].spawn(-1,0,10);
- for(i=0;i<entity.size()+1;i++){
+ build[0].spawn(STRUCTURET,0,10);
+ for(i=0;i<=entity.size();i++){
entity[i]->inWorld=test;
}
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;
+ //std::cout<<"works"<<i<<std::endl;
}
}
}
static const char *dialogBoxText=NULL;
namespace ui {
+ vec2 mouse;
bool debug=false;
unsigned int fontSize;
/*
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
}
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;