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 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'World.cpp') 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++; } -- cgit v1.2.3