From f2b9a0842aef3a892c26ea84be61aabedb786458 Mon Sep 17 00:00:00 2001 From: John Landers Date: Sun, 14 Jan 2024 22:48:15 -0600 Subject: [PATCH] huge portion of rewrite done, basic movement updates to UI --- src/rewrite/block.h | 30 +-- src/rewrite/m_block.c | 372 +++++++++++++++++++++++++++++--- src/rewrite/m_block.h | 31 ++- src/rewrite/m_tetromino.c | 45 +++- src/rewrite/m_tetromino.h | 7 +- src/rewrite/point.h | 14 +- src/rewrite/r_block.c | 87 ++++---- src/rewrite/r_ui.c | 35 +-- src/rewrite/resources/black.png | Bin 881 -> 4847 bytes src/rewrite/tc_input.c | 22 +- src/rewrite/tc_main.c | 99 ++++----- src/rewrite/tc_settings.c | 10 +- src/rewrite/tc_settings.h | 3 +- src/rewrite/tc_window.c | 13 +- 14 files changed, 573 insertions(+), 195 deletions(-) diff --git a/src/rewrite/block.h b/src/rewrite/block.h index a8b9369..6d098a2 100644 --- a/src/rewrite/block.h +++ b/src/rewrite/block.h @@ -2,24 +2,24 @@ #define BLOCK_H_ #include "point.h" -/* still unsure how i want to name structs and enums */ +/* Not sure where this should belong tbh */ +#define BLOCKS_WITHIN_A_TETROMINO 4 -typedef enum btype_t -{ - bt_I, - bt_J, - bt_L, - bt_O, - bt_S, - bt_T, - bt_Z, - bt_Empty +typedef enum btype_t { + bt_Empty, + bt_I, + bt_J, + bt_L, + bt_O, + bt_S, + bt_T, + bt_Z } btype_t; -typedef struct block_t -{ - point_t point; - btype_t type; +typedef struct block_t { + int id; + point_t point; + btype_t type; } block_t; #endif /* BLOCK_H_ */ diff --git a/src/rewrite/m_block.c b/src/rewrite/m_block.c index 127e489..f20ab5c 100644 --- a/src/rewrite/m_block.c +++ b/src/rewrite/m_block.c @@ -1,5 +1,8 @@ #include "m_block.h" + +#include #include +#include #define BLOCK_ARRAY_COLUMNS 10 #define BLOCK_ARRAY_ROWS 20 @@ -7,44 +10,357 @@ block_t *_blocks[BLOCK_ARRAY_LENGTH]; block_t *_updated_blocks[BLOCK_ARRAY_LENGTH]; -int updated_blocks_current_length = 0; +block_t *_recently_spawned_blocks[BLOCKS_WITHIN_A_TETROMINO]; +int _updated_blocks_current_length = 0; +int _spawn_tetromino_flag = 1; +int _can_spawn_tetromino_flag = 1; +btype_t _next_block_type = bt_Empty; +const int _spawn_x = BLOCK_ARRAY_COLUMNS / 2 - 1; +const point_offset_t _shift_down_offset = {0, 1}; +const point_offset_t _shift_left_offset = {-1, 0}; +const point_offset_t _shift_right_offset = {1, 0}; +void (*on_block_spawn)(block_t *blocks[BLOCKS_WITHIN_A_TETROMINO]); -void M_Create_Blocks(void) -{ - int i; - for (i = 0; i < BLOCK_ARRAY_LENGTH; i++) - { - block_t *block = malloc(sizeof(block_t)); - block->point.x = i % BLOCK_ARRAY_COLUMNS; - block->point.y = i / BLOCK_ARRAY_COLUMNS; - block->type = bt_Empty; +void M_B_Create_Blocks(void) { + int i; + for (i = 0; i < BLOCK_ARRAY_LENGTH; i++) { + block_t *block = malloc(sizeof(block_t)); + block->id = -1; + block->point.x = i % BLOCK_ARRAY_COLUMNS; + block->point.y = i / BLOCK_ARRAY_COLUMNS; + block->type = bt_Empty; - _blocks[i] = block; + _blocks[i] = block; + } +} + +void M_B_Update_Blocks(void) { + M_B_Reset_Blocks_Updated(); + if (_spawn_tetromino_flag) { + M_B_Spawn_Blocks(); + M_B_Set_Next_Block_Type(); + _spawn_tetromino_flag = 0; + } +} + +block_t **M_B_Get_Blocks(int *length) { + *length = BLOCK_ARRAY_LENGTH; + return _blocks; +} + +block_t **M_B_Get_Updated_Blocks(int *length) { + *length = _updated_blocks_current_length; + return _updated_blocks; +} + +void M_B_Destroy_Blocks(void) { + int i; + for (i = 0; i < BLOCK_ARRAY_LENGTH; i++) { + free(_blocks[i]); + } +} + +void M_B_Reset_Blocks_Updated(void) { _updated_blocks_current_length = 0; } + +void M_B_On_Block_Spawn(void (*callback)(block_t **blocks)) { + on_block_spawn = callback; +} + +void M_B_Spawn_Blocks(void) { + struct point_offset_t offsets[BLOCKS_WITHIN_A_TETROMINO]; + + if (_next_block_type == bt_Empty) { + M_B_Set_Next_Block_Type(); + } + + switch (_next_block_type) { + case bt_I: + offsets[0].x_offset = 0; + offsets[0].y_offset = 0; + + offsets[1].x_offset = 0; + offsets[1].y_offset = 1; + + offsets[2].x_offset = 0; + offsets[2].y_offset = 2; + + offsets[3].x_offset = 0; + offsets[3].y_offset = 3; + break; + case bt_J: + offsets[0].x_offset = 2; + offsets[0].y_offset = 0; + + offsets[1].x_offset = 0; + offsets[1].y_offset = 1; + + offsets[2].x_offset = 1; + offsets[2].y_offset = 1; + + offsets[3].x_offset = 2; + offsets[3].y_offset = 1; + break; + case bt_L: + offsets[0].x_offset = 0; + offsets[0].y_offset = 0; + + offsets[1].x_offset = 0; + offsets[1].y_offset = 1; + + offsets[2].x_offset = 1; + offsets[2].y_offset = 1; + + offsets[3].x_offset = 2; + offsets[3].y_offset = 1; + break; + case bt_O: + offsets[0].x_offset = 0; + offsets[0].y_offset = 0; + + offsets[1].x_offset = 1; + offsets[1].y_offset = 0; + + offsets[2].x_offset = 0; + offsets[2].y_offset = 1; + + offsets[3].x_offset = 1; + offsets[3].y_offset = 1; + break; + case bt_S: + offsets[0].x_offset = 1; + offsets[0].y_offset = 0; + + offsets[1].x_offset = 2; + offsets[1].y_offset = 0; + + offsets[2].x_offset = 0; + offsets[2].y_offset = 1; + + offsets[3].x_offset = 1; + offsets[3].y_offset = 1; + break; + case bt_T: + offsets[0].x_offset = 1; + offsets[0].y_offset = 0; + + offsets[1].x_offset = 0; + offsets[1].y_offset = 1; + + offsets[2].x_offset = 1; + offsets[2].y_offset = 1; + + offsets[3].x_offset = 2; + offsets[3].y_offset = 1; + break; + case bt_Z: + offsets[0].x_offset = 0; + offsets[0].y_offset = 0; + + offsets[1].x_offset = 1; + offsets[1].y_offset = 0; + + offsets[2].x_offset = 1; + offsets[2].y_offset = 1; + + offsets[3].x_offset = 2; + offsets[3].y_offset = 1; + break; + default: + break; + } + if (M_B_Try_Spawn_Blocks_With_Offset(offsets)) { + on_block_spawn(_recently_spawned_blocks); + } +} + +void M_B_Set_Next_Block_Type(void) { + _next_block_type = M_B_Get_Random_Block_Type(); +} + +btype_t M_B_Get_Random_Block_Type(void) { + srand(time(NULL)); + return (btype_t)(rand() % 7) + 1; +} + +int M_B_Try_Spawn_Blocks_With_Offset(point_offset_t *offsets) { + int i = 0, kinda_unique_id = M_B_Generate_Block_Id(); + point_t spawn_point; + block_t *spawn_block; + while (i < BLOCKS_WITHIN_A_TETROMINO) { + spawn_point.x = _spawn_x + offsets->x_offset; + spawn_point.y = offsets->y_offset; + + spawn_block = M_B_Get_Block_At_Point(spawn_point); + if (spawn_block->type != bt_Empty) { + _can_spawn_tetromino_flag = 0; + return 0; } + spawn_block->id = kinda_unique_id; + M_B_Set_Block_Type(spawn_block, _next_block_type); + + _recently_spawned_blocks[i] = spawn_block; + + i++; + offsets++; + } + + return 1; } -void M_Update_Blocks(void) -{ - /* implement */ +block_t *M_B_Get_Block_At_Point(point_t point) { + return _blocks[(point.x % BLOCK_ARRAY_COLUMNS) + + (point.y * BLOCK_ARRAY_COLUMNS)]; } -block_t **M_Get_Blocks(int *length) -{ - *length = BLOCK_ARRAY_LENGTH; - return _blocks; +void M_B_Set_Block_Type(block_t *block, btype_t type) { + block->type = type; + M_B_Register_Updated_block(block); } -block_t **M_Get_Updated_Blocks(int *length) -{ - *length = updated_blocks_current_length; - return _updated_blocks; +void M_B_Register_Updated_block(block_t *block) { + if (_updated_blocks_current_length < BLOCK_ARRAY_LENGTH) { + _updated_blocks[_updated_blocks_current_length] = block; + _updated_blocks_current_length++; + } } -void M_Destroy_Blocks(void) -{ - int i; - for (i = 0; i < BLOCK_ARRAY_LENGTH; i++) - { - free(_blocks[i]); +int M_B_Can_Move_Blocks_Left(block_t **blocks) { + int i = 0, result = 1; + for (; i < BLOCKS_WITHIN_A_TETROMINO; i++) { + if (!M_B_Can_Move_Block_Left(*(blocks[i]))) { + result = 0; + break; } + } + + return result; +} + +int M_B_Can_Move_Block_Left(block_t block) { + point_t left_adj_block_point; + left_adj_block_point.x = block.point.x - 1; + left_adj_block_point.y = block.point.y; + if (left_adj_block_point.x < 0) { + return 0; + } else if (M_B_Point_Intersects_Static_Block(left_adj_block_point, + block.id)) { + return 0; + } else { + return 1; + } +} + +block_t *M_B_Move_Block_Left(block_t *block) { + /* Kinda dupe from right and down, might consolidate */ + block_t *updated_block = M_B_Get_Block_At_Offset(block, _shift_left_offset); + updated_block->id = block->id; + M_B_Set_Block_Type(updated_block, block->type); + block->id = -1; + M_B_Set_Block_Type(block, bt_Empty); + + return updated_block; +} + +int M_B_Can_Move_Blocks_Right(block_t **blocks) { + int i = 0, result = 1; + for (; i < BLOCKS_WITHIN_A_TETROMINO; i++) { + if (!M_B_Can_Move_Block_Right(*(blocks[i]))) { + result = 0; + break; + } + } + + return result; +} + +int M_B_Can_Move_Block_Right(block_t block) { + point_t right_adj_block_point; + right_adj_block_point.x = block.point.x + 1; + right_adj_block_point.y = block.point.y; + if (right_adj_block_point.x >= BLOCK_ARRAY_COLUMNS) { + return 0; + } else if (M_B_Point_Intersects_Static_Block(right_adj_block_point, + block.id)) { + + return 0; + } else { + return 1; + } +} + +block_t *M_B_Move_Block_Right(block_t *block) { + block_t *updated_block = M_B_Get_Block_At_Offset(block, _shift_right_offset); + updated_block->id = block->id; + M_B_Set_Block_Type(updated_block, block->type); + block->id = -1; + M_B_Set_Block_Type(block, bt_Empty); + + return updated_block; +} + +int M_B_Can_Move_Blocks_Down(block_t **blocks) { + int i = 0, result = 1; + for (; i < BLOCKS_WITHIN_A_TETROMINO; i++) { + if (!M_B_Can_Move_Block_Down(*(blocks[i]))) { + result = 0; + break; + } + } + + if (!result) { + _spawn_tetromino_flag = 1; + } + + return result; +} + +int M_B_Can_Move_Block_Down(block_t block) { + point_t bottom_adj_block_point; + bottom_adj_block_point.x = block.point.x; + bottom_adj_block_point.y = block.point.y + 1; + if (bottom_adj_block_point.y >= BLOCK_ARRAY_ROWS) { + return 0; + } else if (M_B_Point_Intersects_Static_Block(bottom_adj_block_point, + block.id)) { + return 0; + } else { + return 1; + } +} + +block_t *M_B_Move_Block_Down(block_t *block) { + block_t *updated_block = M_B_Get_Block_At_Offset(block, _shift_down_offset); + updated_block->id = block->id; + M_B_Set_Block_Type(updated_block, block->type); + block->id = -1; + M_B_Set_Block_Type(block, bt_Empty); + + return updated_block; +} + +block_t *M_B_Get_Block_At_Offset(block_t *block, point_offset_t offset) { + point_t updated_point; + updated_point.x = block->point.x + offset.x_offset; + updated_point.y = block->point.y + offset.y_offset; + + return M_B_Get_Block_At_Point(updated_point); +} + +int M_B_Point_Intersects_Static_Block(point_t point, int id) { + int result = 0; + + block_t *block_at_point = M_B_Get_Block_At_Point(point); + + if (block_at_point->type != bt_Empty && block_at_point->id != id) { + result = 1; + } + return result; +} + +int M_B_Generate_Block_Id(void) { + /* The odds of this not being unique are high enough, surely + SURELY + */ + srand(time(NULL)); + return rand(); } diff --git a/src/rewrite/m_block.h b/src/rewrite/m_block.h index ed54519..af9ef73 100644 --- a/src/rewrite/m_block.h +++ b/src/rewrite/m_block.h @@ -2,10 +2,31 @@ #define M_BLOCK_H_ #include "block.h" -void M_Create_Blocks(void); -void M_Update_Blocks(void); -block_t **M_Get_Blocks(int *length); -block_t **M_Get_Updated_Blocks(int *length); -void M_Destroy_Blocks(void); +void M_B_Create_Blocks(void); +void M_B_Update_Blocks(void); +block_t **M_B_Get_Blocks(int *length); +block_t **M_B_Get_Updated_Blocks(int *length); +void M_B_Destroy_Blocks(void); +void M_B_Reset_Blocks_Updated(void); +void M_B_Spawn_Blocks(void); +void M_B_Set_Next_Block_Type(void); +btype_t M_B_Get_Random_Block_Type(void); +int M_B_Try_Spawn_Blocks_With_Offset(point_offset_t *offsets); +block_t *M_B_Get_Block_At_Point(point_t point); +void M_B_Set_Block_Type(block_t *block, btype_t type); +void M_B_Register_Updated_block(block_t *block); +int M_B_Can_Move_Blocks_Left(block_t **blocks); +int M_B_Can_Move_Block_Left(block_t block); +block_t *M_B_Move_Block_Left(block_t *block); +int M_B_Can_Move_Blocks_Right(block_t **blocks); +int M_B_Can_Move_Block_Right(block_t block); +block_t *M_B_Move_Block_Right(block_t *block); +int M_B_Can_Move_Blocks_Down(block_t **blocks); +int M_B_Can_Move_Block_Down(block_t block); +block_t *M_B_Move_Block_Down(block_t *block); +block_t *M_B_Get_Block_At_Offset(block_t *block, point_offset_t offset); +void M_B_On_Block_Spawn(void (*callback)(block_t **blocks)); +int M_B_Point_Intersects_Static_Block(point_t point, int id); +int M_B_Generate_Block_Id(void); #endif /* M_BLOCK_H_ */ diff --git a/src/rewrite/m_tetromino.c b/src/rewrite/m_tetromino.c index 21c8e4d..e7bcf4f 100644 --- a/src/rewrite/m_tetromino.c +++ b/src/rewrite/m_tetromino.c @@ -1,6 +1,45 @@ #include "m_tetromino.h" +#include "m_block.h" -void M_Update_Tetromino(void) -{ - /* implement */ +/* Blocks are gauranteed to be in order top left to bottom right */ +block_t *_tetromino_blocks[BLOCKS_WITHIN_A_TETROMINO]; +int registered_flag = 0; + +void M_T_Update_Tetromino(void) { M_T_Tetromino_Fall(); } + +void M_T_Tetromino_Fall(void) { + int i; + if (registered_flag && M_B_Can_Move_Blocks_Down(_tetromino_blocks)) { + for (i = BLOCKS_WITHIN_A_TETROMINO - 1; i >= 0; i--) { + _tetromino_blocks[i] = M_B_Move_Block_Down(_tetromino_blocks[i]); + } + } +} + +void M_T_Register_Falling_Blocks(block_t *blocks[BLOCKS_WITHIN_A_TETROMINO]) { + int i; + if (!registered_flag) { + registered_flag = 1; + } + for (i = 0; i < BLOCKS_WITHIN_A_TETROMINO; i++) { + _tetromino_blocks[i] = blocks[i]; + } +} + +void M_T_Move_Tetromino_Left(void) { + int i; + if (registered_flag && M_B_Can_Move_Blocks_Left(_tetromino_blocks)) { + for (i = 0; i < BLOCKS_WITHIN_A_TETROMINO; i++) { + _tetromino_blocks[i] = M_B_Move_Block_Left(_tetromino_blocks[i]); + } + } +} + +void M_T_Move_Tetromino_Right(void) { + int i; + if (registered_flag && M_B_Can_Move_Blocks_Right(_tetromino_blocks)) { + for (i = BLOCKS_WITHIN_A_TETROMINO - 1; i >= 0; i--) { + _tetromino_blocks[i] = M_B_Move_Block_Right(_tetromino_blocks[i]); + } + } } diff --git a/src/rewrite/m_tetromino.h b/src/rewrite/m_tetromino.h index 1f57c65..58279bb 100644 --- a/src/rewrite/m_tetromino.h +++ b/src/rewrite/m_tetromino.h @@ -2,6 +2,11 @@ #define M_TETROMINO_H_ #include "block.h" -void M_Update_Tetromino(void); +void M_T_Update_Tetromino(void); +void M_T_Apply_To_Tetromino_Blocks(block_t *(*callback)(block_t *block)); +void M_T_Tetromino_Fall(void); +void M_T_Register_Falling_Blocks(block_t **blocks); +void M_T_Move_Tetromino_Left(void); +void M_T_Move_Tetromino_Right(void); #endif /* M_TETROMINO_H_ */ diff --git a/src/rewrite/point.h b/src/rewrite/point.h index a6ae79e..730ab60 100644 --- a/src/rewrite/point.h +++ b/src/rewrite/point.h @@ -2,16 +2,14 @@ #define POINT_H_ #include "point.h" -typedef struct point_t -{ - unsigned int x; - unsigned int y; +typedef struct point_t { + int x; + int y; } point_t; -typedef struct point_offset_t -{ - int xOffset; - int yOffset; +typedef struct point_offset_t { + int x_offset; + int y_offset; } point_offset_t; #endif /* POINT_H_ */ diff --git a/src/rewrite/r_block.c b/src/rewrite/r_block.c index 40e65fa..69e8717 100644 --- a/src/rewrite/r_block.c +++ b/src/rewrite/r_block.c @@ -1,7 +1,7 @@ #include "r_block.h" + #include "sc_def.h" -#define RES_PNG_FILE(name) "resources/" #name ".png" #define TEXTURE_SIZE 32 Texture2D yellow_texture; @@ -13,55 +13,50 @@ Texture2D green_texture; Texture2D orange_texture; Texture2D empty_texture; -void R_Load_Textures(void) -{ - yellow_texture = LoadTexture(RES_PNG_FILE(yellow)); - blue_texture = LoadTexture(RES_PNG_FILE(blue)); - light_blue_texture = LoadTexture(RES_PNG_FILE(light - blue)); - red_texture = LoadTexture(RES_PNG_FILE(red)); - purple_texture = LoadTexture(RES_PNG_FILE(purple)); - green_texture = LoadTexture(RES_PNG_FILE(green)); - orange_texture = LoadTexture(RES_PNG_FILE(orange)); - empty_texture = LoadTexture(RES_PNG_FILE(black)); +void R_Load_Textures(void) { + yellow_texture = LoadTexture("resources/yellow.png"); + blue_texture = LoadTexture("resources/blue.png"); + light_blue_texture = LoadTexture("resources/light-blue.png"); + red_texture = LoadTexture("resources/red.png"); + purple_texture = LoadTexture("resources/purple.png"); + green_texture = LoadTexture("resources/green.png"); + orange_texture = LoadTexture("resources/orange.png"); + empty_texture = LoadTexture("resources/black.png"); } -void R_Draw_Blocks(block_t **blocks, int block_count) -{ - BeginDrawing(); - while (block_count--) - { - R_Draw_Block(*(*blocks)); - blocks++; - } - /* implement */ - EndDrawing(); +void R_Draw_Blocks(block_t **blocks, int block_count) { + BeginDrawing(); + while (block_count--) { + R_Draw_Block(*(*blocks)); + blocks++; + } + /* implement */ + EndDrawing(); } -void R_Draw_Block(block_t block) -{ - Texture2D *texture = __R_Get_Texture_By_Block_Type(block.type); - DrawTexture(*texture, block.point.x * TEXTURE_SIZE, block.point.y * TEXTURE_SIZE, SC_White); +void R_Draw_Block(block_t block) { + Texture2D *texture = __R_Get_Texture_By_Block_Type(block.type); + DrawTexture(*texture, block.point.x * TEXTURE_SIZE, + block.point.y * TEXTURE_SIZE, SC_White); } -Texture2D *__R_Get_Texture_By_Block_Type(btype_t block_type) -{ - switch (block_type) - { - case bt_O: - return &yellow_texture; - case bt_I: - return &light_blue_texture; - case bt_T: - return &purple_texture; - case bt_J: - return &blue_texture; - case bt_L: - return &orange_texture; - case bt_S: - return &green_texture; - case bt_Z: - return &red_texture; - default: - return &empty_texture; - } +Texture2D *__R_Get_Texture_By_Block_Type(btype_t block_type) { + switch (block_type) { + case bt_O: + return &yellow_texture; + case bt_I: + return &light_blue_texture; + case bt_T: + return &purple_texture; + case bt_J: + return &blue_texture; + case bt_L: + return &orange_texture; + case bt_S: + return &green_texture; + case bt_Z: + return &red_texture; + default: + return &empty_texture; + } } diff --git a/src/rewrite/r_ui.c b/src/rewrite/r_ui.c index acb7121..5ca4fc8 100644 --- a/src/rewrite/r_ui.c +++ b/src/rewrite/r_ui.c @@ -2,20 +2,27 @@ #include "raylib.h" #include "sc_def.h" -void R_Draw_Ui(void) -{ - BeginDrawing(); - DrawRectangle(SC_GAME_WIDTH, 0, SC_UI_WIDTH, SC_HEIGHT, SC_Gray); - EndDrawing(); +#define UI_PADDING 16 + +void R_Draw_Ui(void) { + int up_next_box_size; + BeginDrawing(); + DrawRectangle(SC_GAME_WIDTH, 0, SC_UI_WIDTH, SC_HEIGHT, SC_Gray); + up_next_box_size = SC_UI_WIDTH - UI_PADDING * 3; + DrawRectangle(SC_GAME_WIDTH + UI_PADDING, 0 + UI_PADDING, up_next_box_size, + up_next_box_size, SC_Black); + EndDrawing(); } -void R_Draw_Game_Over(int score) -{ - const char *score_message = TextFormat("Score: %d", score); - BeginDrawing(); - DrawRectangle(0, 0, SC_GAME_WIDTH, SC_HEIGHT, SC_Black); - DrawText("Game Over", SC_GAME_WIDTH / 2 - MeasureText("Game Over", 24) / 2, 200, 24, SC_Red); - DrawText(score_message, SC_GAME_WIDTH / 2 - MeasureText(score_message, 18) / 2, 232, 18, SC_Red); - /* Draw a play again button */ - EndDrawing(); +void R_Draw_Game_Over(int score) { + const char *score_message = TextFormat("Score: %d", score); + BeginDrawing(); + DrawRectangle(0, 0, SC_GAME_WIDTH, SC_HEIGHT, SC_Black); + DrawText("Game Over", SC_GAME_WIDTH / 2 - MeasureText("Game Over", 24) / 2, + 200, 24, SC_Red); + DrawText(score_message, + SC_GAME_WIDTH / 2 - MeasureText(score_message, 18) / 2, 232, 18, + SC_Red); + /* Draw a play again button */ + EndDrawing(); } diff --git a/src/rewrite/resources/black.png b/src/rewrite/resources/black.png index d0f2187ad676479054224529fd175f3ddcdb42c3..09270a5d84f728f631c341a3be0572bb86cae127 100644 GIT binary patch literal 4847 zcmeHKc~leU79Y?8A}HX7h&YW!L7c2Z5@I4?f)FK?2goAIaV9f~BiTp-gosK}(2B)f zQSk|Cae0ahSQMX60dYl(byr+#g<2ICLBvfYubLk!+Doe zy>;>;DYCY3$f|h!-s10&**g*^Pj0xe``Nw)Z&wQo`#LQzT03Xf+xnxYen+-<-b8 z=xOIdI~W0pZS9VENH>S)vHe_aDR{fBfbPO$2KhdR!t!ZD8{7{k3pbbV(Bq4GJqT0G zsBT`Hy@57}s4dXVMLo_(%2wc$d`HXHOxl^Cuk&r(b$um1<$^m(#ZI}n`SS72-e*e` zvAYJ-v$w9BM4!5ARg_<5Y<#JyazgQy6SAo)-|~j?1i#&Bo}0X8KRT3Lkz^h&B;a{V zgvM(=TT09C`|M7UB`2jGIIt`A{&ra(&Uy6ZC915>yg#kp9Jgu45B;u~TAzt&4-3nFWNJe2tnl;KVWpGPiPd~rrEZ8xd1>A3 zyo#ddi+OWbAG&)Vf^=sd7%##U6T9euH!?RcOPj zZw}6vzS*5L?3(lK%KwZQ^0d9$?z*P^*}rm>?F(}~Pp!%<SI?A_wMnluQcQ*)Po{^;G1>v5Od< z2OLATyUfao9UiV}b6Jmm<4e!aPOhptiC?a&O^CCP3wFuO;*aC|R)&4wI4Wl_%j;mn z(vE+2G~PDY6vyK0FLNDdR;o+fQdldeyNdTX6b*9?$Ac7WSbkFJn=4mEsnNG;O>5@e z*>w5Ghhyz}OYRR<6mXvlo?j|a>u!(E-@AF2+ol0a3yi_{LreXPK{qF>wXj)!a>pj9N_lsZw(YF{jJB06v!e67Y(zJY)uu*Aw`QFkUetVgne6)N?D7Sf zUZ%h;+B3FCDuNn!@+wXQM2yHn&yC6G<>_f#^VON8ml^4ye>A**Le(|fuQch)y)(z* zU|xDqU@peX!Ub}znvM}#oTQu7IxsgONEm3+Ve(|s2;-!Z(uioyhmX==iV)G_{AEm; zPE5|E!pwRy+8hxhHz&&j2wLEHN1;go0Mw)rgH39c#vm|>XjWVSxVMNIG}x+QOcv4N zWs$I0t0!TUj?$S(h>1#L)5bf(LOr1nL`f!gL4YR_ZKlzv6EGO*>FM-z4qdBPGFSlt z0SqRa!Db^s12JT1jF<`07)DwkIx!@qL9VBCMoO!JEtnXtO*M*WG_VeL$EViGWFO!) zhAtKW9}E+wW3cEII<@MA^%{n zOVz8a=@4=TsUp=t)d0M*K5-c;l|_EAuu!0+)Hq*S0)yHVH zDiO^B0b4As?F|b%ixNf|fJTO;f8b<%DM!@*0vR3@=hlPER7_rj(}a~ zl6)qnQIcSPcQsVEocfDmp&S;$<6?kUHVa2koJ}AB1j$2~Og2H1DA%8Zlb@m+v1DRbY$B~AnBtE zOE5rC-vO4(23lX}4utkbsVv04$)?{x{=h#6_j?FL}6-aGiUb0+3C}R{k!`Sae!y57rh=%-`7Lk2opfJ|?nOij2 zn?Ooe%=YIJ+gc`a^OxpTIa78gg6tE@qz$QKX7>FZAhYLD3-#qnrD;KIy{cpyR@cEw zq`N*;cHL9<9M;Zk^4h>FWH^Z><&7& zG9VX~VD~^VI4^g4BPufmcjpl7I_IweG4D@{j8vG>$19v62i4Ek70Q+n4O)+%_pa@B za38DV^H<+~|2W=>2Yd19*WZs{?z}tPdHMAwzwge+!=u|fj~>4sx26kla=QBb +#include + #include "m_block.h" #include "m_tetromino.h" #include "r_block.h" @@ -5,76 +8,62 @@ #include "tc_input.h" #include "tc_settings.h" #include "tc_window.h" -#include -#include -#include void TC_Start(void); void TC_Initialize(void); void TC_Game_Loop(void); void TC_Stop(void); -int main(int c, char *v[]) -{ - /* Move somwhere else to parse options */ - /* =================================== */ - if (c > 1) - { - if (strcmp(v[1], "--speed") == 0) - { - TC_Set_Game_Speed(atoi(v[2])); - } +int main(int c, char *v[]) { + /* Move somwhere else to parse options */ + /* =================================== */ + if (c > 1) { + if (strcmp(v[1], "--speed") == 0) { + TC_Set_Game_Speed(atoi(v[2])); } - /* =================================== */ + } + /* =================================== */ - TC_Start(); - TC_Stop(); + TC_Start(); + TC_Stop(); } -void TC_Start(void) -{ - TC_Initialize(); - TC_Game_Loop(); +void TC_Start(void) { + TC_Initialize(); + TC_Game_Loop(); } -void TC_Initialize(void) -{ - int n_blocks_created = 0; - block_t **blocks_created = NULL; - TC_Create_Window(); - M_Create_Blocks(); - R_Load_Textures(); - blocks_created = M_Get_Blocks(&n_blocks_created); - R_Draw_Blocks(blocks_created, n_blocks_created); +void TC_Initialize(void) { + int n_blocks_created = 0; + block_t **blocks_created = NULL; + TC_Create_Window(); + M_B_Create_Blocks(); + M_B_On_Block_Spawn(&M_T_Register_Falling_Blocks); + R_Load_Textures(); + blocks_created = M_B_Get_Blocks(&n_blocks_created); + R_Draw_Blocks(blocks_created, n_blocks_created); } -void TC_Game_Loop(void) -{ - int tick_rate, n_updated_blocks = 0; - block_t **updated_blocks = NULL; - while (!TC_Close_Window()) - { - R_Draw_Ui(); - if (tick_rate == 0) - { - TC_Process_Input(); - M_Update_Tetromino(); - M_Update_Blocks(); - M_Get_Updated_Blocks(&n_updated_blocks); - R_Draw_Blocks(updated_blocks, n_updated_blocks); - tick_rate = game_speed_setting; - } - else - { - tick_rate--; - } +void TC_Game_Loop(void) { + int tick_rate = 0, n_updated_blocks = 0; + block_t **updated_blocks = NULL; + while (!TC_Close_Window()) { + R_Draw_Ui(); + if (tick_rate == 0) { + TC_Process_Input(); + M_T_Update_Tetromino(); + M_B_Update_Blocks(); + updated_blocks = M_B_Get_Blocks(&n_updated_blocks); + R_Draw_Blocks(updated_blocks, n_updated_blocks); + tick_rate = game_speed_setting; + } else { + tick_rate--; } - R_Draw_Game_Over(0); - getchar(); /* putting this here just to stop prog from ending atm */ + } + R_Draw_Game_Over(0); } -void TC_Stop(void) -{ - M_Destroy_Blocks(); - TC_Close_Window(); +void TC_Stop(void) { + M_B_Destroy_Blocks(); + TC_Close_Window(); } diff --git a/src/rewrite/tc_settings.c b/src/rewrite/tc_settings.c index 6c50576..d7726d5 100644 --- a/src/rewrite/tc_settings.c +++ b/src/rewrite/tc_settings.c @@ -5,12 +5,6 @@ int target_fps_setting = 60; struct TC_Setting *tc_settings; -void TC_Set_Game_Speed(int speed) -{ - game_speed_setting = speed; -} +void TC_Set_Game_Speed(int speed) { game_speed_setting = speed; } -void TC_Set_Target_Fps(int fps) -{ - target_fps_setting = fps; -} +void TC_Set_Target_Fps(int fps) { target_fps_setting = fps; } diff --git a/src/rewrite/tc_settings.h b/src/rewrite/tc_settings.h index d522dab..90aa1c9 100644 --- a/src/rewrite/tc_settings.h +++ b/src/rewrite/tc_settings.h @@ -1,7 +1,8 @@ #ifndef TC_SETTINGS_H_ #define TC_SETTINGS_H_ -/* these settings could probably be more robust, probably doesn't matter until i need more*/ +/* these settings could probably be more robust, probably doesn't matter until i + * need more*/ /* Maybe have a load defaults, then optionally update? */ void TC_Set_Game_Speed(int speed); diff --git a/src/rewrite/tc_window.c b/src/rewrite/tc_window.c index b4f4b58..557169f 100644 --- a/src/rewrite/tc_window.c +++ b/src/rewrite/tc_window.c @@ -1,15 +1,12 @@ #include "tc_window.h" + #include "raylib.h" #include "sc_def.h" #include "tc_settings.h" -void TC_Create_Window(void) -{ - InitWindow(SC_WIDTH, SC_HEIGHT, "Tetris Clone"); - SetTargetFPS(target_fps_setting); +void TC_Create_Window(void) { + InitWindow(SC_WIDTH, SC_HEIGHT, "Tetris Clone"); + SetTargetFPS(target_fps_setting); } -int TC_Close_Window(void) -{ - return WindowShouldClose(); -} +int TC_Close_Window(void) { return WindowShouldClose(); }