|
@@ -137,10 +137,25 @@ local pieces = {
|
|
|
|
|
|
local board = {}
|
|
|
|
|
|
-local pieceType = 3
|
|
|
-local pieceRotation = 1
|
|
|
-local piece_x = 3
|
|
|
-local piece_y = 0
|
|
|
+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
|
|
@@ -151,58 +166,48 @@ function init_board()
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+function spawn_piece()
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
function draw_piece()
|
|
|
for y = 1, 4 do
|
|
|
for x = 1, 4 do
|
|
|
- local block = pieces[pieceType][pieceRotation][y][x]
|
|
|
+ local block = pieces[active_piece.type][active_piece.rotation][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
|
|
|
+ spr(
|
|
|
+ spriteIndexStart + block,
|
|
|
+ (active_piece.x + x - 1) * blockSize,
|
|
|
+ (active_piece.y + y - 1) * blockSize
|
|
|
)
|
|
|
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()
|
|
|
+ active_piece.type = active_piece.type + 1
|
|
|
+ if active_piece.type > 7 then active_piece.type = 1 end
|
|
|
end
|
|
|
function soft_drop()
|
|
|
- piece_y = piece_y + 1
|
|
|
+ active_piece.y = active_piece.y + 1
|
|
|
end
|
|
|
function try_move_right()
|
|
|
- piece_x = piece_x + 1
|
|
|
+ active_piece.x = active_piece.x + 1
|
|
|
end
|
|
|
function try_move_left()
|
|
|
- piece_x = piece_x - 1
|
|
|
+ active_piece.x = active_piece.x - 1
|
|
|
end
|
|
|
|
|
|
function handle_input()
|
|
|
is_move_pressed = false
|
|
|
- if btn(0) then
|
|
|
+ if btnp(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
|
|
|
+ t_move = rules.das
|
|
|
soft_drop()
|
|
|
end
|
|
|
end
|
|
@@ -210,9 +215,9 @@ function handle_input()
|
|
|
is_move_pressed = true
|
|
|
if t_move <= 0 then
|
|
|
if not is_das_triggered then
|
|
|
- t_move = factor_das
|
|
|
+ t_move = rules.das
|
|
|
else
|
|
|
- t_move = factor_keyrepeat
|
|
|
+ t_move = rules.keyrepeat
|
|
|
end
|
|
|
is_das_triggered = true
|
|
|
try_move_left()
|
|
@@ -222,24 +227,24 @@ function handle_input()
|
|
|
is_move_pressed = true
|
|
|
if t_move <= 0 then
|
|
|
if not is_das_triggered then
|
|
|
- t_move = factor_das
|
|
|
+ t_move = rules.das
|
|
|
else
|
|
|
- t_move = factor_keyrepeat
|
|
|
+ t_move = rules.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]
|
|
|
+ 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
|
|
|
- pieceRotation = pieceRotation + 1
|
|
|
- if pieceRotation > #pieces[pieceType] then
|
|
|
- pieceRotation = 1
|
|
|
+ active_piece.rotation = active_piece.rotation + 1
|
|
|
+ if active_piece.rotation > #pieces[active_piece.type] then
|
|
|
+ active_piece.rotation = 1
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -256,13 +261,24 @@ function TIC()
|
|
|
|
|
|
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
|
|
|
|
|
|
+-- <SPRITES>
|
|
|
+-- 001:bbbbbbbb9aaaaaab9aaaaaab9aaaaaab9aaaaaab9aaaaaab9aaaaaab89999999
|
|
|
+-- 002:8aaaaaaa8999999a8999999a8999999a8999999a8999999a8999999a88888888
|
|
|
+-- 003:4444444423333334233333342333333423333334233333342333333412222222
|
|
|
+-- 004:cccccccc2444444c2444444c2444444c2444444c2444444c2444444c12222222
|
|
|
+-- 005:55555555766666657666666576666665766666657666666576666665f7777777
|
|
|
+-- 006:ddddddddfeeeeeedfeeeeeedfeeeeeedfeeeeeedfeeeeeedfeeeeeedffffffff
|
|
|
+-- 007:3333333312222223122222231222222312222223122222231222222381111111
|
|
|
+-- 016:8bbbbbbb8abbbbba8aabbbaa8aaabaaa8aaa9aaa8aa999aa8a99999a88888888
|
|
|
+-- 017:f5555555f6555556f6655566f6665666f6667666f6677766f6777776ffffffff
|
|
|
+-- 018:0000000000044000004cc4000444cc4004444440004444000004400000000000
|
|
|
+-- 019:0aaaaaa0a000000aa000000aa000000aa000000aa000000aa000000a0aaaaaa0
|
|
|
+-- 020:0666666060000006600000066000000660000006600000066000000606666660
|
|
|
+-- </SPRITES>
|
|
|
+
|
|
|
-- <PALETTE>
|
|
|
--- 000:140c1c44243430346d4e4a4e854c30346524d04648757161597dced27d2c8595a16daa2cd2aa996dc2cadad45edeeed6
|
|
|
+-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
|
|
|
-- </PALETTE>
|
|
|
|