From 82727d2d50d6a71cd5e9d5a7c00fa41888a39eb7 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 28 Sep 2015 08:48:38 -0400 Subject: improvements ;) --- Changelog | 10 ++++++++++ include/entities.h | 2 +- include/world.h | 5 ++++- src/entities.cpp | 14 ++++++++------ src/main.cpp | 6 ++---- src/ui.cpp | 1 + src/world.cpp | 24 +++++++++++++++++++++--- 7 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Changelog b/Changelog index 2d138e4..d878ae9 100644 --- a/Changelog +++ b/Changelog @@ -26,3 +26,13 @@ ========== - added a base for indoor areas + +9/28/2015: +========== + + - added dropping from platforms + - added structure entering/exiting + - improved world/entity handling + - fixed NPC generation + - added enumerators for entity types + - improved NPC wandering diff --git a/include/entities.h b/include/entities.h index 78d9a51..101fc7a 100644 --- a/include/entities.h +++ b/include/entities.h @@ -39,7 +39,7 @@ public: }; class Structures : public Entity{ public: - World *inside; + void *inside; Structures(); unsigned int spawn(int, float, float); }; diff --git a/include/world.h b/include/world.h index 0e8dced..50f2483 100644 --- a/include/world.h +++ b/include/world.h @@ -62,7 +62,10 @@ public: // world is drawn the world has to appear directly behind the player) World *goWorldFront(Player *p); // Functions the same as goWorldBack(), but checks/returns the world in front of // this one. - void addPlatform(float x,float y,float w,float h); + World *goInsideStructure(Player *p); // Returns the world contained in a structure if the player is requesting to enter + // it and is standing in front of it. + void addPlatform(float x,float y,float w,float h); // Dynamically adds a platform to the platform array. These will be automatically + // drawn and handled by the world. }; /* 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