summaryrefslogtreecommitdiff
path: root/core/include
diff options
context:
space:
mode:
Diffstat (limited to 'core/include')
-rw-r--r--core/include/cetris.h99
-rw-r--r--core/include/input.h8
-rw-r--r--core/include/matrix.h15
-rw-r--r--core/include/test.h8
-rw-r--r--core/include/types.h19
5 files changed, 149 insertions, 0 deletions
diff --git a/core/include/cetris.h b/core/include/cetris.h
new file mode 100644
index 0000000..8264842
--- /dev/null
+++ b/core/include/cetris.h
@@ -0,0 +1,99 @@
+#pragma once
+
+#include <stdint.h>
+
+#include "types.h"
+
+#define CETRIS_BOARD_X 10
+#define CETRIS_BOARD_Y 43
+#define CETRIS_BOARD_VISABLE 23
+
+#define CETRIS_HZ 60
+#define CETRIS_DAS_DELAY 11
+#define CETRIS_DAS_PERIOD 3
+#define CETRIS_DROP_PERIOD 2
+#define CETRIS_LINE_CLEAR_DELAY 40
+#define CETRIS_WAIT_ON_CLEAR 0
+
+typedef enum {
+ O, I, S, Z, L, J, T
+} type;
+
+typedef enum {
+ COLOR_NONE,
+ COLOR_O,
+ COLOR_I,
+ COLOR_S,
+ COLOR_Z,
+ COLOR_L,
+ COLOR_J,
+ COLOR_T
+} color;
+
+typedef enum {
+ INIT,
+ ONCE_RIGHT,
+ ONCE_LEFT,
+ TWICE
+} rstate;
+
+struct tetrimino {
+ type t;
+ rstate r;
+ color c;
+ piece_matrix m;
+ vec2 pos;
+ int lock_tick;
+};
+
+typedef struct {
+ uint8_t occupied;
+ uint8_t constant;
+ int remove_tick;
+ color c;
+} slot;
+
+struct cetris_game {
+ /* playfield represented by a 2d array */
+ slot board[CETRIS_BOARD_X][CETRIS_BOARD_Y];
+
+ /* constant queue of all 7 possible tetrimino */
+ struct tetrimino piece_queue[7];
+
+ /* current tetrimino */
+ struct tetrimino current;
+ uint8_t current_index;
+
+ /* input_manager */
+ uint8_t held_moves[7];
+ int das_repeat;
+ input_t prev_das_move;
+ int das_move_tick;
+ int down_move_tick;
+
+ /* internal game tick */
+ int tick;
+ int next_drop_tick;
+
+ /* progress trackers */
+ int lines;
+ uint8_t level;
+ uint8_t game_over;
+
+ /* scoring flags */
+ uint8_t tspin;
+ uint8_t mini_tspin;
+
+ /* long int just incase */
+ long int score;
+};
+
+void next_piece(struct cetris_game* g);
+void wipe_board(struct cetris_game* g);
+
+/* API PROTOTYPES FUNCTIONS */
+
+void init_game(struct cetris_game* g);
+void update_game_tick(struct cetris_game* g);
+void move_peice(struct cetris_game* g, input_t move);
+void stop_holding(struct cetris_game* g, input_t move);
diff --git a/core/include/input.h b/core/include/input.h
new file mode 100644
index 0000000..0092bb4
--- /dev/null
+++ b/core/include/input.h
@@ -0,0 +1,8 @@
+#pragma once
+
+#include <stdint.h>
+
+struct cetris_game;
+
+uint8_t handle_inputs(struct cetris_game* g);
+void clear_held_key(struct cetris_game* g);
diff --git a/core/include/matrix.h b/core/include/matrix.h
new file mode 100644
index 0000000..3ab0252
--- /dev/null
+++ b/core/include/matrix.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <stdint.h>
+
+#include "types.h"
+#include "cetris.h"
+
+extern const piece_matrix default_matrices[7];
+extern const vec2 basic_movements[4];
+
+void move_current(struct cetris_game* g, vec2 offset);
+void overlay_current_matrix(struct cetris_game* g);
+void hard_drop(struct cetris_game* g);
+void rotate_matrix(struct cetris_game* g, int clockwise);
+int8_t check_new_matrix(struct cetris_game* g, piece_matrix m);
diff --git a/core/include/test.h b/core/include/test.h
new file mode 100644
index 0000000..04fd09a
--- /dev/null
+++ b/core/include/test.h
@@ -0,0 +1,8 @@
+struct cetris_game;
+
+enum tests {
+ TSPIN,
+ TSPIN_NO_LINES
+};
+
+void apply_test_board(struct cetris_game* g, enum tests t);
diff --git a/core/include/types.h b/core/include/types.h
new file mode 100644
index 0000000..2ce97c7
--- /dev/null
+++ b/core/include/types.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <stdint.h>
+
+typedef uint8_t piece_matrix[4][4];
+
+typedef struct {
+ int8_t x;
+ int8_t y;
+} vec2;
+
+typedef enum {
+ DOWN = 1,
+ RIGHT = 2,
+ LEFT = 3,
+ ROTATE_CCW = 4,
+ ROTATE_CW = 5,
+ HARD_DROP = 6
+} input_t;