From a55903b8784df7c7033983212ca974e472c51dbf Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 11 Sep 2015 22:34:39 -0400 Subject: basic layered worlds :) --- src/UIClass.cpp | 7 +++++++ src/World.cpp | 47 +++++++++++++++++++++++++++++++++++------------ src/main.cpp | 2 ++ 3 files changed, 44 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/UIClass.cpp b/src/UIClass.cpp index 56a9f47..731e387 100644 --- a/src/UIClass.cpp +++ b/src/UIClass.cpp @@ -1,6 +1,7 @@ #include extern Player player; +extern World *currentWorld; void UIClass::handleEvents(){ SDL_Event e; @@ -20,6 +21,12 @@ void UIClass::handleEvents(){ case SDLK_a: ///A player.velg.x = -10; break; + case SDLK_i: + if(currentWorld->behind)currentWorld=currentWorld->behind; + break; + case SDLK_k: + if(currentWorld->infront)currentWorld=currentWorld->infront; + break; default: break; } diff --git a/src/World.cpp b/src/World.cpp index c2dc62d..6b1b317 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -4,7 +4,8 @@ World::World(void){ line=NULL; lineCount=0; - toLeft=toRight=NULL; + toLeft=toRight=behind=infront=NULL; + root=false; } World::World(const float width,World *l,World *r){ unsigned int i; @@ -16,6 +17,8 @@ World::World(const float width,World *l,World *r){ } toLeft=l; toRight=r; + behind=infront=NULL; + root=false; if(toLeft){ if(toLeft->toRight){ std::cout<<"There's already a world to the left!"<draw(); + } + if(root){ + hline=HLINE; + back=0; + } glBegin(GL_QUADS); for(i=0;iyx>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){ v->y=line[i].start; return; - //v->x=(HLINE*i)-1+HLINE; }else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){ v->y=line[i].start; return; - //v->x=(HLINE*i)-1-width; } }else if(v->y>line[i].start+HLINE/4){ v->y-=HLINE/8; @@ -107,4 +120,14 @@ void World::loadFromFile(FILE *f,World *parent){ toRight->loadFromFile(f,toRight); } } - +void World::addLayer(void){ + if(behind){ + behind->addLayer(); + }else{ + behind=new World((lineCount-1)*HLINE+LAYER_SCALE,NULL,NULL); + behind->infront=this; + } +} +void World::setRoot(void){ + root=true; +} diff --git a/src/main.cpp b/src/main.cpp index 67ba8a6..8768edd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,6 +93,8 @@ int main(int argc,char **argv){ w=new World(2,NULL,w2); currentWorld=w; + currentWorld->addLayer(); + currentWorld->setRoot(); // Save the world if necessary /*FILE *f=fopen("world.dat","r"); -- cgit v1.2.3