load map image into map data
This commit is contained in:
parent
0597b8ca56
commit
50ef6d575f
3 changed files with 41 additions and 0 deletions
36
two_player_cleaning_game/map-util.fnl
Normal file
36
two_player_cleaning_game/map-util.fnl
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
(local name "travis")
|
||||
|
||||
(local levels [
|
||||
{:image-path "assets/level_002.png" :walls []}
|
||||
])
|
||||
|
||||
; "20 x 20 array with the outter edge set to 1 (walls) and the inner edge set to 0 (floor)"
|
||||
(local empty-level
|
||||
(let [level []]
|
||||
(for [y 0 19 1] (table.insert level [])) ; empty rows
|
||||
(each [y row (ipairs level)]
|
||||
(for [x 0 19 1] (table.insert row 0)))
|
||||
level
|
||||
)
|
||||
)
|
||||
|
||||
(lambda load-walls [level]
|
||||
(let [image-data (love.image.newImageData (. level :image-path))]
|
||||
(each [y row (ipairs (. level :walls))]
|
||||
(each [x wall (ipairs row)]
|
||||
(let [(r g b) (image-data:getPixel (- x 1) (- y 1))]
|
||||
; (print (.. x "," y " -> " r "," g "," b))
|
||||
(tset row x (if (= (.. r g b) "111") 0 1)))))))
|
||||
|
||||
(fn load []
|
||||
"load levels"
|
||||
(each [_ level (pairs levels)]
|
||||
(tset level :walls empty-level)
|
||||
(load-walls level))
|
||||
; (print (fennel.view levels))
|
||||
)
|
||||
|
||||
{
|
||||
:load load
|
||||
:levels levels
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue