* This offset is used as the player offset in the world drawing so
* everything can be moved according to the player
*/
-vec2 offset;
+
+vec2 offset; /** OFFSET!!!!!!!!!!!!!!!!!!!! **/
/*
* millis
* objects on the screen so they always appear to be in the same relative area
*/
- offset = player->loc;
- offset.x += player->width/2;
+ offset.x = player->loc.x + player->width/2;
+ offset.y = SCREEN_HEIGHT/2;
/*
* If the camera will go off of the left or right of the screen we want to lock it so we can't
if(player->loc.x + SCREEN_WIDTH/2 > currentWorld->getTheWidth() * 0.5f)
offset.x = ((currentWorld->getTheWidth() * 0.5f) - SCREEN_WIDTH / 2) + player->width / 2;
+ if(player->loc.y > 300 )
+ offset.y = player->loc.y + player->height;
+
/*
* These functions run everyloop to update the current stacks presets
*
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
- glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),0,SCREEN_HEIGHT,-1,1);
+ glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glBegin(GL_QUADS);
glTexCoord2i(0,1);glVertex2i(-SCREEN_WIDTH*2+offset.x,0);
glTexCoord2i(1,1);glVertex2i( SCREEN_WIDTH*2+offset.x,0);
- glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT);
- glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT);
+ glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2);
+ glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2);
glEnd();
glBindTexture(GL_TEXTURE_2D,bgNight);
safeSetColorA(255,255,255,worldShade*4);
glBegin(GL_QUADS);
glTexCoord2i(0,1);glVertex2i(-SCREEN_WIDTH*2+offset.x,0);
glTexCoord2i(1,1);glVertex2i( SCREEN_WIDTH*2+offset.x,0);
- glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT);
- glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT);
+ glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2);
+ glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT*2);
glEnd();
glDisable(GL_TEXTURE_2D);
glUseProgramObjectARB(0);
#endif //SHADERS
- #define pi 3.1415926535
#define raysNOPE
#ifdef rays
break;
default:
if(angle > 0 && angle < 90){
- curCoord.x = r.start.x + float(HLINE / cos(angle*pi/180));
- curCoord.y = r.start.y + float(HLINE / sin(angle*pi/180));
+ curCoord.x = r.start.x + float(HLINE / cos(angle*PI/180));
+ curCoord.y = r.start.y + float(HLINE / sin(angle*PI/180));
}
if(angle > 90 && angle < 180){
- curCoord.x = r.start.x - float(HLINE / cos((90-angle)*pi/180));
- curCoord.y = r.start.y + float(HLINE / sin((90-angle)*pi/180));
+ curCoord.x = r.start.x - float(HLINE / cos((90-angle)*PI/180));
+ curCoord.y = r.start.y + float(HLINE / sin((90-angle)*PI/180));
}
if(angle > 180 && angle < 270){
- curCoord.x = r.start.x - float(HLINE / cos((270-angle)*pi/180));
- curCoord.y = r.start.y - float(HLINE / sin((270-angle)*pi/180));
+ curCoord.x = r.start.x - float(HLINE / cos((270-angle)*PI/180));
+ curCoord.y = r.start.y - float(HLINE / sin((270-angle)*PI/180));
}
if(angle > 270 && angle < 360){
- curCoord.x = r.start.x + float(HLINE / cos((360-angle)*pi/180));
- curCoord.y = r.start.y - float(HLINE / sin((360-angle)*pi/180));
+ curCoord.x = r.start.x + float(HLINE / cos((360-angle)*PI/180));
+ curCoord.y = r.start.y - float(HLINE / sin((360-angle)*PI/180));
}
}//end swtich
/*for(auto &en : entity){
}
#endif //rays
-
- //LIGHT
player->inv->draw();
/*
ui::setFontSize(16);
ui::putText(offset.x-SCREEN_WIDTH/2,
- SCREEN_HEIGHT-ui::fontSize,
+ (offset.y+SCREEN_HEIGHT/2)-ui::fontSize,
"FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nTc: %u\nQc: %u",
fps,
player->ground,
if(fadeIntensity){
glColor4ub(0,0,0,fadeIntensity);
- glRectf(player->loc.x-SCREEN_WIDTH,
- SCREEN_HEIGHT,
- player->loc.x+SCREEN_WIDTH,
- 0);
+ glRectf(offset.x-SCREEN_WIDTH /2,
+ offset.y-SCREEN_HEIGHT/2,
+ offset.x+SCREEN_WIDTH /2,
+ offset.y+SCREEN_HEIGHT/2);
if(fadeIntensity == 255){
ui::importantText("The screen is black.");
}
*/
for(int i = 0 ; i < entity.size(); i++){
- if(!entity[i]->alive)std::cout<<"Entity "<<i<<" is not alive!"<<std::endl;
-
+
/*
* Check if the entity is in this world and is alive.
*/
* Calculate an in-game shading value (as opposed to GLSL shading).
*/
- #define PI 3.1415926535
worldShade=50*sin((tickCount+(DAY_CYCLE/2))/(DAY_CYCLE/PI));
/*
return xo;
}
char *typeOut(char *str){
- static unsigned int sinc,linc,size;
+ static unsigned int sinc,linc,size=0;
static char *ret = NULL;
unsigned int i;
- if(!ret || size != strlen(str)){
+ if(!ret)ret=(char *)calloc(512,sizeof(char));
+ if(size != strlen(str)){
+ memset(ret,0,512);
size=strlen(str);
- ret=(char *)calloc(size,sizeof(char));
linc=0;
sinc=2;
}
void importantText(const char *text,...){
va_list textArgs;
char *ttext;
+ if(!player->ground)return;
va_start(textArgs,text);
ttext=(char *)calloc(512,sizeof(char));
vsnprintf(ttext,512,text,textArgs);
setFontSize(24);
char *rtext;
rtext=typeOut(ttext);
- putString(player->loc.x+player->width/2-SCREEN_WIDTH/2,
- SCREEN_HEIGHT/2+fontSize,
+ putString(offset.x-SCREEN_WIDTH/2,
+ offset.y+fontSize,
rtext);
free(ttext);
}
if(dialogBoxExists){
glColor3ub(0,0,0);
x=player->loc.x-SCREEN_WIDTH/2+HLINE*8;
- y=SCREEN_HEIGHT-HLINE*8;
+ y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4);
char *rtext;
rtext=typeOut(dialogBoxText);
putString(x+HLINE,y-fontSize-HLINE,rtext);
}
setFontSize(14);
- putText(((SCREEN_WIDTH/2)+offset.x)-125,SCREEN_HEIGHT-fontSize,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
+ putText(((SCREEN_WIDTH/2)+offset.x)-125,(offset.y+SCREEN_HEIGHT/2)-fontSize,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
(unsigned)player->maxHealth);
if(player->alive){
glColor3ub(255,0,0);
glRectf((SCREEN_WIDTH/2+offset.x)-125,
- SCREEN_HEIGHT-32,
+ (offset.y+SCREEN_HEIGHT/2)-32,
((SCREEN_WIDTH/2+offset.x)-125)+((player->health/player->maxHealth)*100),
- SCREEN_HEIGHT-32+12);
+ (offset.y+SCREEN_HEIGHT/2)-32+12);
}
}
void handleEvents(void){
static vec2 premouse={0,0};
SDL_Event e;
mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
- mouse.y=SCREEN_HEIGHT-premouse.y;
+ mouse.y=(offset.y+SCREEN_HEIGHT/2)-premouse.y;
while(SDL_PollEvent(&e)){
switch(e.type){
case SDL_QUIT:
*/
case SDL_KEYDOWN:
if(SDL_KEY==SDLK_ESCAPE)gameRunning=false; // Exit the game with ESC
- if(!dialogBoxExists){
+ if(!dialogBoxExists&&!fadeEnable){
if(SDL_KEY==SDLK_a){ // Move left
left=true;
player->vel.x=-.15;
if(SDL_KEY==SDLK_w)currentWorld=currentWorld->goInsideStructure(player);
if(SDL_KEY==SDLK_SPACE){ // Jump
if(player->ground){
- player->vel.y=.5;
+ player->vel.y=.4;
player->loc.y+=HLINE*2;
player->ground=false;
}
if(SDL_KEY==SDLK_c){
dialogBox("","You pressed `c`, but nothing happened?");
}
- if(SDL_KEY==SDLK_p)toggleBlack();
if(SDL_KEY==SDLK_LSHIFT)player->speed = debug?4:3; // Sprint
if(SDL_KEY==SDLK_LCTRL)player->speed = .5;
}
+ if(SDL_KEY==SDLK_p)toggleBlack();
if(SDL_KEY==SDLK_F3)debug^=true;
if(SDL_KEY==SDLK_b & SDL_KEY==SDLK_F3)posFlag^=true;
break;