- added dialog boxes and a key binding to acknoledge them (make them disappear)
- added a togglable debug overlay thing (F3)
- added villages
+
+9/24/2015:
+==========
+
+ - improved entity binding
+ - added structures, villagers, and a basic villager AI
+
class Entity{
public:
+ void *inWorld;
float width;
float height;
float speed;
bool alive;
unsigned int texture[];
-
+
void spawn(float, float);
void draw(void);
void wander(int, vec2*);
class Structures : public Entity{
public:
Structures();
- void spawn(int, float, float);
+ unsigned int spawn(int, float, float);
};
#endif // ENTITIES_H
#include <common.h> // For HLINE, vec2, OpenGL utilities, etc.
-//#define WORLD_ENTITY_MAX 64 // Maximum number of entities that can be bound to a world
-
/*
* World - creates and handles an area of land
*/
int x_start; // Worlds are centered on the x axis (0,n), this contains
// where to start drawing the world to have it centered properly.
World *behind,*infront; // Pointers to other areas of land that are behind or in front of this one, respectively.
- //Entity **peeps; // Stores pointers to entities that are bound to the world
- //unsigned int peepCount; // Number of entities bound to the world
void singleDetect(Entity *e);
public:
World *toLeft,*toRight; // Pointers to areas to the left and right of this world. These are made public
// world is drawn the world has to appear directly behind the player)
World *goWorldFront(Player *p); // Functions the same as goWorldBack(), but checks/returns the world in front of
// this one.
-
- //void addEntity(Entity *e); // Binds an entity to this world (this world will then handle its drawing and detection)
+
};
#endif // WORLD_H
speed = 0;
}
-void Structures::spawn(int t, float x, float y){
+unsigned int Structures::spawn(int t, float x, float y){
loc.x = x;
loc.y = y;
type = t;
entity[entity.size()]->type = 1;
entity[entity.size()]->spawn(loc.x + (float)(i - 5) / 8,0);
}
+ return entity.size();
}
}
**** GAMELOOP ****
**************************/
- World *test =new World(SCREEN_WIDTH/2),
- *test2=new World(SCREEN_WIDTH*2);
+ //************************************************************************//
+ // WORLD GENERATION STUFF //
+ //************************************************************************//
+
+ // Make a world
+ World *test =new World(SCREEN_WIDTH/2);
test->addLayer(400);
- test->addLayer(100);
- test->toLeft=test2;
- test2->toRight=test;
+ test->addLayer(100);
currentWorld=test;
+
+ // Make the player
player=new Player();
player->spawn(0,100);
-
- entity.push_back(new Entity());//create the blank first element for the player;
+
+ // Make structures
+ entity.push_back(new Entity());
build.push_back(Structures());
entity[0]=&build[0];
+
+ static unsigned int i;
build[0].spawn(-1,0,10);
+ for(i=0;i<entity.size()+1;i++){
+ entity[i]->inWorld=test;
+ }
+ for(i=0;i<entity.size();i++){
+ std::cout<<(unsigned)&*entity[i]<<std::endl;
+ }
+ std::cout<<std::endl;
+ for(i=0;i<npc.size();i++){
+ std::cout<<(unsigned)&npc[i]<<std::endl;
+ }
+
+ //************************************************************************//
+ // END WORLD GENERATION STUFF //
+ //************************************************************************//
currentTime=millis();
while(gameRunning){
ui::draw(); // Draw any UI elements if they need to be
for(int i=0;i<=entity.size();i++){
- entity[i]->draw();
+ //entity[i]->draw();
entity[i]->loc.x += entity[i]->vel.x * deltaTime;
entity[i]->loc.y += entity[i]->vel.y * deltaTime;
}
x_start=0-getWidth(this)/2+GEN_INC/2*HLINE; // Calculate x_start (explained in world.h)
behind=infront=NULL; // Set pointers to other worlds to NULL
toLeft=toRight=NULL; // to avoid accidental calls to goWorld... functions
- //peeps=(Entity **)calloc(WORLD_ENTITY_MAX+1,sizeof(Entity *)); // peeps[0] is reserved for the player when detect() is called
- //peepCount=0;
}
World::~World(void){
free(line); // Free (de-allocate) the array 'line'
- //free(peeps); // same for the entity array
}
void World::draw(vec2 *vec){
}else{ // Otherwise reset static values and return
yoff=DRAW_Y_OFFSET;
shade=0;
- /*if(peepCount){
- for(i=1;i<peepCount;i++){
- peeps[i]->draw();
- }
- }*/
+ for(i=0;i<entity.size()+1;i++){
+ if(entity[i]->inWorld==this)
+ entity[i]->draw();
+ }
}
}
}
}
}
+
+extern unsigned int newEntityCount;
void World::detect(Player *p){
unsigned int i;
singleDetect(p);
- for(i=0;i<=entity.size();i++){
- singleDetect(entity[i]);
+ for(i=0;i<entity.size()+1;i++){
+ if(entity[i]->inWorld==this)
+ singleDetect(entity[i]);
}
}
}
return this;
}
-
-/*void World::addEntity(Entity *e){
- if(peepCount!=WORLD_ENTITY_MAX){
- peeps[1+peepCount++]=e; // See peeps's allocation in World() for explanation of the 1+...
- }else{
- std::cout<<"Warning: can't add any more entities"<<std::endl;
- }
-}*/