@@ 1,7 1,6 @@
- ghost blocks
- instant place
- fix thumbsticks
-- fix L rotations
- scorekeeping/display
- clear completed rows (+animation)
- collision detection on rotations
@@ 105,7 105,8 @@ fn do_spawn(state: *state) void = {
fn do_fall(state: *state) void = {
let height = 0;
activesize(state, null, &height);
- if (canmove(state, 0, 1)) {
+ const active = &state.board.active[state.board.active_i];
+ if (canmove(state, active, 0, 1)) {
state.board.active_y += 1;
} else {
commit(state);
@@ 113,29 114,6 @@ fn do_fall(state: *state) void = {
};
};
-fn canmove(state: *state, dx: int, dy: int) bool = {
- let board = &state.board.cells;
- let active = &state.board.active[state.board.active_i];
- const active_x = state.board.active_x;
- const active_y = state.board.active_y;
- for (let y = 0; y < TETROMINO_HEIGHT; y += 1)
- for (let x = 0; x < TETROMINO_WIDTH; x += 1) {
- const active_ix = y * TETROMINO_WIDTH + x;
- if (active[active_ix] == 0) {
- continue;
- };
- if (y + active_y < 0) {
- continue;
- };
- const x = x + dx, y = y + dy;
- const board_ix = (y + active_y) * BOARD_WIDTH + (x + active_x);
- if (board_ix: size >= len(board) || board[board_ix] != 0) {
- return false;
- };
- };
- return true;
-};
-
fn commit(state: *state) void = {
let board = &state.board.cells;
let active = &state.board.active[state.board.active_i];
@@ 203,3 181,29 @@ fn activesize(
case null => void;
};
};
+
+fn canmove(
+ state: *state,
+ active: *[TETROMINO_LEN]color,
+ dx: int, dy: int,
+) bool = {
+ let board = &state.board.cells;
+ const active_x = state.board.active_x;
+ const active_y = state.board.active_y;
+ for (let y = 0; y < TETROMINO_HEIGHT; y += 1)
+ for (let x = 0; x < TETROMINO_WIDTH; x += 1) {
+ const active_ix = y * TETROMINO_WIDTH + x;
+ if (active[active_ix] == 0) {
+ continue;
+ };
+ if (y + active_y < 0) {
+ continue;
+ };
+ const x = x + dx, y = y + dy;
+ const board_ix = (y + active_y) * BOARD_WIDTH + (x + active_x);
+ if (board_ix: size >= len(board) || board[board_ix] != 0) {
+ return false;
+ };
+ };
+ return true;
+};