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:
#include <World.h>\r
#include <cstdio>\r
\r
+static float drawOffsetX=0,\r
+ drawOffsetY=0;\r
+\r
World::World(void){\r
line=NULL;\r
lineCount=entCount=0;\r
}\r
}\r
}\r
-static float drawOffsetX=0,\r
- drawOffsetY=0;\r
+void safeSetColor(int r,int g,int b){\r
+ if(r>255)r=255;else if(r<0)r=0;\r
+ if(g>255)g=255;else if(g<0)g=0;\r
+ if(b>255)b=255;else if(b<0)b=0;\r
+ glColor3ub(r,g,b);\r
+}\r
void World::draw(void){\r
unsigned int i;\r
float x,y,hline=HLINE;\r
static World *root,*cur;\r
+ int shade;\r
root=cur=this;\r
LOOP:\r
if(cur->behind){\r
//behind->draw();\r
}\r
LOOP2:\r
+ shade=30*(drawOffsetY/.3);\r
glBegin(GL_QUADS);\r
for(i=0;i<cur->lineCount-10;i++){\r
x=(hline*i)-1+drawOffsetX;\r
y=cur->line[i].start+drawOffsetY;\r
- glColor3ub(0,200,0);\r
+ safeSetColor(0,200+shade,0);\r
glVertex2f(x ,y);\r
glVertex2f(x+hline,y);\r
y-=hline*2;\r
glVertex2f(x+hline,y);\r
glVertex2f(x ,y);\r
- glColor3ub(150,100,50);\r
+ safeSetColor(150+shade,100+shade,50+shade);\r
glVertex2f(x ,y);\r
glVertex2f(x+hline,y);\r
glVertex2f(x+hline,-1);\r
return;\r
}\r
}else if(v->y>line[i].start+HLINE/4){\r
- v->y-=HLINE/8;\r
+ v->y-=HLINE/32;\r
}\r
}\r
}\r
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