]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added spawn world
authordrumsetmonkey <abelleisle@roadrunner.com>
Tue, 10 Nov 2015 13:38:30 +0000 (08:38 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Tue, 10 Nov 2015 13:38:30 +0000 (08:38 -0500)
Makefile
include/world.h
src/Makefile
src/gameplay.cpp
src/world.cpp

index bbeff1eef73ef30286d5f2cb17134c82ffbd1b15..7a7a868ac273b0b1541dc144f286dba1c3b265cf 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
-LIBS = -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
+LIBS = -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
 \r
 WIN_LIBS = -lopengl32 -lglew32 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype\r
 \r
-FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2\r
+FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2\r
 \r
 all:\r
        @rm -f out/*.o\r
index 9d7a33bd9619ff253569cdd23bc7a90b39f10997..48ca47b6aceefcbb0e6ba3b700f03077bbbe5ae0 100644 (file)
@@ -4,6 +4,11 @@
 #include <common.h> // For HLINE, vec2, OpenGL utilities, etc.
 #include <entities.h>
 
+#define GEN_INC 10             // Defines at what interval y values should be calculated for the array 'line'.
+                                               // As explained in World(), the last few lines in the array 'line' are incorrectly calculated
+                                               // or not calculated at all, so GEN_INC is also used to decrease 'lineCount' in functions like draw()
+                                               // and detect().
+
 struct line_t {
        bool gs;
        float y,gh[2];
@@ -95,7 +100,7 @@ public:
        */
        
        virtual void generate(unsigned int width);
-       void generateFunc(unsigned int width,unsigned int (*func)(unsigned int));
+       void generateFunc(unsigned int width,float(*func)(float));
        
        /*
         *      Looks for the furthest back layer in this world and adds a new layer of width `width` behind it.
index a243846937aa25fecec9f36a614d74e0dbd303ec..aacef575c2349860915b6724aaef5fba0becdca7 100644 (file)
@@ -1,6 +1,6 @@
-LIBS = -lGL -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
+LIBS = -lGL -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
 
-FLAGS = -m32 -std=c++11 -I../include -I../include/freetype2
+FLAGS = -std=c++11 -I../include -I../include/freetype2
 
 OUT = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out\//g'`
 
index 3b13dfe66d93ff39217b0e94fa7c35ce763ac96d..c3f3988733953998f6dc25d0529d0b3dffcb2dc5 100644 (file)
@@ -22,6 +22,10 @@ int giveTestQuest(NPC *speaker){
        return 0;
 }
 
+float playerSpawnHillFunc(float x){
+       x=-x;
+       return (float)(pow(2,(x+200)/5) + 80);
+}
 void initEverything(void){
        unsigned int i;
        
@@ -30,6 +34,7 @@ void initEverything(void){
        */
        
        World *test=new World();
+       World *playerSpawnHill=new World();
        
        /*
         *      Load the saved world if it exists, otherwise generate a new one.
@@ -47,24 +52,29 @@ void initEverything(void){
                fread(buf,1,size,worldLoad);
                test->load(buf);
        }else{*/
-               test->generate(SCREEN_WIDTH * 2);
+               test->generate(SCREEN_WIDTH*2);
                test->addHole(100,150);
        //}
        
        test->addLayer(400);
        
+       playerSpawnHill->generateFunc(1280,playerSpawnHillFunc);
+       //playerSpawnHill->generate(1920);
+
        /*
         *      Setup the current world, making the player initially spawn in `test`.
        */
        
-       currentWorld=test;
+       currentWorld=playerSpawnHill;
+       playerSpawnHill->toRight=test;
+       test->toLeft=playerSpawnHill;
        
        /*
         *      Create the player.
        */
        
        player=new Player();
-       player->spawn(0,200);
+       player->spawn(-1000,200);
        
        /*
         *      Create a structure (this will create villagers when spawned).
index 63604fe73a522a9a2681e677d265c04c3b68e01a..8c42a81a47c8cf366b6c72f025520fa5b44ad49a 100644 (file)
@@ -2,11 +2,6 @@
 
 #define getWidth(w) ((w->lineCount-GEN_INC)*HLINE)     // Calculates the width of world 'w'
 
-#define GEN_INC 10             // Defines at what interval y values should be calculated for the array 'line'.
-                                               // As explained in World(), the last few lines in the array 'line' are incorrectly calculated
-                                               // or not calculated at all, so GEN_INC is also used to decrease 'lineCount' in functions like draw()
-                                               // and detect().
-
 #define GEN_MIN  80
 #define GEN_MAX  110
 #define GEN_INIT 60
@@ -166,13 +161,15 @@ void World::generate(unsigned int width){ // Generates the world and sets all va
        x_start=0 - getWidth(this) / 2;
 }
 
-void World::generateFunc(unsigned int width,unsigned int (*func)(unsigned int)){
+void World::generateFunc(unsigned int width,float(*func)(float)){
        unsigned int i;
        if((lineCount = width) <= 0)
                abort();
        line=(struct line_t *)calloc(lineCount,sizeof(struct line_t));
        for(i=0;i<lineCount;i++){
                line[i].y=func(i);
+               if(line[i].y<0)line[i].y=0;
+               if(line[i].y>2000)line[i].y=2000;
                line[i].color=rand() % 20 + 100;
                line[i].gh[0]=(getRand() % 16) / 3.5 + 2;
                line[i].gh[1]=(getRand() % 16) / 3.5 + 2;
@@ -584,7 +581,7 @@ void World::addLayer(unsigned int width){
 }
 
 World *World::goWorldLeft(Player *p){
-       if(toLeft&&p->loc.x<x_start+HLINE*10){
+       if(toLeft&&p->loc.x<x_start+HLINE*15){
                p->loc.x=toLeft->x_start+getWidth(toLeft)-HLINE*10;
                p->loc.y=toLeft->line[0].y;
                return toLeft;