123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- -- 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
- -- <PALETTE>
- -- 000:140c1c44243430346d4e4a4e854c30346524d04648757161597dced27d2c8595a16daa2cd2aa996dc2cadad45edeeed6
- -- </PALETTE>
|