]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
updates ;)
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 25 Sep 2015 20:15:35 +0000 (16:15 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 25 Sep 2015 20:15:35 +0000 (16:15 -0400)
Changelog
include/entities.h
include/world.h
src/entities.cpp
src/main.cpp
src/world.cpp

index a781c550080d7ad6a82f4795e5d97707ff7f66b2..0e6d0a84944699059b0d9b462d3082dc1727ed7f 100644 (file)
--- a/Changelog
+++ b/Changelog
        - 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
+
index e7389dc83bf9ff7ba55fd17119bc164ffad90769..2687c24a78a40cd30790fd1a4c5d94bd7e296dce 100644 (file)
@@ -5,6 +5,7 @@
 
 class Entity{
 public:
+       void *inWorld;
        float width;
        float height;
        float speed;
@@ -15,7 +16,7 @@ public:
        bool alive;
 
        unsigned int texture[];
-
+       
        void spawn(float, float);
        void draw(void);
        void wander(int, vec2*);
@@ -38,7 +39,7 @@ public:
 class Structures : public Entity{
 public:
        Structures();
-       void spawn(int, float, float);
+       unsigned int spawn(int, float, float);
 };
 
 #endif // ENTITIES_H
index 2a1d3c328eb4ae4240d542d04321480b5ad51e32..ff1a3ef24cfe3ad1b25ea0c5ef1343af34f98792 100644 (file)
@@ -3,8 +3,6 @@
 
 #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
 */
@@ -29,8 +27,6 @@ private:
        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
@@ -59,8 +55,7 @@ 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
index 9c18313272a390f3453d7cfb17777fd3e7f1ad69..5da39dd336c4782ceaf8d024b2b49f66823ee42d 100644 (file)
@@ -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();
        }
 }
index 327bd66d722ad99f9f0b245983d9c59ca63e9758..6049d2cb069f9c8bb46a10a89e1791639e98d387 100644 (file)
@@ -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;
        }
index b279f2f67b9aa89c74f2466dba4bab5a38c637d1..fde75bba4f1e57ddee139e34dc0bf96c72e9b3e6 100644 (file)
@@ -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;
-       }
-}*/