From 82727d2d50d6a71cd5e9d5a7c00fa41888a39eb7 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 28 Sep 2015 08:48:38 -0400 Subject: improvements ;) --- src/entities.cpp | 14 ++++++++------ src/main.cpp | 6 ++---- src/ui.cpp | 1 + src/world.cpp | 24 +++++++++++++++++++++--- 4 files changed, 32 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/entities.cpp b/src/entities.cpp index e93f23a..9808086 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -63,6 +63,7 @@ void NPC::interact(){ Structures::Structures(){ type = -1; speed = 0; + alive = true; } unsigned int Structures::spawn(int t, float x, float y){ @@ -72,20 +73,21 @@ unsigned int Structures::spawn(int t, float x, float y){ /*VILLAGE*/ if(type == -1){ - width = 4 * HLINE; - height = 4 * HLINE; + loc.y=100; + width = 20 * HLINE; + height = 16 * HLINE; //int tempN = (getRand() % 5 + 1); int tempN = 2; for(int i=0;ispawn(loc.x + (float)(i - 5) / 8,100); - std::cout<<"Entity Type["<type<alive<type<alive<generate(200); - test->toRight=iw; - iw->toLeft=test; - // Make the player player=new Player(); player->spawn(0,100); @@ -110,6 +107,7 @@ int main(int argc, char *argv[]){ static unsigned int i; build[0].spawn(-1,0,10); + build[0].inside=iw; for(i=0;iinWorld=test; } @@ -198,7 +196,7 @@ void logic(){ for(int i=0;i<=entity.size();i++){ if(entity[i]->alive&&entity[i]->type == 1){ entity[i]->wander(90, &entity[i]->vel); - std::cout<<"works"<ground=false; player->loc.y-=HLINE*1.5; } + if(SDL_KEY==SDLK_w)currentWorld=currentWorld->goInsideStructure(player); if(SDL_KEY==SDLK_SPACE){ // Jump if(player->ground){ player->vel.y=.25; diff --git a/src/world.cpp b/src/world.cpp index a5a6f4a..9f60a4a 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -107,10 +107,10 @@ LOOP2: // Draw each world ui::putText(entity[i]->loc.x,entity[i]->loc.y,"%d",i); } } - glColor3ub(255,0,0); + safeSetColor(255+shade*2,0+shade,0+shade); 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); + glRectf(current->platform[i].p1.x,current->platform[i].p1.y+yoff-DRAW_Y_OFFSET, + current->platform[i].p2.x,current->platform[i].p2.y+yoff-DRAW_Y_OFFSET); } 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. @@ -217,6 +217,24 @@ void World::addPlatform(float x,float y,float w,float h){ platform.push_back((Platform){{x,y},{x+w,y+h}}); } +World *World::goInsideStructure(Player *p){ + unsigned int i; + for(i=0;itype==-1){ + if(entity[i]->inWorld==this){ + if(p->loc.x>entity[i]->loc.x&&p->loc.x+p->widthloc.x+entity[i]->width){ + return (World *)((Structures *)entity[i])->inside; + } + }else if(((Structures *)entity[i])->inside==this){ + p->loc.x=entity[i]->loc.x+entity[i]->width/2-p->width/2; + p->loc.y=entity[i]->loc.y+HLINE; + return (World *)entity[i]->inWorld; + } + } + } + return this; +} + IndoorWorld::IndoorWorld(void){ -- cgit v1.2.3