#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
*/
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.
// 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);
};
/*
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();
}
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();
if(SDL_KEY==SDLK_SPACE){ // Jump
if(player->ground){
player->vel.y=.25;
+ //player->loc.y+=HL
player->ground=false;
}
}
#include <world.h>
+#include <ui.h>
#define getWidth(w) ((w->lineCount-GEN_INC)*HLINE) // Calculates the width of world 'w'
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;
}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();
- }
}
}
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)
return this;
}
+void World::addPlatform(float x,float y,float w,float h){
+ platform.push_back((Platform){{x,y},{x+w,y+h}});
+}