#include "libepc.h" #include "tetris.h" #include #define HIGH_WATER 5 /* ------------------------------------------------------------ */ /* Implements all the dynamics of the Tetris object. */ /* Returns TRUE if Tetris object placed at or above high water. */ /* ------------------------------------------------------------ */ BOOL HandleObject(KEYS *keys) { static DWORD32 left_right_timer = 0 ; static DWORD32 vertical_timer = 0 ; static BOOL space_down = FALSE ; static char color = 0x07 ; static int count = 0 ; static int rot = 0 ; static int row = 0 ; static int col = 40 ; int old_row, old_col, old_rot ; DWORD32 now = Now_Plus(0) ; old_row = row ; old_col = col ; old_rot = rot ; if (now >= vertical_timer) { row++ ; vertical_timer += 200 ; /* 0.20 secs */ } else if (now >= left_right_timer) { if (keys->left_down) { col -= 2 ; /* 2 columns per move */ if (col < 0) col = 0 ; } if (keys->right_down) { col += 2 ; /* 2 columns per move */ if (col > 76) col = 76 ; } left_right_timer += 40 ; /* 0.04 secs */ } else return FALSE ; /* Rotate once on each depression of space bar */ if (!space_down && keys->space_down) rot = (rot + 1) % 4 ; space_down = keys->space_down ; /* Erase the object, then look for collision at new location */ PaintObject(old_row, old_col, old_rot, FALSE, 0x00) ; if (Blocked(row, col, rot)) { /* Blocked: Repaint at old position */ PaintObject(old_row, old_col, old_rot, TRUE, color) ; if (row != old_row) { if (row < HIGH_WATER) return TRUE ; Tone(1000) ; SetCursorPosition(0,0) ; PutUnsigned(++count, 10, 4) ; row = 0 ; col = 4 + 2 * (random() % 37) ; rot = random() % 4 ; if (++color == 16) color = 1 ; } else { col = old_col ; rot = old_rot ; } } /* Not blocked: Repaint at new position */ else PaintObject(row, col, rot, TRUE, color) ; return FALSE ; }