M board.ha => board.ha +8 -2
@@ 28,14 28,14 @@ const color_map: [_](u8, u8, u8) = [
type board = struct {
cells: [BOARD_WIDTH * BOARD_HEIGHT]color,
+ offs_x: int,
+ offs_y: int,
active: [][TETROMINO_LEN]color,
active_i: int,
active_x: int,
active_y: int,
ghost_x: int,
ghost_y: int,
- offs_x: int,
- offs_y: int,
};
fn draw_board(state: *state, board: *board) (void | sdl2::error) = {
@@ 48,6 48,7 @@ fn draw_board(state: *state, board: *board) (void | sdl2::error) = {
continue;
};
let color = &color_map[cell];
+ sdl2::set_texture_alpha_mod(tex.tex, 255)?;
sdl2::set_texture_color_mod(tex.tex, color.0, color.1, color.2)?;
sdl2::render_copy(state.render, tex.tex, null, &sdl2::rect {
x = offs.0 + x * BOARD_SCALE * tex.width,
@@ 141,6 142,11 @@ fn update_ghost(state: *state) void = {
};
fn commit(state: *state) void = {
+ if (state.board.active_y < 0) {
+ state.state = gamestate::GAMEOVER;
+ return;
+ };
+
let board = &state.board.cells;
let active = &state.board.active[state.board.active_i];
const active_x = state.board.active_x;
M main.ha => main.ha +1 -0
@@ 16,6 16,7 @@ type gamestate = enum {
SPAWN,
FALL,
CLEAR,
+ GAMEOVER,
};
type state = struct {
M notes.txt => notes.txt +0 -1
@@ 4,7 4,6 @@
- try to accomodate rotation by moving pieces left/right
- piece swapping
- keyboard input
-- game over (+animation)
- victory (+animation)
- music
- sound effects
M update.ha => update.ha +7 -1
@@ 43,6 43,9 @@ fn update(state: *state) (void | sdl2::error) = {
case controller_button::A, controller_button::B,
controller_button::X, controller_button::Y =>
rotate(state);
+ case controller_button::DPAD_UP =>
+ state.board.active_y = state.board.ghost_y;
+ commit(state);
case controller_button::DPAD_DOWN =>
state.faster = true;
case => void;
@@ 64,6 67,9 @@ fn update(state: *state) (void | sdl2::error) = {
do_fall(state, now);
case gamestate::CLEAR =>
do_clear(state, now);
+ case gamestate::GAMEOVER =>
+ // TODO: Game over screen
+ state.run = false;
};
};
};
@@ 130,7 136,7 @@ fn do_clear(state: *state, now: u32) void = {
fn schedule_tick(state: *state, now: u32) void = {
if (state.faster) {
- state.next = now + 100;
+ state.next = now + state.speed / 4;
} else {
state.next = now + state.speed;
};