From 914731713a79011d37b3e9fd8350812644af3b9b Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sun, 24 Apr 2022 19:56:53 -0400 Subject: [PATCH] current piece --- game/mode.fnl | 9 +++++++-- game/rules.fnl | 21 ++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/game/mode.fnl b/game/mode.fnl index 8b9d81d..6841292 100644 --- a/game/mode.fnl +++ b/game/mode.fnl @@ -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) diff --git a/game/rules.fnl b/game/rules.fnl index 04a8bc0..1057074 100644 --- a/game/rules.fnl +++ b/game/rules.fnl @@ -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