diff options
Diffstat (limited to 'main.cpp')
| -rw-r--r-- | main.cpp | 78 |
1 files changed, 55 insertions, 23 deletions
@@ -128,13 +128,31 @@ void sdl_put_letter(SDL_Renderer *ren, SDL_Texture *tex,int x,int y, int w, int } -void sdl_put_str(SDL_Renderer *ren, SDL_Texture *tex,int x, int y,int size,std::string str,int r,int g, int b) +void sdl_put_str(SDL_Renderer *ren, SDL_Texture *tex,int x, int y,int size,std::string str,int r,int g, int b,int length,int win_width,int win_height,int which,int of) { + length++; + int max_char_width=win_width/length; + int max_char_height=max_char_width*10/8; + int char_width=max_char_width*size/10; + int char_height=max_char_height*size/10; + int pos=0; + x=(win_width-length*char_width)/2; + + if(y==-1) + { + y=win_height/2+(which-1)*max_char_height; + } + + + SDL_SetRenderDrawColor(ren, 40,40,40, 255); + SDL_Rect rect2={0,y-2,win_width,char_height+4}; + SDL_RenderFillRect(ren,&rect2); + for(char ch:str) { pos++; - sdl_put_letter(ren,tex,x+8*size*pos,y, 8*size,10*size, r,g,b, ch); + sdl_put_letter(ren,tex,x+char_width*pos,y, char_width,char_height, r,g,b, ch); } } @@ -183,6 +201,20 @@ int main(int, char**){ // init world LEVEL 1 World world(1); + + + + int show_tiles_back=6; + int show_tiles_front=10; + int show_tiles_size=20; + int show_tiles_vertical_move=12; + int show_tiles_max_height=800; + int show_tiles_water_level=-1; + + show_tiles_size=win_height/15; + show_tiles_back=win_width/show_tiles_size*0.25; + show_tiles_front=win_width/show_tiles_size*1; + while (!quit) { // calc delta and FPS @@ -211,6 +243,10 @@ int main(int, char**){ win_width=event.window.data1; win_height=event.window.data2; + show_tiles_size=win_height/15; + show_tiles_back=win_width/show_tiles_size*0.25; + show_tiles_front=win_width/show_tiles_size*1; +// while(show_tiles_size%20!=0)show_tiles_size--; } if (event.type==SDL_MOUSEBUTTONDOWN) @@ -218,7 +254,7 @@ int main(int, char**){ mouse_x=event.button.x; mouse_y=event.button.y; - world.mouseclick((mouse_x+50-world.player.x2)/100+world.player.x-5,10-mouse_y/100); + world.mouseclick((mouse_x+show_tiles_size/2-world.player.x2)/show_tiles_size+world.player.x-show_tiles_back,show_tiles_vertical_move-mouse_y/show_tiles_size); } @@ -241,26 +277,26 @@ int main(int, char**){ SDL_RenderClear(ren); // render visible area - for(int i=world.player.x-5;i<world.player.x+30;i++) + for(int i=world.player.x-show_tiles_back;i<world.player.x+show_tiles_front;i++) { - int br=i-world.player.x+5; + int tile_col=i-world.player.x+show_tiles_back; if(i<0||i>=world.bricks.size())continue; - SDL_Rect rect={br*100-100*world.player.x2,(10-world.coins_pos[i])*100,100,100}; + SDL_Rect rect={tile_col*show_tiles_size-show_tiles_size*world.player.x2,(show_tiles_vertical_move-world.coins_pos[i])*show_tiles_size,show_tiles_size,show_tiles_size}; SDL_RenderCopy(ren,textures[2],NULL,&rect); for(int j=0;j<world.bricks[i].size();j++) { - SDL_Rect rect={br*100-100*world.player.x2,(10-world.bricks[i][j].altitude)*100,100,100}; + SDL_Rect rect={tile_col*show_tiles_size-show_tiles_size*world.player.x2,(show_tiles_vertical_move-world.bricks[i][j].altitude)*show_tiles_size,show_tiles_size,show_tiles_size}; switch(world.bricks[i][j].type) { case 0: SDL_RenderCopy(ren,textures[4],NULL,&rect); SDL_SetRenderDrawColor(ren, 150+19*(i%2),115,70, 255); - rect.h=800; - rect.y+=100; + rect.h=show_tiles_max_height; + rect.y+=show_tiles_size; SDL_RenderFillRect(ren,&rect); break; case 1: @@ -284,37 +320,33 @@ int main(int, char**){ // water level SDL_SetRenderDrawColor(ren, 100*(i%2),100*(i%2),255, 255); - SDL_Rect rect2={br*100-100*world.player.x2,(15)*100+std::sin(frameTime/1000.0+i)*30,100,800}; + SDL_Rect rect2={tile_col*show_tiles_size-show_tiles_size*world.player.x2,show_tiles_vertical_move*show_tiles_size-show_tiles_water_level*show_tiles_size+std::sin(frameTime/1000.0+i)*show_tiles_size*0.33,show_tiles_size,show_tiles_max_height}; SDL_RenderFillRect(ren,&rect2); } // render player char - SDL_Rect rect={450,(10-world.player.y)*100-world.player.y2*100,100,100}; + SDL_Rect rect={(show_tiles_back-0.5)*show_tiles_size,(show_tiles_vertical_move-world.player.y)*show_tiles_size-world.player.y2*show_tiles_size,show_tiles_size,show_tiles_size}; if(world.player.anim==0)SDL_RenderCopy(ren,textures[0],NULL,&rect); else SDL_RenderCopy(ren,textures[1],NULL,&rect); // HUD std::stringstream strbuffer; strbuffer << "SCORE:" << world.coins << " | LVL:" << world.level << " | FPS:" << fps << " | RES:"<<win_width << "*" << win_height ; - sdl_put_str(ren, textures[3],10, 10, 4,strbuffer.str(),190,190,222); + sdl_put_str(ren, textures[3],10, 10, 10,strbuffer.str(),222,255,222,60,win_width,win_height,1,1); + if(world.player.dead) { - SDL_SetRenderDrawColor(ren, 100,100,100, 255); - SDL_Rect rect2={250,350,1200,300}; - SDL_RenderFillRect(ren,&rect2); - sdl_put_str(ren, textures[3],300, 400, 7,"LUNATIC LEMMY DIED!",250,100,100); - sdl_put_str(ren, textures[3],280, 500, 4,"[click to retry]",200,190,222); + sdl_put_str(ren, textures[3],300, -1, 10,"LUNATIC LEMMY DIED!",250,100,100,19,win_width,win_height,1,2); + sdl_put_str(ren, textures[3],280, -1, 5,"[click to retry]",200,190,222,15,win_width,win_height,2,2); } + if(world.player.win) { - SDL_SetRenderDrawColor(ren, 100,100,100, 255); - SDL_Rect rect2={250,350,800,300}; - SDL_RenderFillRect(ren,&rect2); - sdl_put_str(ren, textures[3],300, 400, 7,"! LEVEL UP !",100,250,100); - sdl_put_str(ren, textures[3],280, 500, 4,"[click for next level]",100,250,222); + sdl_put_str(ren, textures[3],300, -1, 10," ! LEVEL UP ",100,250,100,22,win_width,win_height,1,2); + sdl_put_str(ren, textures[3],280, -1, 5,"[click for next level]",100,250,222,22,win_width,win_height,2,2); } + // - // finish rendering SDL_RenderPresent(ren); if(world.player.collected_coin) |
