diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2015-11-10 08:38:30 -0500 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2015-11-10 08:38:30 -0500 |
commit | a075f1b6c2c65570ab7b249b12efefcfcc442e95 (patch) | |
tree | 5d8a933505b31e3da8071f15f30240bb5828d925 /src | |
parent | b0f7e8d2caa72ab1fe93fa58dbfa841750d96037 (diff) |
Added spawn world
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/gameplay.cpp | 16 | ||||
-rw-r--r-- | src/world.cpp | 11 |
3 files changed, 19 insertions, 12 deletions
diff --git a/src/Makefile b/src/Makefile index a243846..aacef57 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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'` diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 3b13dfe..c3f3988 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -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). diff --git a/src/world.cpp b/src/world.cpp index 63604fe..8c42a81 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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; |