diff --git a/game/rules.fnl b/game/rules.fnl index 76fe437..2bf1afc 100644 --- a/game/rules.fnl +++ b/game/rules.fnl @@ -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 diff --git a/game/tilemap.fnl b/game/tilemap.fnl index c1385de..1ebe98e 100644 --- a/game/tilemap.fnl +++ b/game/tilemap.fnl @@ -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)))