2021-03-07 16:55:50 +00:00
|
|
|
(local lume (require :lib.lume))
|
|
|
|
(local map (require :game.tilemap))
|
|
|
|
(local tileset (require :game.tiles))
|
2021-02-07 21:56:19 +00:00
|
|
|
(local state (require :game.state))
|
|
|
|
|
2021-03-07 16:55:50 +00:00
|
|
|
(local Rules {})
|
2021-02-07 21:56:19 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
(local tetrominoes
|
|
|
|
{:O [["##"
|
|
|
|
"##"]]
|
2021-03-07 16:55:50 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
:L [["###"
|
|
|
|
"# "]
|
2021-03-07 16:55:50 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
["# "
|
|
|
|
"# "
|
|
|
|
"##"]
|
2021-03-07 16:55:50 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
[" #"
|
|
|
|
"###"]
|
2021-03-07 16:55:50 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
["##"
|
|
|
|
" #"
|
|
|
|
" #"]]
|
2021-03-07 16:55:50 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
:J [["###"
|
|
|
|
" #"]
|
2021-03-07 16:55:50 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
["##"
|
|
|
|
"# "
|
|
|
|
"# "]
|
2021-03-07 16:55:50 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
["# "
|
|
|
|
"###"]
|
2021-03-28 19:23:08 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
[" #"
|
|
|
|
" #"
|
|
|
|
"##"]]
|
2021-03-28 19:23:08 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
:I [["####"]
|
2021-03-28 19:23:08 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
["#"
|
|
|
|
"#"
|
|
|
|
"#"
|
|
|
|
"#"]]
|
|
|
|
|
|
|
|
:S [[" ##"
|
|
|
|
"## "]
|
|
|
|
|
|
|
|
["# "
|
|
|
|
"##"
|
|
|
|
" #"]]
|
|
|
|
|
|
|
|
:Z [["## "
|
|
|
|
" ##"]
|
|
|
|
|
|
|
|
[" #"
|
|
|
|
"##"
|
|
|
|
"# "]]
|
|
|
|
|
|
|
|
:T [["###"
|
|
|
|
" # "]
|
|
|
|
|
|
|
|
["# "
|
|
|
|
"##"
|
|
|
|
"# "]
|
|
|
|
|
|
|
|
[" # "
|
|
|
|
"###"]
|
|
|
|
|
|
|
|
[" #"
|
|
|
|
"##"
|
|
|
|
" #"]]})
|
|
|
|
|
|
|
|
(fn Rules.choose-random-tetromino []
|
|
|
|
(let [possible-values (icollect [k (pairs state.tetrominoes)] k)
|
|
|
|
ivalue (love.math.random (length possible-values))]
|
|
|
|
(. possible-values ivalue)))
|
|
|
|
|
|
|
|
(fn Rules.reset-game []
|
|
|
|
(set state.tetrominoes tetrominoes)
|
|
|
|
(set state.well (map.new-tilemap 12 21))
|
|
|
|
(for [y 0 19]
|
|
|
|
(map.set-itile-at 0 y state.well "X")
|
|
|
|
(map.set-itile-at 11 y state.well "X"))
|
|
|
|
(for [x 0 11]
|
|
|
|
(map.set-itile-at x 20 state.well "X"))
|
|
|
|
(set state.next-piece (Rules.choose-random-tetromino)))
|
|
|
|
|
|
|
|
(fn Rules.tetromino [k irotation]
|
|
|
|
(let [rotations (or (. state.tetrominoes k) [["##" "##"]])
|
|
|
|
irotation (+ (% (- irotation 1) (length rotations)) 1)]
|
|
|
|
(. rotations irotation)))
|
2021-03-28 19:23:08 +00:00
|
|
|
|
2021-03-07 16:55:50 +00:00
|
|
|
Rules
|
2021-02-07 21:56:19 +00:00
|
|
|
|