use sdl2;
fn draw(state: *state) (void | sdl2::error) = {
sdl2::set_render_draw_color(state.render, 0, 0, 0, 255)?;
sdl2::render_clear(state.render)?;
sdl2::render_copy(state.render, state.scene.tex, null, &sdl2::rect{
x = 0,
y = 0,
w = 640,
h = 480,
})?;
draw_board(state, &state.board)?;
switch (state.state) {
case gamestate::CLEAR =>
draw_clear(state)?;
case => void; // No special drawing required
};
sdl2::render_present(state.render);
};
fn draw_clear(state: *state) (void | sdl2::error) = {
if (state.clearframe < 0) {
return;
};
for (let i = 0z; i < len(state.clearlines); i += 1) {
draw_clearline(state, state.clearlines[i])?;
};
};
fn draw_clearline(state: *state, y: int) (void | sdl2::error) = {
const inrect = &sdl2::rect {
x = state.clearframe * 4,
y = 0,
w = 4,
h = 4,
};
const tex = state.clear;
const board = &state.board;
const offs = (board.offs_x * SCENE_SCALE, board.offs_y * SCENE_SCALE);
for (let x = 0; x < BOARD_WIDTH; x += 1) {
const outrect = &sdl2::rect {
x = offs.0 + x * BOARD_SCALE * TETROMINO_WIDTH,
y = offs.1 + y * BOARD_SCALE * TETROMINO_HEIGHT,
w = TETROMINO_WIDTH * BOARD_SCALE,
h = TETROMINO_HEIGHT * BOARD_SCALE,
};
sdl2::render_copy(state.render, tex.tex, inrect, outrect)?;
};
};