current piece

This commit is contained in:
Jeremy Penner 2022-04-24 19:56:53 -04:00
parent 60a853fc7c
commit 914731713a
2 changed files with 23 additions and 7 deletions

View file

@ -19,8 +19,13 @@
(set state.update-exception (.. msg "\n" (debug.traceback)))))))
(fn game-draw []
(map.draw-tilemap (* dim.tilesize 5) 0 state.well tiles.tetristile)
(map.draw-tilemap (/ dim.tilesize 2) dim.tilesize (rules.tetromino state.next-piece 1) tiles.tetristile))
(let [xnext (/ dim.tilesize 2)
xwell (* dim.tilesize 5)
current (rules.current-tetromino)]
(map.draw-tilemap xwell 0 state.well tiles.tetristile)
(map.draw-tilemap xnext dim.tilesize (rules.tetromino state.next-piece 1) tiles.tetristile)
(when current
(map.draw-tilemap (+ xwell (* state.current.x dim.tilesize)) (* state.current.y dim.tilesize) current tiles.tetristile))))
(fn exception-draw []
(love.graphics.setColor 1 0 0 1)

View file

@ -77,6 +77,11 @@
ivalue (love.math.random (length possible-values))]
(. possible-values ivalue)))
(fn Rules.tetromino [k irotation]
(let [rotations (or (. state.tetrominoes k) [["##" "##"]])
irotation (+ (% (- irotation 1) (length rotations)) 1)]
(. rotations irotation)))
(fn Rules.reset-game []
(set state.tetrominoes tetrominoes)
(set state.well (map.new-tilemap 12 21))
@ -85,12 +90,18 @@
(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)))
(set state.drop-ms 750)
(Rules.play-next-piece))
(fn Rules.tetromino [k irotation]
(let [rotations (or (. state.tetrominoes k) [["##" "##"]])
irotation (+ (% (- irotation 1) (length rotations)) 1)]
(. rotations irotation)))
(fn Rules.play-next-piece []
(let [piece (or state.next-piece (Rules.choose-random-tetromino))
x (/ (- (length (. state.well 1)) 2) 2)]
(set state.current {: piece : x :y 0 :irotation 1})
(set state.next-piece (Rules.choose-random-tetromino))))
(fn Rules.current-tetromino []
(when state.current
(Rules.tetromino state.current.piece state.current.irotation)))
Rules