123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- -- 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
- -- <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:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
- -- </PALETTE>
|