summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c55
1 files changed, 21 insertions, 34 deletions
diff --git a/src/main.c b/src/main.c
index 66a222c..0b65f7d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,42 +42,34 @@ int piece_queue[2][TETROMINO_COUNT] = {
int current_bag = 0;
int current_piece_index = 0;
-void render_matrix(void);
-void make_bag(int *bag);
+void draw_block(int x, int y, int width, int height, struct Color color)
+{
+ DrawRectangle(x, -y + SCREEN_HEIGHT - height, width, height, color);
+}
void render_matrix(void)
{
- /* top left matrix 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;
-
- /* top left queue corner */
- int queue_start_x =
- (SCREEN_WIDTH/2 + BLOCK_SIZE);
- int queue_start_y =
- (SCREEN_HEIGHT - (3 * MATRIX_HEIGHT / 2 * BLOCK_SIZE)) / 2;
-
+ int matrix_origin_x = (SCREEN_WIDTH/2 - (MATRIX_WIDTH * BLOCK_SIZE))/2;
+ int matrix_origin_y = (SCREEN_HEIGHT - MATRIX_HEIGHT/2 * BLOCK_SIZE)/2;
/* draw matrix background */
- DrawRectangle(
- matrix_start_x - 1
- ,matrix_start_y + (MATRIX_HEIGHT/2 * BLOCK_SIZE) - 1
+ draw_block(
+ matrix_origin_x - 1
+ ,matrix_origin_y - 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
+ /* draw matrix */
+ for (int i = 0; i < MATRIX_WIDTH; i++) {
+ for (int j = 0; j < MATRIX_HEIGHT; j++) {
+ draw_block(
+ matrix_origin_x + i * BLOCK_SIZE + 1
+ ,matrix_origin_y + j * BLOCK_SIZE + 1
,BLOCK_SIZE - 2
,BLOCK_SIZE - 2
- ,matrix[x][y]
+ ,matrix[i][j]
);
}
}
@@ -85,10 +77,10 @@ void render_matrix(void)
/* draw current piece */
for (int i = 0; i < tetrominos[current_piece.type].size; i++) {
for (int j = 0; j < tetrominos[current_piece.type].size; j++) {
- if (tetrominos[current_piece.type].directions[current_piece.rotation][i][j]) {
- DrawRectangle(
- matrix_start_x + ((current_piece.pos_x + j-2) * BLOCK_SIZE) + 1
- ,matrix_start_y + ((current_piece.pos_y + i-2) * BLOCK_SIZE) + 1
+ if (tetrominos[current_piece.type].directions[current_piece.rotation][j][i] == 1) {
+ draw_block(
+ (matrix_origin_x + ((current_piece.pos_x + i - 1) * BLOCK_SIZE)) + 1
+ ,(matrix_origin_y + ((current_piece.pos_y - j + 1) * BLOCK_SIZE)) + 1
,BLOCK_SIZE - 2
,BLOCK_SIZE - 2
,tetrominos[current_piece.type].color
@@ -96,11 +88,6 @@ void render_matrix(void)
}
}
}
-
- // draw queue
- // STUB
- (void)queue_start_x;
- (void)queue_start_y;
}
void shuffle_bag(int *bag)
@@ -125,7 +112,7 @@ void generation_phase(void)
// set current piece
current_piece.type = piece_queue[current_bag][current_piece_index++];
current_piece.rotation = NORTH;
- current_piece.pos_x = 5;
+ current_piece.pos_x = 4;
current_piece.pos_y = 20;
}