- load mrmo sprite sheet
- find player character
- move player character with dvorak key press
This commit is contained in:
Anish Lakhwara 2022-05-30 22:30:36 +10:00
parent befb1dd65b
commit a210317ab4
2 changed files with 35 additions and 15 deletions

BIN
images/MRMOTEXT.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View file

@ -4,24 +4,44 @@
(var time 0)
(love.graphics.setNewFont 30)
(local sheet (love.graphics.newImage "images/MRMOTEXT.png"))
(local (major minor revision) (love.getVersion))
(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))
{:draw (fn draw [message]
(local (w h _flags) (love.window.getMode))
(love.graphics.printf
(: "Love Version: %s.%s.%s"
:format major minor revision) 0 10 w :center)
(love.graphics.printf
(: "This window should close in %0.1f seconds"
:format (math.max 0 (- 3 time)))
0 (- (/ h 2) 15) w :center))
(love.graphics.draw sheet player (get-player-x) (get-player-y) 0 2 2)
)
:update (fn update [dt set-mode]
(if (< counter 65535)
(set counter (+ counter 1))
(set counter 0))
(incf time dt)
(when (> time 3)
(love.event.quit)))
(incf time dt))
:keypressed (fn keypressed [key set-mode]
(love.event.quit))}
(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)))
)}