-- title: blockbattle -- author: pixelbath -- desc: a falling blocks game totally not inspired by anything previous -- script: lua t=0 local pieces = { { { {0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, }, { {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, }, }, { { {0, 0, 0, 0}, {0, 4, 4, 0}, {0, 4, 4, 0}, {0, 0, 0, 0}, }, }, { { {0, 0, 0, 0}, {2, 2, 2, 0}, {0, 0, 2, 0}, {0, 0, 0, 0}, }, { {0, 2, 0, 0}, {0, 2, 0, 0}, {2, 2, 0, 0}, {0, 0, 0, 0}, }, { {2, 0, 0, 0}, {2, 2, 2, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, }, { {0, 2, 2, 0}, {0, 2, 0, 0}, {0, 2, 0, 0}, {0, 0, 0, 0}, }, }, { { {0, 0, 0, 0}, {3, 3, 3, 0}, {3, 0, 0, 0}, {0, 0, 0, 0}, }, { {0, 3, 0, 0}, {0, 3, 0, 0}, {0, 3, 3, 0}, {0, 0, 0, 0}, }, { {0, 0, 3, 0}, {3, 3, 3, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, }, { {3, 3, 0, 0}, {0, 3, 0, 0}, {0, 3, 0, 0}, {0, 0, 0, 0}, }, }, { { {0, 0, 0, 0}, {5, 5, 5, 0}, {0, 5, 0, 0}, {0, 0, 0, 0}, }, { {0, 5, 0, 0}, {0, 5, 5, 0}, {0, 5, 0, 0}, {0, 0, 0, 0}, }, { {0, 5, 0, 0}, {5, 5, 5, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, }, { {0, 5, 0, 0}, {5, 5, 0, 0}, {0, 5, 0, 0}, {0, 0, 0, 0}, }, }, { { {0, 0, 0, 0}, {0, 6, 6, 0}, {6, 6, 0, 0}, {0, 0, 0, 0}, }, { {6, 0, 0, 0}, {6, 6, 0, 0}, {0, 6, 0, 0}, {0, 0, 0, 0}, }, }, { { {0, 0, 0, 0}, {7, 7, 0, 0}, {0, 7, 7, 0}, {0, 0, 0, 0}, }, { {0, 7, 0, 0}, {7, 7, 0, 0}, {7, 0, 0, 0}, {0, 0, 0, 0}, }, }, } local board = {} local pieceType = 3 local pieceRotation = 1 local piece_x = 3 local piece_y = 0 function init_board() for y = 1, 20 do board[y] = {} for x = 1, 10 do board[y][x] = 0 end end end function draw_piece() for y = 1, 4 do for x = 1, 4 do local block = pieces[pieceType][pieceRotation][y][x] if block ~= 0 then local blockSize = 8 local blockDrawSize = blockSize - 1 rect( (piece_x + x - 1) * blockSize, (piece_y + y - 1) * blockSize, blockDrawSize, blockDrawSize, block ) end end end end local factor_are = 4 -- piece spawn delay local factor_das = 20 local factor_keyrepeat = 5 local t_move = 0 local is_move_pressed = false local is_das_triggered = false function hard_drop() end function soft_drop() piece_y = piece_y + 1 end function try_move_right() piece_x = piece_x + 1 end function try_move_left() piece_x = piece_x - 1 end function handle_input() is_move_pressed = false if btn(0) then hard_drop() end if btn(1) then is_move_pressed = true if t_move <= 0 then if not is_das_triggered then t_move = factor_das else t_move = factor_keyrepeat end is_das_triggered = true soft_drop() end end if btn(2) then is_move_pressed = true if t_move <= 0 then if not is_das_triggered then t_move = factor_das else t_move = factor_keyrepeat end is_das_triggered = true try_move_left() end end if btn(3) then is_move_pressed = true if t_move <= 0 then if not is_das_triggered then t_move = factor_das else t_move = factor_keyrepeat end is_das_triggered = true try_move_right() end end if btnp(4) then pieceRotation = pieceRotation - 1 if pieceRotation < 1 then pieceRotation = #pieces[pieceType] end end if btnp(5) then pieceRotation = pieceRotation + 1 if pieceRotation > #pieces[pieceType] then pieceRotation = 1 end end if is_move_pressed then t_move = t_move - 1 else t_move = -1 is_das_triggered = false end end function TIC() handle_input() cls(0) draw_piece() print("is_move_pressed: " .. tostring(is_move_pressed), 0, 0) print("is_das_triggered: " .. tostring(is_das_triggered), 0, 7) print("t_move: " .. tostring(t_move), 0, 14) end -- -- 000:140c1c44243430346d4e4a4e854c30346524d04648757161597dced27d2c8595a16daa2cd2aa996dc2cadad45edeeed6 --