diff options
author | turnipgod | 2025-03-01 18:46:48 -0500 |
---|---|---|
committer | turnipgod | 2025-03-01 18:50:18 -0500 |
commit | 5a8765cddc3fc328f3cb22606688dd1ccb2f2f22 (patch) | |
tree | 914dee0d9cda7ce1a00e34bccbaf7f7fe51807d9 | |
parent | ee90c1c219403778425a66fe5105646fca237b54 (diff) |
basic matrix rendering
-rw-r--r-- | src/main.c | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c index d61885b..661233b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,14 +1,70 @@ #include "raylib.h" +#define SCREEN_WIDTH 800 +#define SCREEN_HEIGHT 600 + +#define MATRIX_WIDTH 10 +#define MATRIX_HEIGHT 40 + +#define BLOCK_SIZE 25 + +struct Color matrix[MATRIX_WIDTH][MATRIX_HEIGHT]; + +void render_matrix(void); + +void render_matrix(void) +{ + /* top left corner */ + int matrix_start_x = + (SCREEN_WIDTH/2 - (MATRIX_WIDTH * BLOCK_SIZE)) / 2; + int matrix_start_y = + (SCREEN_HEIGHT - (3 * MATRIX_HEIGHT / 2 * BLOCK_SIZE)) / 2; + + /* draw matrix background */ + DrawRectangle( + matrix_start_x - 1 + ,matrix_start_y + (MATRIX_HEIGHT/2 * BLOCK_SIZE) - 1 + ,MATRIX_WIDTH * BLOCK_SIZE + 2 + ,MATRIX_HEIGHT/2 * BLOCK_SIZE + 2 + ,GRAY + ); + + /* draw blocks from matrix */ + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 10; x++) { + DrawRectangle( + (x * BLOCK_SIZE) + matrix_start_x + 1 + ,(y * BLOCK_SIZE) + matrix_start_y + 1 + ,BLOCK_SIZE - 2 + ,BLOCK_SIZE - 2 + ,matrix[x][y] + ); + } + } +} + int main(void) { - InitWindow(800, 450, "raylib [core] example - basic window"); + InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "~turnipGod's Tetris"); + + // set all blocks to white + for (int y = 0; y < 40; y++) { + for (int x = 0; x < 10; x++) { + matrix[x][y] = WHITE; + } + } + + // set playarea blocks to purple + for (int y = 20; y < 40; y++) { + for (int x = 0; x < 10; x++) { + matrix[x][y] = PURPLE; + } + } - while (!WindowShouldClose()) - { + while (!WindowShouldClose()) { BeginDrawing(); - ClearBackground(RAYWHITE); - DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + ClearBackground(WHITE); + render_matrix(); EndDrawing(); } |