]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world physic fixes
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 12 Nov 2015 13:28:27 +0000 (08:28 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 12 Nov 2015 13:28:27 +0000 (08:28 -0500)
Changelog
Makefile
include/world.h
src/Makefile
src/gameplay.cpp
src/world.cpp

index dba1ecfb5c4f8e29d948412eaf1a5343704c79ec..5fa36602b1a5bfb3f89916c8167b140428b5b575 100644 (file)
--- a/Changelog
+++ b/Changelog
        - added drawing/handling of entities on all layers at all times
        - removed building entering/exiting
        - andy broke SDL cuz he's bad
+       
+11/10/2015:
+===========
+
+       - fixed building entering/exiting
+       - prototyped first world for story-line-thing
+       - andy fixes sdl
index 7a7a868ac273b0b1541dc144f286dba1c3b265cf..bbeff1eef73ef30286d5f2cb17134c82ffbd1b15 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
-LIBS = -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
+LIBS = -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
 \r
 WIN_LIBS = -lopengl32 -lglew32 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype\r
 \r
-FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2\r
+FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2\r
 \r
 all:\r
        @rm -f out/*.o\r
index 48ca47b6aceefcbb0e6ba3b700f03077bbbe5ae0..cb40ef63b39ed5466fdcb9b73231fcfe0596ca0b 100644 (file)
@@ -36,10 +36,6 @@ protected:
         
        struct line_t *line;
        
-       /*
-        *      Keeps a dynamically allocated array of platforms in the world.
-       */
-       
        /*
         *      Contains the starting x-coordinate to draw the world at. This should be equal to
         *      - getWidth() (see world.cpp) / 2
@@ -81,7 +77,7 @@ public:
        std::vector<Mob                 *>      mob;
        std::vector<Entity              *>      entity;
        
-       void addStructure(_TYPE t,float x,float y,void *inside);
+       void addStructure(_TYPE t,float x,float y,World *outside,World *inside);
        void addMob(int t,float x,float y);
        void addNPC(float x,float y);
        
index aacef575c2349860915b6724aaef5fba0becdca7..a243846937aa25fecec9f36a614d74e0dbd303ec 100644 (file)
@@ -1,6 +1,6 @@
-LIBS = -lGL -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
+LIBS = -lGL -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
 
-FLAGS = -std=c++11 -I../include -I../include/freetype2
+FLAGS = -m32 -std=c++11 -I../include -I../include/freetype2
 
 OUT = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out\//g'`
 
index c3f3988733953998f6dc25d0529d0b3dffcb2dc5..c1705119b213eb4b6d9fb132fa5a9d1a14578978 100644 (file)
@@ -82,7 +82,8 @@ void initEverything(void){
        
        IndoorWorld *iw=new IndoorWorld();
        iw->generate(200);
-       currentWorld->addStructure(STRUCTURET,(rand()%120*HLINE),10,iw);
+       
+       currentWorld->addStructure(STRUCTURET,(rand()%120*HLINE),10,test,iw);
        
        /*
         *      Spawn a mob. 
index 8c42a81a47c8cf366b6c72f025520fa5b44ad49a..049e49877d49774ea6d7f7170874a9151d795e38 100644 (file)
@@ -471,22 +471,37 @@ void World::singleDetect(Entity *e){
                */
                
                if(e->loc.y < line[i].y){
-                 
-                       e->ground=true;
                        
-                       e->vel.y=0;
-                       e->loc.y=line[i].y - .001 * deltaTime;
+                       /*
+                        *      Check that the entity isn't trying to run through a wall.
+                       */
+                       
+                       if(e->loc.y + e->height > line[i-(int)e->width/2/HLINE].y &&
+                          e->loc.y + e->height > line[i+(int)e->width/2/HLINE].y ){
+                       
+                               e->loc.y=line[i].y - .001 * deltaTime;
+                               e->ground=true;
+                               e->vel.y=0;
+                               
+                       }else{
+                               
+                               /*
+                                *      Push the entity out of the wall if it's trying to go through it.
+                               */
+                               
+                               do{
+                                       e->loc.x+=.001 * e->vel.x>0?-1:1;
+                                       i=(e->loc.x - e->width / 2 - x_start) / HLINE;
+                               }while(line[i].y>e->loc.y+ e->height);
+                               
+                       }
                
                /*
-                *      Otherwise, if the entity is above the line... 
+                *      Handle gravity if the entity is above the line.
                */
                
                }else{
                        
-                       /*
-                        *      Handle gravity.
-                       */
-                       
                        if(e->vel.y > -2)e->vel.y-=.001 * deltaTime;
                        
                }
@@ -510,44 +525,26 @@ void World::singleDetect(Entity *e){
 }
 
 void World::detect(Player *p){
-       World *hey;
        
        /*
         *      Handle the player. 
        */
        
        singleDetect(p);
-       
+               
        /*
         *      Handle all remaining entities in this world. 
        */
        
-        hey = this;
-
-LOOP:
-
-       if(hey->behind){
-               hey=hey->behind;
-               goto LOOP;
-       }
-
-LOOP2:
-       
-       for(auto &e : hey->entity)
+       for(auto &e : entity)
                singleDetect(e);
-               
-       if(hey->infront){
-               hey=hey->infront;
-               goto LOOP2;
-       }
 }
 
-void World::addStructure(_TYPE t,float x,float y,void *inside){
+void World::addStructure(_TYPE t,float x,float y,World *outside,World *inside){
        build.push_back(new Structures());
        build.back()->spawn(t,x,y);
-       build.back()->inside=inside;
-       
-       std::cout<<"inside: "<<build.back()->inside<<" "<<inside<<std::endl;
+       build.back()->inWorld=outside;
+       build.back()->inside=(void *)inside;
        
        entity.push_back(build.back());
 }
@@ -583,7 +580,7 @@ void World::addLayer(unsigned int width){
 World *World::goWorldLeft(Player *p){
        if(toLeft&&p->loc.x<x_start+HLINE*15){
                p->loc.x=toLeft->x_start+getWidth(toLeft)-HLINE*10;
-               p->loc.y=toLeft->line[0].y;
+               p->loc.y=toLeft->line[toLeft->lineCount-GEN_INC-1].y;
                return toLeft;
        }
        return this;
@@ -612,7 +609,26 @@ World *World::goWorldFront(Player *p){
        return this;
 }
 
+std::vector<void *>thing;
 World *World::goInsideStructure(Player *p){
+       if(!thing.size()){
+               for(auto &b : build){
+                       if(p->loc.x            > b->loc.x            &&
+                          p->loc.x + p->width < b->loc.x + b->width ){
+                               thing.push_back(this);
+                               return (World *)b->inside;
+                       }
+               }
+       }else{
+               for(auto &b : ((World *)thing.back())->build){
+                       if(b->inside == this){
+                               World *tmp = (World *)thing.back();
+                               p->loc.x = b->loc.x + (b->width / 2) - (p->width / 2);
+                               thing.erase(thing.end()-1);
+                               return tmp;
+                       }
+               }
+       }
        return this;
 }