fix rotation and placement
This commit is contained in:
parent
c8a42fd631
commit
370d5ebc7e
|
@ -140,7 +140,16 @@
|
|||
|
||||
(fn Rules.rotate [di]
|
||||
(when state.current
|
||||
(set state.current.irotation (+ state.current.irotation di))))
|
||||
(var settled false)
|
||||
(let [irotation (+ state.current.irotation di)
|
||||
tetromino (Rules.tetromino state.current.piece irotation)]
|
||||
(each [_ dx (ipairs [0 1 -1]) :until settled]
|
||||
(let [x (+ state.current.x dx)
|
||||
y state.current.y]
|
||||
(when (not (Rules.collides? tetromino x y))
|
||||
(set settled true)
|
||||
(set state.current.x x)
|
||||
(set state.current.irotation irotation)))))))
|
||||
|
||||
(set Rules.commands
|
||||
{:move Rules.try-move-piece
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
(fn set-itile-at [x y tilemap itile]
|
||||
(let [row (or (. tilemap (+ y 1)) "")
|
||||
row (.. row (string.rep " " (math.max 0 (- x (length row)))))
|
||||
pre (row:sub 1 (- x 1))
|
||||
post (row:sub (+ x 1))
|
||||
pre (row:sub 1 x)
|
||||
post (row:sub (+ x 2))
|
||||
row (.. pre itile post)]
|
||||
(tset tilemap (+ y 1) row)))
|
||||
|
||||
|
|
Loading…
Reference in a new issue