~sircmpwn/tetrominoes

4e8c92bb66bdb6612b626b9412c44de841fa65f1 — Drew DeVault 2 years ago cc5cb0d
Check collisions on rotation attempts
2 files changed, 11 insertions(+), 3 deletions(-)

M notes.txt
M update.ha
M notes.txt => notes.txt +1 -1
@@ 3,7 3,7 @@
- fix thumbsticks
- scorekeeping/display
- clear completed rows (+animation)
- collision detection on rotations
- try to accomodate rotation by moving pieces left/right
- piece swapping
- keyboard input
- game over (+animation)

M update.ha => update.ha +10 -2
@@ 149,8 149,13 @@ fn move_right(state: *state) void = {
fn rotate(state: *state) void = {
	// TODO: Make sure this rotation is allowed
	const board = &state.board;
	board.active_i += 1;
	board.active_i = board.active_i % len(board.active): int;
	const next = board.active_i + 1;
	const next = next % len(board.active): int;
	const active = &state.board.active[next];
	if (!canmove(state, active, 0, 0)) {
		return;
	};
	board.active_i = next;
};

fn activesize(


@@ 199,6 204,9 @@ fn canmove(
		if (y + active_y < 0) {
			continue;
		};
		if (x + active_x >= BOARD_WIDTH) {
			return false;
		};
		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) {