summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiguel <miguel@localhost>2017-09-14 09:14:30 +0200
committermiguel <miguel@localhost>2017-09-14 09:14:30 +0200
commit551d539fc2b4612683611a64f0e0a97a5244d8f3 (patch)
treedc2ffb2c7a3430f0f5a80208f368fb8e02518ca7
parent1555b96b32a919c3e3b9e44ac1d80dab005d9ab8 (diff)
added scaling support
-rw-r--r--World.cpp20
-rw-r--r--coin.bmpbin10138 -> 1738 bytes
-rw-r--r--guy01.bmpbin480122 -> 1322 bytes
-rw-r--r--guy02.bmpbin640138 -> 1322 bytes
-rw-r--r--main.cpp78
5 files changed, 71 insertions, 27 deletions
diff --git a/World.cpp b/World.cpp
index 04801f5..5d17d42 100644
--- a/World.cpp
+++ b/World.cpp
@@ -39,9 +39,9 @@ void World::next_level()
reset();
bricks=
{
- { {0,1} },
- { {0,1} },
- { {0,1} },
+ { {0,2} },
+ { {0,2} },
+ { {0,2} },
{ {0,0},{5,1} },
{ {0,0},{5,1} },
{ {0,0},{5,1} },
@@ -86,7 +86,19 @@ void World::next_level()
{ {0,0}},
{ {0,0}},
{ {0,0}},
- { {0,0}}
+ { {0,0}},
+ { {1,0},{5,1} },
+ { {2,0},{5,1},{7,1} },
+ { {3,0},{6,1} },
+ {},
+ {},
+ {},
+ {},
+ { {0,1} },
+ { {0,1} },
+ { {0,1} },
+ { {0,0},{5,1} },
+ { {0,0},{5,1} },
};
}
diff --git a/coin.bmp b/coin.bmp
index a16d1c2..f128548 100644
--- a/coin.bmp
+++ b/coin.bmp
Binary files differ
diff --git a/guy01.bmp b/guy01.bmp
index 169f872..ac16086 100644
--- a/guy01.bmp
+++ b/guy01.bmp
Binary files differ
diff --git a/guy02.bmp b/guy02.bmp
index 5e89c77..c150e2c 100644
--- a/guy02.bmp
+++ b/guy02.bmp
Binary files differ
diff --git a/main.cpp b/main.cpp
index 2d84d8f..f796cd0 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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)