(local lume (require :lib.lume)) (local map (require :game.tilemap)) (local tileset (require :game.tiles)) (local state (require :game.state)) (local Rules {}) (local tetrominoes {:O [["##" "##"]] :L [["###" "# "] ["# " "# " "##"] [" #" "###"] ["##" " #" " #"]] :J [["###" " #"] ["##" "# " "# "] ["# " "###"] [" #" " #" "##"]] :I [["####"] ["#" "#" "#" "#"]] :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