aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/world.h9
-rw-r--r--src/entities.cpp2
-rw-r--r--src/main.cpp3
-rw-r--r--src/ui.cpp1
-rw-r--r--src/world.cpp31
5 files changed, 38 insertions, 8 deletions
diff --git a/include/world.h b/include/world.h
index e826ba2..0e8dced 100644
--- a/include/world.h
+++ b/include/world.h
@@ -3,6 +3,10 @@
#include <common.h> // For HLINE, vec2, OpenGL utilities, etc.
+typedef struct {
+ vec2 p1,p2;
+} __attribute__ ((packed)) Platform;
+
/*
* World - creates and handles an area of land
*/
@@ -24,10 +28,11 @@ protected:
unsigned char color;
} __attribute__ ((packed)) *line;
unsigned int lineCount; // Size of the array 'line' (aka the width of the world)
+ std::vector<Platform> platform; // An array (vector thing) of platforms
int x_start; // Worlds are centered on the x axis (0,n), this contains
// where to start drawing the world to have it centered properly.
World *behind,*infront; // Pointers to other areas of land that are behind or in front of this one, respectively.
- void singleDetect(Entity *e);
+ void singleDetect(Entity *e); // Handles an individual entity (gravity n' stuff)
public:
World *toLeft,*toRight; // Pointers to areas to the left and right of this world. These are made public
// so that they can easily be set without a function.
@@ -57,7 +62,7 @@ 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);
};
/*
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}});
+}