From 871f17ae1096899ffb902f1dd99c0c8d14d1c665 Mon Sep 17 00:00:00 2001 From: miguel Date: Sat, 23 Sep 2017 12:29:16 +0200 Subject: random next stone --- World.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- World.h | 1 + main.cpp | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/World.cpp b/World.cpp index 5d17d42..10eb126 100644 --- a/World.cpp +++ b/World.cpp @@ -7,6 +7,7 @@ World::World(int l):level(l) level--; next_level(); reset(); + next_stone=2; } void World::reset() @@ -17,6 +18,7 @@ void World::reset() player.x2=player.x=0; player.speed=level; + player.speed=0; player.anim=0; player.y=bricks[0][0].altitude+1; player.y2=0; @@ -187,7 +189,7 @@ void World::sim(double time) return; } -// player.speed--; + player.speed--; } @@ -201,11 +203,45 @@ void World::sim(double time) void World::mouseclick(int x, int y) { + std::random_device rd; //Will be used to obtain a seed for the random number engine + std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() + std::uniform_int_distribution<> dis(2, 4); + if(player.dead){reset();return;} if(player.win){next_level();return;} if(x<0||x>=bricks.size())return; int idx=0; for(Brick &brick:bricks[x]) + { + if(brick.type==0&&brick.altitude>=y) + { + return; + } + if(brick.type<=1&&brick.altitude==y) + { + return; + } + if(brick.type>1&&brick.altitude==y) + { + // brick.type++; + // if(brick.type>=5) + // { + bricks[x].erase(bricks[x].begin()+idx); + // } + // return; + } + idx++; + + + } + bricks[x].push_back({y,next_stone}); + next_stone=dis(gen); + player.speed++; + return; + + if(x<0||x>=bricks.size())return; + idx=0; + for(Brick &brick:bricks[x]) { if(brick.type==0&&brick.altitude>=y) { @@ -229,6 +265,6 @@ void World::mouseclick(int x, int y) } bricks[x].push_back({y,2}); -// player.speed++; + player.speed++; } diff --git a/World.h b/World.h index 7a63093..1ba2471 100644 --- a/World.h +++ b/World.h @@ -26,6 +26,7 @@ struct World std::vector coins_pos; std::vector> bricks{{{}}}; + int next_stone; int level; int coins; World(int level); diff --git a/main.cpp b/main.cpp index 7c7e466..bd248af 100644 --- a/main.cpp +++ b/main.cpp @@ -355,16 +355,33 @@ void main_loop(void *arg) SDL_SetRenderDrawColor(ctx->ren, 0, 0, 0, 255); SDL_RenderClear(ctx->ren); + SDL_SetRenderDrawColor(ctx->ren, 0x99, 0x99, 0x99, 255); + + for(int j=1;j<12;j++) + { + SDL_Rect rect={0,(ctx->show_tiles_vertical_move-j)*ctx->show_tiles_size,ctx->show_tiles_size,ctx->show_tiles_size}; + rect.h=ctx->show_tiles_max_height; + rect.y+=ctx->show_tiles_size; + SDL_RenderDrawLine(ctx->ren,0,rect.y,ctx->win_width,rect.y); + } + // render visible area for(int i=ctx->world.player.x-ctx->show_tiles_back;iworld.player.x+ctx->show_tiles_front;i++) { int tile_col=i-ctx->world.player.x+ctx->show_tiles_back; if(i<0||i>=ctx->world.bricks.size())continue; + SDL_SetRenderDrawColor(ctx->ren, 0x99, 0x99, 0x99, 255); + SDL_RenderDrawLine(ctx->ren,(int)(tile_col*ctx->show_tiles_size-ctx->show_tiles_size*ctx->world.player.x2),ctx->win_height,(int)(tile_col*ctx->show_tiles_size-ctx->show_tiles_size*ctx->world.player.x2),0); + + + //coins SDL_Rect rect={(int)(tile_col*ctx->show_tiles_size-ctx->show_tiles_size*ctx->world.player.x2),(ctx->show_tiles_vertical_move-ctx->world.coins_pos[i])*ctx->show_tiles_size,ctx->show_tiles_size,ctx->show_tiles_size}; SDL_RenderCopy(ctx->ren,ctx->textures[2],NULL,&rect); + + for(int j=0;jworld.bricks[i].size();j++) { SDL_Rect rect={(int)(tile_col*ctx->show_tiles_size-ctx->show_tiles_size*ctx->world.player.x2),(ctx->show_tiles_vertical_move-ctx->world.bricks[i][j].altitude)*ctx->show_tiles_size,ctx->show_tiles_size,ctx->show_tiles_size}; @@ -410,9 +427,23 @@ void main_loop(void *arg) // HUD std::stringstream strbuffer; - strbuffer << "SCORE:" << ctx->world.coins << " | LVL:" << ctx->world.level << " | FPS:" << ctx->fps << " | RES:"<win_width << "*" << ctx->win_height ; + strbuffer << "NEXT_STONE (see below)"<< " | SCORE:" << ctx->world.coins << " | LVL:" << ctx->world.level << " | FPS:" << ctx->fps << " | RES:"<win_width << "*" << ctx->win_height ; sdl_put_str(ctx->ren, ctx->textures[3],10, 10, 10,strbuffer.str(),222,255,222,60,ctx->win_width,ctx->win_height,1,1); + rect={10,20,60,60}; + + switch(ctx->world.next_stone) + { + case 2: + SDL_RenderCopy(ctx->ren,ctx->textures[5],NULL,&rect); + break; + case 3: + SDL_RenderCopy(ctx->ren,ctx->textures[6],NULL,&rect); + break; + case 4: + SDL_RenderCopy(ctx->ren,ctx->textures[7],NULL,&rect); + break; + } if(ctx->world.player.dead) { sdl_put_str(ctx->ren, ctx->textures[3],300, -1, 10,"LUNATIC LEMMY DIED!",250,100,100,19,ctx->win_width,ctx->win_height,1,2); -- cgit v1.2.3