]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
improvements ;)
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 28 Sep 2015 12:48:38 +0000 (08:48 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 28 Sep 2015 12:48:38 +0000 (08:48 -0400)
Changelog
include/entities.h
include/world.h
src/entities.cpp
src/main.cpp
src/ui.cpp
src/world.cpp

index 2d138e4ac61e626d851bf53ae557d044b1ed7aad..d878ae92f28e852a5c21d3008871d24f05b6bb06 100644 (file)
--- a/Changelog
+++ b/Changelog
 ==========
 
        - added a base for indoor areas
+
+9/28/2015:
+==========
+
+       - added dropping from platforms
+       - added structure entering/exiting
+       - improved world/entity handling
+       - fixed NPC generation
+       - added enumerators for entity types
+       - improved NPC wandering
index 78d9a51039c68e45a4453934fe3993fcf9a4ed31..101fc7a9a199634b1cf0f8c330ed298ea9661845 100644 (file)
@@ -39,7 +39,7 @@ public:
 };
 class Structures : public Entity{
 public:
-       World *inside;
+       void *inside;
        Structures();
        unsigned int spawn(int, float, float);
 };
index 0e8dced482e3d1611c480b32a30cdd8730c92eed..50f2483643ad397eafc3e4772bdcee992b31de8b 100644 (file)
@@ -62,7 +62,10 @@ 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 addPlatform(float x,float y,float w,float h);      
+       World *goInsideStructure(Player *p);                            // Returns the world contained in a structure if the player is requesting to enter
+                                                                                                               // it and is standing in front of it.
+       void addPlatform(float x,float y,float w,float h);      // Dynamically adds a platform to the platform array. These will be automatically
+                                                                                                               // drawn and handled by the world.
 };
 
 /*
index e93f23a7e1f344e30f10f7b21111ef1474a4f10e..980808633975fb072086088c66d8887de5ea9be1 100644 (file)
@@ -63,6 +63,7 @@ void NPC::interact(){
 Structures::Structures(){
        type = -1;
        speed = 0;
+       alive = true;
 }
 
 unsigned int Structures::spawn(int t, float x, float y){
@@ -72,20 +73,21 @@ unsigned int Structures::spawn(int t, float x, float y){
 
        /*VILLAGE*/
        if(type == -1){
-               width =  4 * HLINE;
-               height = 4 * HLINE;
+               loc.y=100;
+               width =  20 * HLINE;
+               height = 16 * HLINE;
 
                //int tempN = (getRand() % 5 + 1);
                int tempN = 2;
                for(int i=0;i<tempN;i++){
                        entity.push_back(new NPC());
                        npc.push_back(NPC());
-                       std::cout<<"NPC:"<<npc.size()<<std::endl;
-                       std::cout<<"Entity:"<<entity.size()<<std::endl;
+                       //std::cout<<"NPC:"<<npc.size()<<std::endl;
+                       //std::cout<<"Entity:"<<entity.size()<<std::endl;
                        entity[entity.size()] = &npc[npc.size()-1];
                        entity[entity.size()-1]->spawn(loc.x + (float)(i - 5) / 8,100);
-                       std::cout<<"Entity Type["<<entity.size()<<"]: "<<entity[entity.size()]->type<<std::endl;
-                       std::cout<<"Entity Life["<<entity.size()<<"]: "<<entity[entity.size()]->alive<<std::endl;
+                       //std::cout<<"Entity Type["<<entity.size()<<"]: "<<entity[entity.size()]->type<<std::endl;
+                       //std::cout<<"Entity Life["<<entity.size()<<"]: "<<entity[entity.size()]->alive<<std::endl;
                }
                return entity.size();
        }
index 1e8b942d2d7b209e013604f219c1c22eef1d48b6..6a1650b246a6f99a51f45e4f025e700a615daaed 100644 (file)
@@ -96,9 +96,6 @@ int main(int argc, char *argv[]){
        IndoorWorld *iw=new IndoorWorld();
        iw->generate(200);
        
-       test->toRight=iw;
-       iw->toLeft=test;
-       
        // Make the player
        player=new Player();
        player->spawn(0,100);
@@ -110,6 +107,7 @@ int main(int argc, char *argv[]){
        
        static unsigned int i;
        build[0].spawn(-1,0,10);
+       build[0].inside=iw;
        for(i=0;i<entity.size()+1;i++){
                entity[i]->inWorld=test;
        }
@@ -198,7 +196,7 @@ void logic(){
        for(int i=0;i<=entity.size();i++){
                if(entity[i]->alive&&entity[i]->type == 1){
                        entity[i]->wander(90, &entity[i]->vel);
-                       std::cout<<"works"<<i<<std::endl;
+                       //std::cout<<"works"<<i<<std::endl;
                }
        }
 }
index 75bc5ee15f62fe0694f01c913a82dae7d7dbbc28..9b3cdffd01680a7b402a5f139b90133e094f2959 100644 (file)
@@ -146,6 +146,7 @@ namespace ui {
                                        player->ground=false;
                                        player->loc.y-=HLINE*1.5;
                                }
+                               if(SDL_KEY==SDLK_w)currentWorld=currentWorld->goInsideStructure(player);
                                if(SDL_KEY==SDLK_SPACE){                                                                                        // Jump
                                        if(player->ground){
                                                player->vel.y=.25;
index a5a6f4ac44b344d41180792310f981326fcbe65d..9f60a4aac76109006abf2523af9f4df34cf1b5a9 100644 (file)
@@ -107,10 +107,10 @@ LOOP2:                                                                                                    // Draw each world
                        ui::putText(entity[i]->loc.x,entity[i]->loc.y,"%d",i);
                }
        }
-       glColor3ub(255,0,0);
+       safeSetColor(255+shade*2,0+shade,0+shade);
        for(i=0;i<current->platform.size();i++){
-               glRectf(current->platform[i].p1.x,current->platform[i].p1.y,
-                               current->platform[i].p2.x,current->platform[i].p2.y);
+               glRectf(current->platform[i].p1.x,current->platform[i].p1.y+yoff-DRAW_Y_OFFSET,
+                               current->platform[i].p2.x,current->platform[i].p2.y+yoff-DRAW_Y_OFFSET);
        }
        if(current->infront){                   // If there's a world in front of the one that was just drawn
                yoff-=DRAW_Y_OFFSET;            // draw it as well.
@@ -217,6 +217,24 @@ void World::addPlatform(float x,float y,float w,float h){
        platform.push_back((Platform){{x,y},{x+w,y+h}});
 }
 
+World *World::goInsideStructure(Player *p){
+       unsigned int i;
+       for(i=0;i<entity.size();i++){
+               if(entity[i]->type==-1){
+                       if(entity[i]->inWorld==this){
+                               if(p->loc.x>entity[i]->loc.x&&p->loc.x+p->width<entity[i]->loc.x+entity[i]->width){
+                                       return (World *)((Structures *)entity[i])->inside;
+                               }
+                       }else if(((Structures *)entity[i])->inside==this){
+                               p->loc.x=entity[i]->loc.x+entity[i]->width/2-p->width/2;
+                               p->loc.y=entity[i]->loc.y+HLINE;
+                               return (World *)entity[i]->inWorld;
+                       }
+               }
+       }
+       return this;
+}
+
 
 
 IndoorWorld::IndoorWorld(void){