diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-12 08:28:27 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-12 08:28:27 -0500 |
commit | ac52ecab5df8382b51d48a9431f672bfc502a400 (patch) | |
tree | 461471432d4233da40283f3cac12737ee35b7045 | |
parent | a075f1b6c2c65570ab7b249b12efefcfcc442e95 (diff) |
world physic fixes
-rw-r--r-- | Changelog | 7 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | include/world.h | 6 | ||||
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/gameplay.cpp | 3 | ||||
-rw-r--r-- | src/world.cpp | 82 |
6 files changed, 63 insertions, 43 deletions
@@ -266,3 +266,10 @@ - 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 @@ -1,8 +1,8 @@ -LIBS = -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
+LIBS = -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
WIN_LIBS = -lopengl32 -lglew32 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
-FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2
+FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2
all:
@rm -f out/*.o
diff --git a/include/world.h b/include/world.h index 48ca47b..cb40ef6 100644 --- a/include/world.h +++ b/include/world.h @@ -37,10 +37,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); diff --git a/src/Makefile b/src/Makefile index aacef57..a243846 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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'` diff --git a/src/gameplay.cpp b/src/gameplay.cpp index c3f3988..c170511 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -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. diff --git a/src/world.cpp b/src/world.cpp index 8c42a81..049e498 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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; } |