From 4391f9289b7368765b39c9654d6b0bdf2db8f36b Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 27 Sep 2015 10:35:40 -0400 Subject: added platforms --- src/entities.cpp | 2 +- src/main.cpp | 3 ++- src/ui.cpp | 1 + src/world.cpp | 31 +++++++++++++++++++++++++++---- 4 files changed, 31 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/entities.cpp b/src/entities.cpp index 3c2120b..da28851 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -85,7 +85,7 @@ unsigned int Structures::spawn(int t, float x, float y){ entity[entity.size()] = &npc[npc.size()-1]; entity[entity.size()]->alive=true; entity[entity.size()]->type = 1; - entity[entity.size()]->spawn(loc.x + (float)(i - 5) / 8,0); + entity[entity.size()]->spawn(loc.x + (float)(i - 5) / 8,100); } return entity.size(); } diff --git a/src/main.cpp b/src/main.cpp index 1747915..0ba715f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,7 +89,8 @@ int main(int argc, char *argv[]){ World *test=new World(); test->generate(SCREEN_WIDTH/2); test->addLayer(400); - test->addLayer(100); + test->addLayer(100); + test->addPlatform(150,100,100,10); currentWorld=test; IndoorWorld *iw=new IndoorWorld(); diff --git a/src/ui.cpp b/src/ui.cpp index f849cf8..1e78dca 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -145,6 +145,7 @@ namespace ui { if(SDL_KEY==SDLK_SPACE){ // Jump if(player->ground){ player->vel.y=.25; + //player->loc.y+=HL player->ground=false; } } diff --git a/src/world.cpp b/src/world.cpp index cab9ecb..14df394 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1,4 +1,5 @@ #include +#include #define getWidth(w) ((w->lineCount-GEN_INC)*HLINE) // Calculates the width of world 'w' @@ -100,6 +101,17 @@ LOOP2: // Draw each world cline[i].y-=(yoff-DRAW_Y_OFFSET); // Reset 'cline[i]'`s y to what it was } glEnd(); + for(i=0;iinWorld==current){ + entity[i]->draw(); + ui::putText(entity[i]->loc.x,entity[i]->loc.y,"%d",i); + } + } + glColor3ub(255,0,0); + for(i=0;iplatform.size();i++){ + glRectf(current->platform[i].p1.x,current->platform[i].p1.y, + current->platform[i].p2.x,current->platform[i].p2.y); + } 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. shade-=DRAW_SHADE; @@ -108,10 +120,6 @@ LOOP2: // Draw each world }else{ // Otherwise reset static values and return yoff=DRAW_Y_OFFSET; shade=0; - for(i=0;iinWorld==this) - entity[i]->draw(); - } } } @@ -124,6 +132,18 @@ void World::singleDetect(Entity *e){ e->ground=true; e->loc.y=line[i].y+HLINE/2; }else{ // If the player is above the ground do some gravity stuff + for(i=0;iloc.x+e->width>platform[i].p1.x)&(e->loc.x+e->widthloc.xloc.x>platform[i].p1.x))){ + if(e->loc.y>platform[i].p2.y-HLINE&&e->loc.yvel.y<0){ + e->vel.y=0; + e->loc.y=platform[i].p2.y; + e->ground=true; + } + } + } + } e->vel.y-=.01; } if(e->loc.x