From 60699af63f92f43cc4b4b9e3050fcdd2a8468281 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Wed, 10 Apr 2019 15:14:00 -0400 Subject: add opengl fronend, remove sdl frontend, refactor build system --- core/include/cetris.h | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ core/include/input.h | 8 +++++ core/include/matrix.h | 15 ++++++++ core/include/test.h | 8 +++++ core/include/types.h | 19 ++++++++++ 5 files changed, 149 insertions(+) create mode 100644 core/include/cetris.h create mode 100644 core/include/input.h create mode 100644 core/include/matrix.h create mode 100644 core/include/test.h create mode 100644 core/include/types.h (limited to 'core/include') 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 + +#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 + +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 + +#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 + +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; -- cgit v1.2.3-101-g0448