summary refs log tree commit diff
path: root/src/main.c
blob: 1761efe4918b42cb1e950069d26d02bdf20089ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "raylib.h"

#define SCREEN_WIDTH  800
#define SCREEN_HEIGHT 600

#define MATRIX_WIDTH  10
#define MATRIX_HEIGHT 40

#define BLOCK_SIZE 25

#include "tetromino.h"

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(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()) {
        BeginDrawing();
        ClearBackground(WHITE);
        render_matrix();
        EndDrawing();
    }

    CloseWindow();

    return 0;
}