diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-04 08:50:18 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-04 08:50:18 -0500 |
commit | 69701af0cdd9b5cb41fff7ac7b1265c71506b7da (patch) | |
tree | 423fc30de843943db89cde9aa5802883a25bd8b9 | |
parent | 6b7dd6a9c031fd2129676500bc8e8633d3fcf234 (diff) |
ortho binds to y
-rw-r--r-- | Changelog | 8 | ||||
-rw-r--r-- | include/common.h | 4 | ||||
-rw-r--r-- | main.cpp | 53 | ||||
-rw-r--r-- | src/gameplay.cpp | 2 | ||||
-rw-r--r-- | src/inventory.cpp | 2 | ||||
-rw-r--r-- | src/ui.cpp | 28 | ||||
-rw-r--r-- | src/world.cpp | 2 |
7 files changed, 56 insertions, 43 deletions
@@ -231,3 +231,11 @@ - added typewriter-esque text drawing - documented ui.h - continued work on GLSL shaders + +11/4/2015: +========== + + - fixed typewriter output free() error + - added y-binding to ortho (if player is high in the sky ortho and UI will match it) + - added maximum to gravity's pull + - worked on storyline diff --git a/include/common.h b/include/common.h index 41cc7b9..39812c4 100644 --- a/include/common.h +++ b/include/common.h @@ -101,6 +101,10 @@ typedef struct { #define DEBUG_printf( message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__ ) + +#define PI 3.1415926535 + + /* * References the variable in main.cpp, used for smoother drawing. */ @@ -186,7 +186,8 @@ std::string readFile(const char *filePath) { * 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 @@ -568,8 +569,8 @@ void render(){ * 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 @@ -581,6 +582,9 @@ void render(){ 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 * @@ -621,7 +625,7 @@ void render(){ 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(); @@ -656,16 +660,16 @@ void render(){ 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); @@ -774,7 +778,6 @@ void render(){ glUseProgramObjectARB(0); #endif //SHADERS - #define pi 3.1415926535 #define raysNOPE #ifdef rays @@ -809,20 +812,20 @@ void render(){ 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){ @@ -844,8 +847,6 @@ void render(){ } #endif //rays - - //LIGHT player->inv->draw(); /* @@ -863,7 +864,7 @@ void render(){ 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, @@ -910,10 +911,10 @@ void render(){ 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."); } @@ -969,8 +970,7 @@ void logic(){ */ 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. */ @@ -1092,7 +1092,6 @@ void logic(){ * 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)); /* diff --git a/src/gameplay.cpp b/src/gameplay.cpp index f986ce3..baa91e8 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -51,7 +51,7 @@ void initEverything(void){ */ player=new Player(); - player->spawn(0,100); + player->spawn(0,5000); /* * Create a structure (this will create villagers when spawned). diff --git a/src/inventory.cpp b/src/inventory.cpp index cb33deb..c79a29b 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -91,7 +91,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){ void Inventory::draw(void){ unsigned int i=0; - float y=SCREEN_HEIGHT/2,xoff; + float y=offset.y,xoff; ui::setFontSize(14); ui::putText(offset.x-SCREEN_WIDTH/2,y,"Inventory:"); while(item[i].count){ @@ -142,12 +142,13 @@ namespace ui { 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; } @@ -189,6 +190,7 @@ namespace ui { 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); @@ -196,8 +198,8 @@ namespace ui { 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); } @@ -206,7 +208,7 @@ namespace ui { 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); @@ -214,14 +216,14 @@ namespace ui { 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){ @@ -229,7 +231,7 @@ namespace ui { 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: @@ -250,7 +252,7 @@ namespace ui { */ 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; @@ -272,7 +274,7 @@ namespace ui { 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; } @@ -307,10 +309,10 @@ namespace ui { 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; diff --git a/src/world.cpp b/src/world.cpp index 0ec0f35..5e7fb41 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -446,7 +446,7 @@ void World::singleDetect(Entity *e){ * Handle gravity. */ - e->vel.y-=.001 * deltaTime; + if(e->vel.y > -2)e->vel.y-=.001 * deltaTime; } |