diff options
| -rw-r--r-- | World.cpp | 40 | ||||
| -rw-r--r-- | World.h | 1 | ||||
| -rw-r--r-- | main.cpp | 33 |
3 files changed, 71 insertions, 3 deletions
@@ -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,6 +203,10 @@ 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; @@ -217,6 +223,36 @@ void World::mouseclick(int x, int y) } 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) + { + return; + } + if(brick.type<=1&&brick.altitude==y) + { + return; + } + if(brick.type>1&&brick.altitude==y) + { brick.type++; if(brick.type>=5) { @@ -229,6 +265,6 @@ void World::mouseclick(int x, int y) } bricks[x].push_back({y,2}); -// player.speed++; + player.speed++; } @@ -26,6 +26,7 @@ struct World std::vector<int> coins_pos; std::vector<std::vector<Brick>> bricks{{{}}}; + int next_stone; int level; int coins; World(int level); @@ -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;i<ctx->world.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;j<ctx->world.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:"<<ctx->win_width << "*" << ctx->win_height ; + strbuffer << "NEXT_STONE (see below)"<< " | SCORE:" << ctx->world.coins << " | LVL:" << ctx->world.level << " | FPS:" << ctx->fps << " | RES:"<<ctx->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); |
