int main(void) { setup_pins(); setup_comparator(); setup_timer0(); ledsetup(); uint8_t message_buffer[12] = {0}; Controller *controller = (Controller*)message_buffer; machine_init(); Animation anim; clear_animation(&anim); bool prev_machine_toggle = true; delay_ms(1000); while(1) { // Wait until we have a valid message while(!getMessage(message_buffer)) {} // Interpret the input process_input(controller, &anim); if((prev_machine_toggle && !machine_toggle) || machine_toggle) { show_animation(&anim); } clear_animation(&anim); prev_machine_toggle = machine_toggle; // Wait for the 2nd paired request to pass _delay_us(2000); } }
static int clear_even_rows(void) { int abs_row; /* absolute row number */ int count = 0; int i = GAME_BOARD_HEIGHT; int cleared_rows[4]; /* XXX: max 4 rows can be cleared at a time? */ /* use animation style 3 */ static void (*clear_animation)(int *, int) = draw_cleared_rows_animation_3; for (abs_row = GAME_BOARD_HEIGHT; i > top_row; abs_row--) { int j; int found = 1; for (j = 1; j < GAME_BOARD_WIDTH + 1; j++) { if (!board[i][j]) { found = 0; break; } } if (found) cleared_rows[count++] = abs_row - 1; /* save the absolute row */ else { i--; continue; /* move on to check the next row */ } memset(board[i], 0, sizeof (*board)); /* clear the current row */ /* move down the all the rows above the cleared row */ memmove((void *)board[top_row + 1], (void *)board[top_row], (i - top_row) * sizeof (*board)); top_row++; assert(top_row <= GAME_BOARD_HEIGHT); } /* now animate (blink) the cleared rows */ if (count) clear_animation(cleared_rows, count); return count; }