diff options
-rw-r--r-- | include/World.h | 7 | ||||
-rw-r--r-- | include/common.h | 2 | ||||
-rw-r--r-- | src/World.cpp | 25 | ||||
-rw-r--r-- | src/main.cpp | 8 |
4 files changed, 36 insertions, 6 deletions
diff --git a/include/World.h b/include/World.h index e405059..3b4b56d 100644 --- a/include/World.h +++ b/include/World.h @@ -3,7 +3,8 @@ #include <common.h>
-#define HLINE (2.0f/(SCREEN_WIDTH/4))
+#define goWorldLeft(w) if(w->toLeft){w=w->toLeft;}
+#define goWorldRight(w) if(w->toRight){w=w->toRight;}
class World {
private:
@@ -13,7 +14,9 @@ private: } *line;
unsigned int lineCount;
public:
- World(float width);
+ World *toLeft,*toRight;
+ World(void);
+ World(const float width,World *l,World *r);
void draw(void);
void detect(vec2 *v,const float width);
};
diff --git a/include/common.h b/include/common.h index 782ebd6..9ce1be0 100644 --- a/include/common.h +++ b/include/common.h @@ -18,7 +18,7 @@ typedef struct{float x; float y;}vec2; #define SCREEN_HEIGHT 800
#define FULLSCREEN
-
+#define HLINE (2.0f/(SCREEN_WIDTH/4))
//SDL VARIABLES
extern SDL_Window *window;
diff --git a/src/World.cpp b/src/World.cpp index 022948f..c3a76c7 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1,6 +1,11 @@ #include <World.h>
-World::World(float width){
+World::World(void){
+ line=NULL;
+ lineCount=0;
+ toLeft=toRight=NULL;
+}
+World::World(const float width,World *l,World *r){
unsigned int i;
double f;
lineCount=width/HLINE+1;
@@ -8,6 +13,24 @@ World::World(float width){ std::cout<<"Failed to allocate memory!"<<std::endl;
abort();
}
+ toLeft=l;
+ toRight=r;
+ if(toLeft){
+ if(toLeft->toRight){
+ std::cout<<"There's already a world to the left!"<<std::endl;
+ abort();
+ }else{
+ toLeft->toRight=this;
+ }
+ }
+ if(toRight){
+ if(toRight->toLeft){
+ std::cout<<"There's already a world to the right!"<<std::endl;
+ abort();
+ }else{
+ toRight->toLeft=this;
+ }
+ }
line[0].start=(rand()%100)/100.0f-0.8f; // lazy
if(line[0].start>-0.5f)line[0].start=-0.7f;
for(i=10;i<lineCount;i+=10){
diff --git a/src/main.cpp b/src/main.cpp index b04cb59..fa3a9c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ bool gameRunning = true; UIClass ui;
Entities *entit1;
Player player;
+World *currentWorld;
int main(int argc,char **argv){
// Initialize SDL
@@ -54,7 +55,10 @@ int main(int argc,char **argv){ entit1 = &player;
entit1->spawn(0,0);
- World *w=new World(2);
+ World *w=NULL;
+ World *w2=new World(4,w,NULL);
+ w=new World(2,NULL,w2);
+ currentWorld=w;
while(gameRunning){
ui.handleEvents(); // Handle events
@@ -75,7 +79,7 @@ int main(int argc,char **argv){ **** RENDER STUFF HERE ****
**************************/
- w->draw();
+ currentWorld->draw();
glColor3ub(0,0,0);
glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height);
|