From 60f685b7b544b94ae1e6212b939cdae5ac12e725 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 28 Sep 2015 08:14:20 -0400 Subject: added dropping from platforms --- src/entities.cpp | 8 +++----- src/main.cpp | 2 +- src/ui.cpp | 4 ++++ src/world.cpp | 15 ++++++++------- 4 files changed, 16 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/entities.cpp b/src/entities.cpp index da28851..140223d 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -50,9 +50,9 @@ NPC::NPC(){ width = HLINE * 8; height = HLINE * 12; speed = 1; - type = 0; + type = 1; subtype = 0; - alive = false; + alive = true; canMove = true; } @@ -78,13 +78,11 @@ unsigned int Structures::spawn(int t, float x, float y){ //int tempN = (getRand() % 5 + 1); int tempN = 2; for(int i=0;ialive=true; - entity[entity.size()]->type = 1; 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 0ba715f..9e029cf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -173,7 +173,7 @@ void render(){ d=deltaTime; debugDiv=0; } - ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nD: %d\nRes: %ux%u",fps,d,SCREEN_WIDTH,SCREEN_HEIGHT); + ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nD: %d G:%d\nRes: %ux%u",fps,d,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT); } ui::draw(); // Draw any UI elements if they need to be diff --git a/src/ui.cpp b/src/ui.cpp index 1e78dca..75bc5ee 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -142,6 +142,10 @@ namespace ui { player->vel.x=.15; currentWorld=currentWorld->goWorldRight(player); } + if(SDL_KEY==SDLK_s && player->ground==2){ + player->ground=false; + player->loc.y-=HLINE*1.5; + } if(SDL_KEY==SDLK_SPACE){ // Jump if(player->ground){ player->vel.y=.25; diff --git a/src/world.cpp b/src/world.cpp index 14df394..a5a6f4a 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -102,7 +102,7 @@ LOOP2: // Draw each world } glEnd(); for(i=0;iinWorld==current){ + if(entity[i]->inWorld==this){ entity[i]->draw(); ui::putText(entity[i]->loc.x,entity[i]->loc.y,"%d",i); } @@ -127,11 +127,7 @@ void World::singleDetect(Entity *e){ unsigned int i; if(e->alive){ i=(e->loc.x+e->width/2-x_start)/HLINE; // Calculate what line the player is currently on - if(e->loc.y<=line[i].y){ // Snap the player to the top of that line if the player is inside it - e->vel.y=0; - e->ground=true; - e->loc.y=line[i].y+HLINE/2; - }else{ // If the player is above the ground do some gravity stuff + if(e->loc.y>line[i].y){ // Snap the player to the top of that line if the player is inside it for(i=0;iloc.x+e->width>platform[i].p1.x)&(e->loc.x+e->widthloc.xloc.x>platform[i].p1.x))){ @@ -139,12 +135,17 @@ void World::singleDetect(Entity *e){ if(e->vel.y<0){ e->vel.y=0; e->loc.y=platform[i].p2.y; - e->ground=true; + e->ground=2; + return; } } } } e->vel.y-=.01; + }else{ + e->vel.y=0; + e->ground=true; + e->loc.y=line[i].y+HLINE/2; } if(e->loc.xvel.x=0; -- cgit v1.2.3