aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--include/world.h7
-rw-r--r--src/Makefile4
-rw-r--r--src/gameplay.cpp16
-rw-r--r--src/world.cpp11
5 files changed, 27 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index bbeff1e..7a7a868 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
-LIBS = -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
+LIBS = -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
WIN_LIBS = -lopengl32 -lglew32 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
-FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2
+FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2
all:
@rm -f out/*.o
diff --git a/include/world.h b/include/world.h
index 9d7a33b..48ca47b 100644
--- a/include/world.h
+++ b/include/world.h
@@ -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.
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;