]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
added linked worlds
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 10 Sep 2015 19:19:18 +0000 (15:19 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 10 Sep 2015 19:19:18 +0000 (15:19 -0400)
include/World.h
include/common.h
src/World.cpp
src/main.cpp

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