melee-roguelite/mode-intro.fnl

71 lines
2.1 KiB
Plaintext
Raw Normal View History

(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)
(local sheet (love.graphics.newImage "images/MRMOTEXT.png"))
2022-03-10 12:29:30 -08:00
(fn split-images [sheet height width]
(var images [])
(for [y 0 (- (sheet:getHeight) height) height]
(for [x 0 (- (sheet:getWidth) width) width]
(table.insert images (love.graphics.newQuad x y width height (sheet:getDimensions)))
))
images)
(local sprites (split-images sheet 8 8))
(fn get-image [sprites row column]
(. sprites (+ (* 32 row) (+ column 1))))
(var player-data {:x 100
:y 100
:rotation 0
:image (get-image sprites 13 1)})
(fn get-player-x []
(. player-data :x))
(fn get-player-y []
(. player-data :y))
(fn get-player-rotation []
(. player-data :rotation))
(fn move-player [x1 y1]
(tset player-data :x (+ (. player-data :x) x1))
(tset player-data :y (+ (. player-data :y) y1)))
(fn rotate-player [rx ry]
(tset player-data :rotation (math.atan2 rx ry)))
(fn handle-input [joystick]
(local x (joystick.obj:getAxis 1))
(local y (joystick.obj:getAxis 2))
(local rx (joystick.obj:getAxis 4))
(local ry (joystick.obj:getAxis 5))
(move-player x y)
(rotate-player rx ry))
(fn draw-player []
(love.graphics.setColor 0.12 0.78 0.55)
(love.graphics.draw sheet (. player-data :image) (get-player-x) (get-player-y) (get-player-rotation) 2 2 4 4))
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))
(draw-player)
)
:update (fn update [dt joystick set-mode]
(handle-input joystick)
(incf time dt))
2018-10-17 18:32:39 -07:00
:keypressed (fn keypressed [key set-mode]
(let [step 16]
(if (love.keyboard.isDown ".")
(tset player-data :y (- (. player-data :y) step)))
(if (love.keyboard.isDown "e")
(tset player-data :y (+ (. player-data :y) step)))
(if (love.keyboard.isDown "u")
(tset player-data :x (+ (. player-data :x) step)))
(if (love.keyboard.isDown "o")
(tset player-data :x (- (. player-data :x) step)))
))}