aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-09-27 10:35:40 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-09-27 10:35:40 -0400
commit4391f9289b7368765b39c9654d6b0bdf2db8f36b (patch)
treed023c1f7cde41199cd44cba2d49f5f36bd915ecf /src
parent5781bba3aa5764792b25a1d395cac388d001d713 (diff)
added platforms
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp2
-rw-r--r--src/main.cpp3
-rw-r--r--src/ui.cpp1
-rw-r--r--src/world.cpp31
4 files changed, 31 insertions, 6 deletions
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 <world.h>
+#include <ui.h>
#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;i<entity.size()+1;i++){
+ if(entity[i]->inWorld==current){
+ entity[i]->draw();
+ ui::putText(entity[i]->loc.x,entity[i]->loc.y,"%d",i);
+ }
+ }
+ glColor3ub(255,0,0);
+ 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);
+ }
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;i<entity.size()+1;i++){
- if(entity[i]->inWorld==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;i<platform.size();i++){
+ if(((e->loc.x+e->width>platform[i].p1.x)&(e->loc.x+e->width<platform[i].p2.x))||
+ ((e->loc.x<platform[i].p2.x)&(e->loc.x>platform[i].p1.x))){
+ if(e->loc.y>platform[i].p2.y-HLINE&&e->loc.y<platform[i].p2.y){
+ if(e->vel.y<0){
+ e->vel.y=0;
+ e->loc.y=platform[i].p2.y;
+ e->ground=true;
+ }
+ }
+ }
+ }
e->vel.y-=.01;
}
if(e->loc.x<x_start){ // Keep the player inside world bounds (ui.cpp handles world jumping)
@@ -192,6 +212,9 @@ World *World::goWorldFront(Player *p){
return this;
}
+void World::addPlatform(float x,float y,float w,float h){
+ platform.push_back((Platform){{x,y},{x+w,y+h}});
+}