mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
close window when loss
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "../io/colour/colour8.h"
|
#include "../io/colour/colour8.h"
|
||||||
#include "../io/input.h"
|
#include "../io/input.h"
|
||||||
|
#include "../io/window.h"
|
||||||
#include "../util/types.h"
|
#include "../util/types.h"
|
||||||
#include "../util/vec.h"
|
#include "../util/vec.h"
|
||||||
#include "./tetromino/shapes.h"
|
#include "./tetromino/shapes.h"
|
||||||
@@ -66,7 +67,9 @@ struct gamedata* game_init(void) {
|
|||||||
void game_update(int movdat, size_t time) {
|
void game_update(int movdat, size_t time) {
|
||||||
static time_t drop_timeout = 0;
|
static time_t drop_timeout = 0;
|
||||||
movdat |= MOVD & -!!time_poll(time, 200, &drop_timeout);
|
movdat |= MOVD & -!!time_poll(time, 200, &drop_timeout);
|
||||||
place_update(&dat, movdat);
|
|
||||||
|
if (place_update(&dat, movdat))
|
||||||
|
window_close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_free(void) {
|
void game_free(void) {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ static int plcmnt_intersect(u8* restrict const* restrict const rows, u8 const id
|
|||||||
plcmnt_valid(rows, pos + bpos[3]));
|
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)
|
// store the current index and ID, only changes when placed (which yields no movement) and rotation (which occurs last)
|
||||||
int tmp;
|
int tmp;
|
||||||
u8 id = gdat->pdat.cur;
|
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
|
clear_rows(gdat->rows, &gdat->pnts); // clear the rows that have been completed
|
||||||
next_shape();
|
next_shape();
|
||||||
audio_play(AUDIO_ID_PLACE);
|
audio_play(AUDIO_ID_PLACE);
|
||||||
|
|
||||||
|
if (plcmnt_intersect(gdat->rows, gdat->pdat.cur, gdat->pdat.sel))
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update X axis
|
// update X axis
|
||||||
@@ -112,4 +115,5 @@ void place_update(struct gamedata* gdat, int movdat) {
|
|||||||
// update roll
|
// update roll
|
||||||
tmp = id ^ (((!!(movdat & MOVRR) - !!(movdat & MOVRL)) * 8 + id) & 31);
|
tmp = id ^ (((!!(movdat & MOVRR) - !!(movdat & MOVRL)) * 8 + id) & 31);
|
||||||
gdat->pdat.cur ^= (tmp && !plcmnt_intersect(gdat->rows, id ^ tmp, gdat->pdat.sel)) * tmp;
|
gdat->pdat.cur ^= (tmp && !plcmnt_intersect(gdat->rows, id ^ tmp, gdat->pdat.sel)) * tmp;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
#include "../game.h"
|
#include "../game.h"
|
||||||
|
|
||||||
/* updates the movement of the pdat structure, updating the rows when colliding downwards.
|
/* updates the movement of the `pdat` structure, updating the rows when colliding downwards.
|
||||||
* closes window when the next shape intersects with the current one */
|
* returns `0` if we successfully updated. Returns 1 if we couldn't update. (e.g. when a next block immediately collides) */
|
||||||
void place_update(struct gamedata* gdat, int movdat);
|
int place_update(struct gamedata* gdat, int movdat);
|
||||||
|
|||||||
Reference in New Issue
Block a user