Skip to content

Commit

Permalink
gravity bugfix, update display_board signature
Browse files Browse the repository at this point in the history
* Fix bug introduced in last commit when I tried to explicitly cast a uint
    to an int variable; it prevented the gravity check from ever activating,
    so pieces wouldn't ever actually be added to be board.
* Changed display_board to take TetrisBoard instead of TetrisBoard*
  • Loading branch information
0xjmux committed Mar 23, 2024
1 parent 7242afd commit 31afd27
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/driver_tetris.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
waddch((w),' '|A_REVERSE|COLOR_PAIR(x))
#define ADD_EMPTY(w) waddch((w), ' '); waddch((w), ' ')

void display_board(WINDOW *w, TetrisBoard *b);
void display_board(WINDOW *w, TetrisBoard b);
void update_score(WINDOW *w, TetrisGame *tg);

// Debug functions
Expand Down
11 changes: 6 additions & 5 deletions src/driver_tetris.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int main(void) {
tg_tick(tg, move);

// display board
display_board(g_win, &tg->active_board);
display_board(g_win, tg->active_board);
update_score(s_win, tg);

switch(getch()) {
Expand Down Expand Up @@ -161,7 +161,7 @@ int main(void) {
/**
* Draw board array presented by tetris game
*/
void display_board(WINDOW *w, TetrisBoard *tb) {
void display_board(WINDOW *w, TetrisBoard tb) {

static struct timeval last_update;

Expand All @@ -179,8 +179,8 @@ void display_board(WINDOW *w, TetrisBoard *tb) {
wmove(w, 1 + i, 1);
for (int j = 0; j < TETRIS_COLS; j++) {

if (tb->board[i][j] >= 0) {
ADD_BLOCK(w, tb->board[i][j]);
if (tb.board[i][j] >= 0) {
ADD_BLOCK(w, tb.board[i][j]);
}
else {
ADD_EMPTY(w);
Expand All @@ -191,10 +191,11 @@ void display_board(WINDOW *w, TetrisBoard *tb) {

last_update = curr_time_usec;
wrefresh(w);

#ifdef DEBUG_T
// fprintf(gamelog, "display_board()\n");
// print_board_state(*tb, gamelog);
fflush(gamelog);
// fflush(gamelog);
#endif

#ifdef DEBUG_T_WIN
Expand Down
2 changes: 1 addition & 1 deletion tetris/tetris.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ bool check_do_piece_gravity(TetrisGame *tg) {
// check if it's time for piece to be moved down
int32_t time_diff_usec = get_elapsed_us(tg->last_gravity_tick_usec, curr_time_usec);

if (time_diff_usec > (int32_t)tg->gravity_tick_rate_usec) {
if (time_diff_usec > tg->gravity_tick_rate_usec) {

// if can move down
if(check_valid_move(tg, T_DOWN)) {
Expand Down

0 comments on commit 31afd27

Please sign in to comment.