summaryrefslogtreecommitdiff
path: root/lib/cetris.h
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2026-07-18 13:34:49 -0400
committerAndrew Opalach <andrew@akon.city> 2026-07-18 13:45:01 -0400
commit72f5ec3ce777fc05150856f1841e60b0f5c9f8f7 (patch)
tree9b26fd3b314bcf3a2259704c076d819212f172f0 /lib/cetris.h
parente6b1631d27f9fe54f3cdd3d7ee1e65d726927e3c (diff)
downloadcetris-72f5ec3ce777fc05150856f1841e60b0f5c9f8f7.tar.gz
cetris-72f5ec3ce777fc05150856f1841e60b0f5c9f8f7.tar.bz2
cetris-72f5ec3ce777fc05150856f1841e60b0f5c9f8f7.zip
restore old frontends as they were
Minimal changes, just enough to get them building and running. Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'lib/cetris.h')
-rwxr-xr-xlib/cetris.h42
1 files changed, 24 insertions, 18 deletions
diff --git a/lib/cetris.h b/lib/cetris.h
index a400779..7525cd2 100755
--- a/lib/cetris.h
+++ b/lib/cetris.h
@@ -6,10 +6,6 @@
#include <string.h>
#include <time.h>
-#ifndef CETRIS_ENABLE_DAS
-#define CETRIS_ENABLE_DAS 1
-#endif
-
typedef struct
{
char x;
@@ -109,7 +105,8 @@ typedef struct
bool (*win_condition)(ctrs_game *);
} ctrs_config;
-typedef struct {
+typedef struct
+{
unsigned char move_event;
unsigned char hold_event;
@@ -123,10 +120,10 @@ typedef struct {
bool start_game;
bool stop_game;
-
} ctrs_events;
-struct ctrs_game {
+struct ctrs_game
+{
// playfield represented by a 2d array
unsigned char **board;
@@ -183,7 +180,7 @@ struct ctrs_game {
ctrs_config config;
};
-const ctrs_matrix ctrs_default_matrices[7] =
+static const ctrs_matrix ctrs_default_matrices[7] =
{
{ 0b0000, 0b1100, 0b0110, 0b0000},
{ 0b0000, 0b0010, 0b1110, 0b0000},
@@ -195,7 +192,8 @@ const ctrs_matrix ctrs_default_matrices[7] =
};
// https://tetris.wiki/SRS
-static const ctrs_vec2 srs_wall_kicks[8][5] = {
+static const ctrs_vec2 srs_wall_kicks[8][5] =
+{
{{0, 0}, {-1, 0}, {-1, 1}, {0, -2}, {-1, -2}}, // 0->R
{{0, 0}, {1, 0}, {1, -1}, {0, 2}, {1, 2}}, // R->0
{{0, 0}, {1, 0}, {1, -1}, {0, 2}, {1, 2}}, // R->2
@@ -206,7 +204,8 @@ static const ctrs_vec2 srs_wall_kicks[8][5] = {
{{0, 0}, {1, 0}, {1, 1}, {0, -2}, {1, -2}} // 0->L
};
-static const ctrs_vec2 srs_wall_kicks_i[8][5] = {
+static const ctrs_vec2 srs_wall_kicks_i[8][5] =
+{
{{0, 0}, {-2, 0}, {1, 0}, {-2, -1}, {1, 2}}, // 0->R
{{0, 0}, {2, 0}, {-1, 0}, {2, 1}, {-1, -2}}, // R->0
{{0, 0}, {-1, 0}, {2, 0}, {-1, 2}, {2, -1}}, // R->2
@@ -217,14 +216,15 @@ static const ctrs_vec2 srs_wall_kicks_i[8][5] = {
{{0, 0}, {-1, 0}, {2, 0}, {-1, 2}, {2, -1}} // 0->L
};
-static const ctrs_vec2 basic_movements[3] = {
+static const ctrs_vec2 basic_movements[3] =
+{
{0, 1}, {1, 0}, {-1, 0} // DOWN, RIGHT, LEFT
};
static void update_board(ctrs_game *g);
static void
-set_piece(ctrs_game *g, unsigned char type, ctrs_mino* mino)
+set_piece(ctrs_game *g, unsigned char type, ctrs_mino *mino)
{
memset(mino, 0, sizeof(ctrs_mino));
@@ -383,8 +383,10 @@ move_current(ctrs_game *g, unsigned char move)
g->events.move_event++;
if (g->current.lock_tick)
g->current.lock_tick = g->tick + g->config.lock_delay;
+#if CETRIS_ENABLE_DAS
if (move == DOWN && g->held_moves[DOWN])
g->score++;
+#endif
}
update_board(g);
@@ -652,7 +654,7 @@ update_board(ctrs_game *g)
if (g->lines >= (g->level * 10)) g->level++;
}
-void
+static void
ctrs_hold_piece(ctrs_game *g)
{
if (g->current.held) return;
@@ -676,8 +678,8 @@ ctrs_hold_piece(ctrs_game *g)
}
#if CETRIS_ENABLE_DAS
-void
-ctrs_unhold_move(ctrs_game* g, unsigned char move)
+static void
+ctrs_unhold_move(ctrs_game *g, unsigned char move)
{
if (!g->held_moves[move]) return;
@@ -706,7 +708,7 @@ ctrs_unhold_move(ctrs_game* g, unsigned char move)
}
#endif
-void
+static void
ctrs_move_piece(ctrs_game *g, unsigned char move)
{
#if CETRIS_ENABLE_DAS
@@ -752,7 +754,7 @@ ctrs_move_piece(ctrs_game *g, unsigned char move)
}
}
-void
+static void
ctrs_init_game(ctrs_game *g)
{
srand(time(NULL));
@@ -772,6 +774,8 @@ ctrs_init_game(ctrs_game *g)
g->line_remove_tick = (unsigned long *)calloc(g->config.board_y, sizeof(unsigned long));
+ g->events.lock_event.processed = true;
+
g->waiting = false;
g->level = g->config.starting_level;
@@ -787,7 +791,7 @@ ctrs_init_game(ctrs_game *g)
next_piece(g);
}
-bool
+static bool
ctrs_update_game_tick(ctrs_game *g)
{
if (g->game_over)
@@ -809,11 +813,13 @@ ctrs_update_game_tick(ctrs_game *g)
if (!g->next_drop_tick)
{
+#if CETRIS_ENABLE_DAS
if (g->held_moves[DOWN])
{
g->next_drop_tick = g->tick + g->config.drop_period;
}
else
+#endif
{
if (g->level <= 20)
g->next_drop_tick = g->tick + g->config.levels[g->level - 1];