diff --git a/src/game/game.c b/src/game/game.c index 37fd323..a76d930 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -8,6 +8,7 @@ #include "../io/colour/colour8.h" #include "../io/input.h" +#include "../io/window.h" #include "../util/types.h" #include "../util/vec.h" #include "./tetromino/shapes.h" @@ -66,7 +67,9 @@ struct gamedata* game_init(void) { void game_update(int movdat, size_t time) { static time_t drop_timeout = 0; movdat |= MOVD & -!!time_poll(time, 200, &drop_timeout); - place_update(&dat, movdat); + + if (place_update(&dat, movdat)) + window_close(); } void game_free(void) { diff --git a/src/game/tetromino/placing.c b/src/game/tetromino/placing.c index be53ad8..7dcff2a 100644 --- a/src/game/tetromino/placing.c +++ b/src/game/tetromino/placing.c @@ -88,7 +88,7 @@ static int plcmnt_intersect(u8* restrict const* restrict const rows, u8 const id plcmnt_valid(rows, pos + bpos[3])); } -void place_update(struct gamedata* gdat, int movdat) { +int place_update(struct gamedata* gdat, int movdat) { // store the current index and ID, only changes when placed (which yields no movement) and rotation (which occurs last) int tmp; u8 id = gdat->pdat.cur; @@ -103,6 +103,9 @@ void place_update(struct gamedata* gdat, int movdat) { clear_rows(gdat->rows, &gdat->pnts); // clear the rows that have been completed next_shape(); audio_play(AUDIO_ID_PLACE); + + if (plcmnt_intersect(gdat->rows, gdat->pdat.cur, gdat->pdat.sel)) + return 1; } // update X axis @@ -112,4 +115,5 @@ void place_update(struct gamedata* gdat, int movdat) { // update roll tmp = id ^ (((!!(movdat & MOVRR) - !!(movdat & MOVRL)) * 8 + id) & 31); gdat->pdat.cur ^= (tmp && !plcmnt_intersect(gdat->rows, id ^ tmp, gdat->pdat.sel)) * tmp; + return 0; } diff --git a/src/game/tetromino/placing.h b/src/game/tetromino/placing.h index a990e48..0ba1152 100644 --- a/src/game/tetromino/placing.h +++ b/src/game/tetromino/placing.h @@ -5,6 +5,6 @@ #include "../game.h" -/* updates the movement of the pdat structure, updating the rows when colliding downwards. - * closes window when the next shape intersects with the current one */ -void place_update(struct gamedata* gdat, int movdat); +/* updates the movement of the `pdat` structure, updating the rows when colliding downwards. + * returns `0` if we successfully updated. Returns 1 if we couldn't update. (e.g. when a next block immediately collides) */ +int place_update(struct gamedata* gdat, int movdat);