From 370d5ebc7e72dabe0bace0cc8f38e0cc9a6ac482 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sun, 24 Apr 2022 21:47:13 -0400 Subject: [PATCH] fix rotation and placement --- game/rules.fnl | 11 ++++++++++- game/tilemap.fnl | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) 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)))