2021-04-11 03:39:42 +00:00
|
|
|
(local util (require :lib.util))
|
2021-02-07 21:56:19 +00:00
|
|
|
(local state (require :game.state))
|
2021-03-07 16:55:50 +00:00
|
|
|
(local map (require :game.tilemap))
|
|
|
|
(local rules (require :game.rules))
|
2022-04-24 23:39:15 +00:00
|
|
|
(local tiles (require :game.tiles))
|
|
|
|
(local dim (require :game.dim))
|
2021-04-11 03:39:42 +00:00
|
|
|
(local {: draw : update} (util.require :game.entity))
|
2021-02-07 21:56:19 +00:00
|
|
|
|
2022-04-24 23:39:15 +00:00
|
|
|
(fn game-update [dt])
|
2021-02-07 21:56:19 +00:00
|
|
|
|
2021-03-30 23:24:52 +00:00
|
|
|
(fn exception-update [dt]
|
|
|
|
(when (love.keyboard.isDown :f2)
|
|
|
|
(set state.update-exception nil)))
|
|
|
|
|
|
|
|
(fn update [dt]
|
|
|
|
(if state.update-exception
|
|
|
|
(exception-update dt)
|
|
|
|
(xpcall #(game-update dt) (fn [msg]
|
|
|
|
(set state.update-exception (.. msg "\n" (debug.traceback)))))))
|
|
|
|
|
|
|
|
(fn game-draw []
|
2022-04-24 23:39:15 +00:00
|
|
|
(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))
|
2021-02-07 21:56:19 +00:00
|
|
|
|
2021-03-30 23:24:52 +00:00
|
|
|
(fn exception-draw []
|
|
|
|
(love.graphics.setColor 1 0 0 1)
|
|
|
|
(love.graphics.setNewFont 14)
|
|
|
|
(love.graphics.printf (.. "Press F2 when resolved\n" state.update-exception) 20 20 (- (love.graphics.getWidth) 40)))
|
|
|
|
|
|
|
|
(fn draw []
|
|
|
|
(if state.update-exception
|
|
|
|
(exception-draw)
|
|
|
|
(game-draw)))
|
|
|
|
|
2021-02-07 21:56:19 +00:00
|
|
|
{: update : draw}
|
|
|
|
|