diff --git a/two_player_cleaning_game/assets/dust_001.aseprite b/two_player_cleaning_game/assets/dust_001.aseprite new file mode 100644 index 0000000..6a7b47a Binary files /dev/null and b/two_player_cleaning_game/assets/dust_001.aseprite differ diff --git a/two_player_cleaning_game/assets/dust_001.png b/two_player_cleaning_game/assets/dust_001.png new file mode 100644 index 0000000..65bbbf8 Binary files /dev/null and b/two_player_cleaning_game/assets/dust_001.png differ diff --git a/two_player_cleaning_game/main.fnl b/two_player_cleaning_game/main.fnl index e7ce215..fc30edd 100644 --- a/two_player_cleaning_game/main.fnl +++ b/two_player_cleaning_game/main.fnl @@ -1,17 +1,40 @@ (local map-util (require "map-util.fnl")) (var player-sprite nil) ; 20x20 pixels +(var dust-sprite nil) ; 35x35 pixels (local game-state { :player-pos [0 0] + :level 1 + :world [] }) +(fn start-level [] + ;; set player position to the start of the current level + (tset game-state :player-pos + (. map-util :levels (. game-state :level) :player-start)) + ;; set fresh world + (let [world []] + (each [y walls (ipairs (. map-util :levels (. game-state :level) :walls))] + (table.insert world []) + (each [x wall (ipairs walls)] + (table.insert (. world y) {:revealed false :type + (if (= wall 1) :wall :floor) + }) + ) + ) + (tset game-state :world world) + ) +) + (fn love.load [] (map-util:load) (love.window.setMode 600 640) - (set player-sprite (love.graphics.newImage "assets/player_001.png")) + (set dust-sprite (love.graphics.newImage "assets/dust_001.png")) + (start-level) + (print (fennel.view game-state)) ;; start a thread listening on stdin (: (love.thread.newThread "require('love.event') while 1 do love.event.push('stdin', io.read('*line')) end") :start)) @@ -22,6 +45,7 @@ while 1 do love.event.push('stdin', io.read('*line')) end") :start)) (print (if ok (fennel.view val) val)))) + ;; drawing (lambda color [full-r full-g full-b] (let [(r g b) (love.math.colorFromBytes full-r full-g full-b)] @@ -30,23 +54,57 @@ while 1 do love.event.push('stdin', io.read('*line')) end") :start)) (local off-white (color 237 230 200)) (local black [0 0 0]) +(local black-half-tone [0 0 0 0.25]) (fn draw-game-outline [] (love.graphics.setColor (unpack black)) (love.graphics.rectangle "line" 50 50 500 500)) +(fn draw-world [] + (love.graphics.setColor (unpack black)) + ; (love.graphics.rectangle "fill" 50 50 500 500)) + (each [y cells (ipairs (. game-state :world))] + (each [x cell (ipairs cells)] + (case [(. cell :revealed) (. cell :type)] + [false _] (do + (love.graphics.setColor 1 1 1) ; reset color to white (no tinting) + (love.graphics.draw dust-sprite (+ 45 (* 25 (- x 1))) (+ 45 (* 25 (- y 1))))) + + [true :wall] (love.graphics.rectangle "fill" (+ 50 (* 25 (- x 1))) (+ 50 (* 25 (- y 1))) 25 25) + ) + ) + ) +) + + +; (print (fennel.view game-state)) (fn draw-player [] (love.graphics.setColor 1 1 1) ; reset color to white (no tinting) - (love.graphics.draw player-sprite 50 50 0 1.25 1.25)) + (let [[player-x player-y] (. game-state :player-pos)] + (love.graphics.draw player-sprite + (* 25 player-x) + (* 25 player-y) + 0 1.25 1.25))) + +(fn draw-ghost-grid [] + (love.graphics.setColor (unpack black-half-tone)) + (for [y 0 19 1] + (for [x 0 19 1] + (love.graphics.rectangle "line" + (+ 50 (* x 25)) + (+ 50 (* y 25)) + 25 25)))) (fn love.draw [] ;; clear the screen and set bg to off white (love.graphics.clear) (love.graphics.setColor (unpack off-white)) (love.graphics.rectangle "fill" 0 0 600 640) - - (draw-player) (draw-game-outline) + (draw-ghost-grid) + + (draw-world) + (draw-player) ) ; (love.graphics.print "Hello from Fennel!\nPress any key to quit" 10 10)) diff --git a/two_player_cleaning_game/map-util.fnl b/two_player_cleaning_game/map-util.fnl index 2c5aaf0..0ff9d4b 100644 --- a/two_player_cleaning_game/map-util.fnl +++ b/two_player_cleaning_game/map-util.fnl @@ -1,7 +1,7 @@ (local name "travis") (local levels [ - {:image-path "assets/level_002.png" :walls []} + {:image-path "assets/level_002.png" :player-start [10 19] :walls []} ]) ; "20 x 20 array with the outter edge set to 1 (walls) and the inner edge set to 0 (floor)"