2021-09-13 22:11:55 -07:00
|
|
|
(import-macros {: incf} :sample-macros)
|
|
|
|
|
2018-10-17 18:32:39 -07:00
|
|
|
(var counter 0)
|
|
|
|
(var time 0)
|
|
|
|
|
2022-03-10 12:29:30 -08:00
|
|
|
(love.graphics.setNewFont 30)
|
2022-05-30 05:30:36 -07:00
|
|
|
(local sheet (love.graphics.newImage "images/MRMOTEXT.png"))
|
2022-03-10 12:29:30 -08:00
|
|
|
|
2022-05-30 05:30:36 -07:00
|
|
|
(fn split-images [sheet height width]
|
|
|
|
(var images {})
|
|
|
|
(var count 0)
|
|
|
|
(for [y 0 (- (sheet:getHeight) height) height]
|
|
|
|
(for [x 0 (- (sheet:getWidth) width) width]
|
|
|
|
(tset images count (love.graphics.newQuad x y width height (sheet:getDimensions)))
|
|
|
|
(set count (+ count 1))
|
|
|
|
))
|
|
|
|
images)
|
|
|
|
|
|
|
|
(local sprites (split-images sheet 8 8))
|
|
|
|
(fn get-image [sprites row column]
|
|
|
|
(. sprites (+ (* 32 row) column)))
|
|
|
|
|
|
|
|
(local player (get-image sprites 13 1))
|
|
|
|
(var player-data {:x 100
|
|
|
|
:y 100})
|
|
|
|
|
|
|
|
(fn get-player-x []
|
|
|
|
(. player-data :x))
|
|
|
|
(fn get-player-y []
|
|
|
|
(. player-data :y))
|
2022-03-16 17:22:07 -07:00
|
|
|
|
2018-10-17 18:32:39 -07:00
|
|
|
{:draw (fn draw [message]
|
2022-03-10 12:29:30 -08:00
|
|
|
(local (w h _flags) (love.window.getMode))
|
2022-05-30 05:30:36 -07:00
|
|
|
(love.graphics.draw sheet player (get-player-x) (get-player-y) 0 2 2)
|
|
|
|
)
|
2018-10-17 18:32:39 -07:00
|
|
|
:update (fn update [dt set-mode]
|
2022-05-30 05:30:36 -07:00
|
|
|
(incf time dt))
|
2018-10-17 18:32:39 -07:00
|
|
|
:keypressed (fn keypressed [key set-mode]
|
2022-05-30 05:30:36 -07:00
|
|
|
(if (love.keyboard.isDown ".")
|
|
|
|
(tset player-data :y (- (. player-data :y) 8)))
|
|
|
|
(if (love.keyboard.isDown "e")
|
|
|
|
(tset player-data :y (+ (. player-data :y) 8)))
|
|
|
|
(if (love.keyboard.isDown "u")
|
|
|
|
(tset player-data :x (+ (. player-data :x) 8)))
|
|
|
|
(if (love.keyboard.isDown "o")
|
|
|
|
(tset player-data :x (- (. player-data :x) 8)))
|
|
|
|
)}
|