-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.c
42 lines (40 loc) · 1.57 KB
/
util.c
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
#include "game.h"
void WriteGameToBuffer(game_t *game, char *buffer){
// renders the board
char temp_buffer[ROWS][COLUMNS*3];
for(int row = 0; row < ROWS; row++){
for(int col = 0; col < COLUMNS; col++){
if(game->play_area[row][col] != EMPTY){
temp_buffer[row][2*col] = '[';
temp_buffer[row][2*col + 1] = ']';
}
else {
temp_buffer[row][2*col] = ' ';
temp_buffer[row][2*col + 1] = '.';
}
}
}
if (game->state == RUNNING_STATE){
//renders shadow piece
for(int col = 0; col < 4; col++){
for(int row = 0; row < 4; row++){
if(game->tetrominos[game->piece_index][game->tet_rotation][row][col] == FALLING_SQUARE){
temp_buffer[row + game->lowest_piece_row][2*(col + game->piece_col)] = '(';
temp_buffer[row + game->lowest_piece_row][2*(col + game->piece_col) + 1] = ')';
}
}
}
//renders the falling piece
for(int col = 0; col < 4; col++){
for(int row = 0; row < 4; row++){
if(game->tetrominos[game->piece_index][game->tet_rotation][row][col] == FALLING_SQUARE){
temp_buffer[row + game->piece_row][2*(col + game->piece_col)] = '[';
temp_buffer[row + game->piece_row][2*(col + game->piece_col) + 1] = ']';
}
}
}
}
for (int i = 0; i < ROWS*COLUMNS*3 ; i++) {
*(buffer + i) = temp_buffer[i/ROWS][i%(3*COLUMNS)];
}
}