Allow spawn rate option to work as intended

master
Tiehuis 9 years ago
parent a75c200842
commit 375cdeb7da
  1. 8
      src/engine.c
  2. 8
      src/main.c

@ -183,6 +183,9 @@ void gamestate_new_block(struct gamestate *g)
srand(time(NULL));
}
/* Exit early if there are no spaces to place a block */
if (g->blocks_in_play == g->gridsize) return;
/* Fix up this random number generator */
/* Method:
* - Find a non-biased index between 0 and blocks_play, n
@ -252,6 +255,11 @@ struct gamestate* gamestate_init(struct gameoptions *opt)
g->blocks_in_play = 0;
g->opts = opt;
/* Clamp spawn rate to maximum to avoid possible excessive calculation
* int generation of blocks */
if (g->opts->spawn_rate > g->gridsize)
g->opts->spawn_rate = g->gridsize;
highscore_load(g);
/* Initial 3 random blocks */

@ -47,18 +47,18 @@ get_new_key:;
/* Game will only end if 0 moves available */
if (game_running) {
/* Maybe change this behaviour so if we don't move, we still generate a block */
if (gamestate_tick(s, g, direction, g->opts->animate ? draw_then_sleep : NULL))
gamestate_tick(s, g, direction, g->opts->animate ? draw_then_sleep : NULL);
int spawned;
for (spawned = 0; spawned < g->opts->spawn_rate; spawned++)
gamestate_new_block(g);
if (gamestate_end_condition(g)) {
game_running = false;
goto game_end;
}
}
}
game_end:
gfx_destroy(s);
gamestate_clear(g);
return 0;

Loading…
Cancel
Save