edtris/game/rules.fnl

97 lines
1.5 KiB
Plaintext
Raw Normal View History

(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))
(local Rules {})
2021-02-07 21:56:19 +00:00
2022-04-24 23:39:15 +00:00
(local tetrominoes
{:O [["##"
"##"]]
2022-04-24 23:39:15 +00:00
:L [["###"
"# "]
2022-04-24 23:39:15 +00:00
["# "
"# "
"##"]
2022-04-24 23:39:15 +00:00
[" #"
"###"]
2022-04-24 23:39:15 +00:00
["##"
" #"
" #"]]
2022-04-24 23:39:15 +00:00
:J [["###"
" #"]
2022-04-24 23:39:15 +00:00
["##"
"# "
"# "]
2022-04-24 23:39:15 +00:00
["# "
"###"]
2022-04-24 23:39:15 +00:00
[" #"
" #"
"##"]]
2022-04-24 23:39:15 +00:00
:I [["####"]
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)))
Rules
2021-02-07 21:56:19 +00:00