aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/UIClass.cpp14
-rw-r--r--src/World.cpp19
-rw-r--r--src/main.cpp9
3 files changed, 31 insertions, 11 deletions
diff --git a/src/UIClass.cpp b/src/UIClass.cpp
index c1c1180..e416bc1 100644
--- a/src/UIClass.cpp
+++ b/src/UIClass.cpp
@@ -16,16 +16,20 @@ void UIClass::handleEvents(){
case SDL_KEYDOWN:
if(e.key.keysym.sym == SDLK_d) player.right = true;
if(e.key.keysym.sym == SDLK_a) player.left = true;
- if(e.key.keysym.sym == SDLK_SPACE) player.loc.y += 10;
+ if(e.key.keysym.sym == SDLK_SPACE) player.loc.y += .5;
if(e.key.keysym.sym == SDLK_i)
if(currentWorld->behind){
- player.loc.x-=(currentWorld->getWidth()-currentWorld->behind->getWidth())/2;
- currentWorld=currentWorld->behind;
+ player.loc.x-=(currentWorld->getWidth()-currentWorld->behind->getWidth())/2; // Match player's location to new area
+ currentWorld=currentWorld->behind; // Go to new area
+ if(player.loc.x>-1+currentWorld->getWidth()) // Don't let player fall out of world if previous area was bigger
+ player.loc.x=-1+currentWorld->getWidth()-player.width-HLINE;
}
if(e.key.keysym.sym == SDLK_k)
if(currentWorld->infront){
- player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2;
- currentWorld=currentWorld->infront;
+ player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2; // Match player's location to new area
+ currentWorld=currentWorld->infront; // Go to new area
+ if(player.loc.x>-1+currentWorld->getWidth()) // Don't let player fall out of world if previous area was bigger
+ player.loc.x=-1+currentWorld->getWidth()-player.width-HLINE;
}
break;
case SDL_KEYUP:
diff --git a/src/World.cpp b/src/World.cpp
index 0ee8658..ca19ba1 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1,6 +1,9 @@
#include <World.h>
#include <cstdio>
+static float drawOffsetX=0,
+ drawOffsetY=0;
+
World::World(void){
line=NULL;
lineCount=entCount=0;
@@ -48,12 +51,17 @@ World::World(const float width,World *l,World *r){
}
}
}
-static float drawOffsetX=0,
- drawOffsetY=0;
+void safeSetColor(int r,int g,int b){
+ if(r>255)r=255;else if(r<0)r=0;
+ if(g>255)g=255;else if(g<0)g=0;
+ if(b>255)b=255;else if(b<0)b=0;
+ glColor3ub(r,g,b);
+}
void World::draw(void){
unsigned int i;
float x,y,hline=HLINE;
static World *root,*cur;
+ int shade;
root=cur=this;
LOOP:
if(cur->behind){
@@ -65,17 +73,18 @@ LOOP:
//behind->draw();
}
LOOP2:
+ shade=30*(drawOffsetY/.3);
glBegin(GL_QUADS);
for(i=0;i<cur->lineCount-10;i++){
x=(hline*i)-1+drawOffsetX;
y=cur->line[i].start+drawOffsetY;
- glColor3ub(0,200,0);
+ safeSetColor(0,200+shade,0);
glVertex2f(x ,y);
glVertex2f(x+hline,y);
y-=hline*2;
glVertex2f(x+hline,y);
glVertex2f(x ,y);
- glColor3ub(150,100,50);
+ safeSetColor(150+shade,100+shade,50+shade);
glVertex2f(x ,y);
glVertex2f(x+hline,y);
glVertex2f(x+hline,-1);
@@ -109,7 +118,7 @@ void World::detect(vec2 *v,const float width){
return;
}
}else if(v->y>line[i].start+HLINE/4){
- v->y-=HLINE/8;
+ v->y-=HLINE/32;
}
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 25d76b5..50eab25 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -142,7 +142,14 @@ void render(){
glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on
glPushMatrix(); //push the matrix to the top of the matrix stack
glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode
- glOrtho(-1 + player.loc.x, 1 + player.loc.x , -1, 1, -1,1); //set the the size of the screen
+ //set the the size of the screen
+ if(player.loc.x-1<-1){
+ glOrtho(-1,1,-1,1,-1,1);
+ }else if(player.loc.x+1>-1+currentWorld->getWidth()){
+ glOrtho(-3+currentWorld->getWidth(),-1+currentWorld->getWidth(),-1,1,-1,1);
+ }else{
+ glOrtho(-1 + player.loc.x, 1 + player.loc.x , -1, 1, -1,1);
+ }
glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects
glPushMatrix(); //push the matrix to the top of the matrix stack
glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode