re-implement shape dropping

This commit is contained in:
2025-06-26 14:08:34 +02:00
parent d852eb2283
commit dd8fc37494
3 changed files with 10 additions and 4 deletions

View File

@@ -7,10 +7,12 @@
#include <time.h> #include <time.h>
#include "../io/colour/colour8.h" #include "../io/colour/colour8.h"
#include "../io/input.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"
#include "tetromino/placing.h" #include "tetromino/placing.h"
#include "time.h"
static colour8 rowdat[COLUMNS * ROWS] = {0}; // contains the raw data of the rows, in no particular order static colour8 rowdat[COLUMNS * ROWS] = {0}; // contains the raw data of the rows, in no particular order
static struct gamedata dat = {0}; static struct gamedata dat = {0};
@@ -63,7 +65,9 @@ struct gamedata* game_init(void) {
} }
// called every time the game's state is updated // called every time the game's state is updated
void game_update(int movdat) { void game_update(int movdat, size_t time) {
static time_t drop_timeout = 0;
movdat |= !!time_poll(time, 200, &drop_timeout) * MOVD;
place_update(&dat, movdat); place_update(&dat, movdat);
} }

View File

@@ -2,6 +2,7 @@
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include "../io/colour/colour8.h" #include "../io/colour/colour8.h"
#include "../util/types.h" #include "../util/types.h"
@@ -37,5 +38,5 @@ struct gamedata {
void next_shape(void); void next_shape(void);
struct gamedata* game_init(void); struct gamedata* game_init(void);
void game_update(int); void game_update(int movdat, size_t time);
void game_free(void); void game_free(void);

View File

@@ -48,11 +48,12 @@ void window_free(void) {
void window_open(void) { void window_open(void) {
while (!close) { while (!close) {
game_update(input_getdat()); size_t time = time_pull();
game_update(input_getdat(), time);
render_update(); render_update();
static time_t timeout = 0; static time_t timeout = 0;
if (time_poll(time_pull(), music.ms, &timeout)) if (time_poll(time, music.ms, &timeout))
audio_play(&music); audio_play(&music);
} }
} }