close window when loss

This commit is contained in:
2025-07-03 13:51:04 +02:00
parent 9cafbedad8
commit 507066d1a9
3 changed files with 12 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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);