aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp3
-rw-r--r--src/main.cpp37
-rw-r--r--src/world.cpp27
3 files changed, 40 insertions, 27 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index 9c18313..5da39dd 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -64,7 +64,7 @@ Structures::Structures(){
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;
@@ -86,5 +86,6 @@ void Structures::spawn(int t, float x, float y){
entity[entity.size()]->type = 1;
entity[entity.size()]->spawn(loc.x + (float)(i - 5) / 8,0);
}
+ return entity.size();
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 327bd66..6049d2c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -81,20 +81,41 @@ int main(int argc, char *argv[]){
**** 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){
@@ -157,7 +178,7 @@ void render(){
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;
}
diff --git a/src/world.cpp b/src/world.cpp
index b279f2f..fde75bb 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -50,13 +50,10 @@ World::World(unsigned int width){ // Generates the world and sets all variables
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){
@@ -106,11 +103,10 @@ LOOP2: // Draw each world
}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();
+ }
}
}
@@ -133,11 +129,14 @@ void World::singleDetect(Entity *e){
}
}
}
+
+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]);
}
}
@@ -185,11 +184,3 @@ World *World::goWorldFront(Player *p){
}
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;
- }
-}*/