aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog10
-rw-r--r--include/entities.h2
-rw-r--r--include/world.h5
-rw-r--r--src/entities.cpp14
-rw-r--r--src/main.cpp6
-rw-r--r--src/ui.cpp1
-rw-r--r--src/world.cpp24
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;i<tempN;i++){
entity.push_back(new NPC());
npc.push_back(NPC());
- std::cout<<"NPC:"<<npc.size()<<std::endl;
- std::cout<<"Entity:"<<entity.size()<<std::endl;
+ //std::cout<<"NPC:"<<npc.size()<<std::endl;
+ //std::cout<<"Entity:"<<entity.size()<<std::endl;
entity[entity.size()] = &npc[npc.size()-1];
entity[entity.size()-1]->spawn(loc.x + (float)(i - 5) / 8,100);
- std::cout<<"Entity Type["<<entity.size()<<"]: "<<entity[entity.size()]->type<<std::endl;
- std::cout<<"Entity Life["<<entity.size()<<"]: "<<entity[entity.size()]->alive<<std::endl;
+ //std::cout<<"Entity Type["<<entity.size()<<"]: "<<entity[entity.size()]->type<<std::endl;
+ //std::cout<<"Entity Life["<<entity.size()<<"]: "<<entity[entity.size()]->alive<<std::endl;
}
return entity.size();
}
diff --git a/src/main.cpp b/src/main.cpp
index 1e8b942..6a1650b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -96,9 +96,6 @@ int main(int argc, char *argv[]){
IndoorWorld *iw=new IndoorWorld();
iw->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;i<entity.size()+1;i++){
entity[i]->inWorld=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"<<i<<std::endl;
+ //std::cout<<"works"<<i<<std::endl;
}
}
}
diff --git a/src/ui.cpp b/src/ui.cpp
index 75bc5ee..9b3cdff 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -146,6 +146,7 @@ namespace ui {
player->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;i<current->platform.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;i<entity.size();i++){
+ if(entity[i]->type==-1){
+ if(entity[i]->inWorld==this){
+ if(p->loc.x>entity[i]->loc.x&&p->loc.x+p->width<entity[i]->loc.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){