-- 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 active_piece = {
type = 3,
rotation = 1,
x = 3, y = 0,
}
local rules = {
keyrepeat = 5,
das = 20,
are = 4,
}
local spriteIndexStart = 256
local blockSize = 8
local t_move = 0
local is_move_pressed = false
local is_das_triggered = false
function init_board()
for y = 1, 20 do
board[y] = {}
for x = 1, 10 do
board[y][x] = 0
end
end
end
function spawn_piece()
end
function draw_piece()
for y = 1, 4 do
for x = 1, 4 do
local block = pieces[active_piece.type][active_piece.rotation][y][x]
if block ~= 0 then
spr(
spriteIndexStart + block,
(active_piece.x + x - 1) * blockSize,
(active_piece.y + y - 1) * blockSize
)
end
end
end
end
function hard_drop()
active_piece.type = active_piece.type + 1
if active_piece.type > 7 then active_piece.type = 1 end
end
function soft_drop()
active_piece.y = active_piece.y + 1
end
function try_move_right()
active_piece.x = active_piece.x + 1
end
function try_move_left()
active_piece.x = active_piece.x - 1
end
function handle_input()
is_move_pressed = false
if btnp(0) then
hard_drop()
end
if btn(1) then
is_move_pressed = true
if t_move <= 0 then
t_move = rules.das
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 = rules.das
else
t_move = rules.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 = rules.das
else
t_move = rules.keyrepeat
end
is_das_triggered = true
try_move_right()
end
end
if btnp(4) then
active_piece.rotation = active_piece.rotation - 1
if active_piece.rotation < 1 then
active_piece.rotation = #pieces[active_piece.type]
end
end
if btnp(5) then
active_piece.rotation = active_piece.rotation + 1
if active_piece.rotation > #pieces[active_piece.type] then
active_piece.rotation = 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()
end
--
-- 001:bbbbbbbb9aaaaaab9aaaaaab9aaaaaab9aaaaaab9aaaaaab9aaaaaab89999999
-- 002:8aaaaaaa8999999a8999999a8999999a8999999a8999999a8999999a88888888
-- 003:4444444423333334233333342333333423333334233333342333333412222222
-- 004:cccccccc2444444c2444444c2444444c2444444c2444444c2444444c12222222
-- 005:55555555766666657666666576666665766666657666666576666665f7777777
-- 006:ddddddddfeeeeeedfeeeeeedfeeeeeedfeeeeeedfeeeeeedfeeeeeedffffffff
-- 007:3333333312222223122222231222222312222223122222231222222381111111
-- 016:8bbbbbbb8abbbbba8aabbbaa8aaabaaa8aaa9aaa8aa999aa8a99999a88888888
-- 017:f5555555f6555556f6655566f6665666f6667666f6677766f6777776ffffffff
-- 018:0000000000044000004cc4000444cc4004444440004444000004400000000000
-- 019:0aaaaaa0a000000aa000000aa000000aa000000aa000000aa000000a0aaaaaa0
-- 020:0666666060000006600000066000000660000006600000066000000606666660
--
--
-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
--