From 9a79400080100fac25a6a4786bbe1c2d42a80551 Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Mon, 6 Apr 2026 17:04:11 +0200 Subject: [PATCH] render dust fog of war Press any key to quit" 10 10)) --- .../assets/dust_001.aseprite | Bin 0 -> 764 bytes two_player_cleaning_game/assets/dust_001.png | Bin 0 -> 510 bytes two_player_cleaning_game/main.fnl | 66 ++++++++++++++++-- two_player_cleaning_game/map-util.fnl | 2 +- 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 two_player_cleaning_game/assets/dust_001.aseprite create mode 100644 two_player_cleaning_game/assets/dust_001.png 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 0000000000000000000000000000000000000000..6a7b47a255859f0dc2a9364a0664b9719c50db9a GIT binary patch literal 764 zcmeyv#K7=iDI!W}0jNHsdN=;|Cv$A&Jk)V2@(*MAp*?G(R)(=8-Az0>Z>Rm~&9DBx?fg|&Syo;1 z{_7pH`E1-`IuRQZ4mPoZ7>i@2V=7s?0Lq8FhJI1M=5tu_wL!&hUA@k*VZ&rN500001b5ch_0Itp) z=>Px$xJg7oR9J=0n6Hw;Fc8K!clRC`91ekE=ANKa85x1)0g&K$04$=ivXdw1BOof6 zsi{XJ>8b6cX_6-C_TZaAK%31kn?K(YfDaOzGq~VsYkQXE#h`C1j4O~WnBI1`KNz21 zFK1(%LBO#BWs_C*0RMK}<_ z({=z;%Ia-E#>~6}2wZDM1^P`^{{l0}Ox?)AOQo!OA24K(BAeE8X1PeBgN9@h2T?cD zd;$xewo_nSK(-7zVbt%obA)Q4*NucMFIco4P(dLG=({Nf1hgrc0v2U(zH))#u2oHz z#G66^PVCrCdYMtZ$5$pVi&b<95d*Gkw?Fhw`wk|{3+6jY%6dly>Se|UXwJgR zx|>2erI<1&Oej$3`+BhkCOgRTf(Z^?JwrV$u6WVjgllWLNT6;csPG{!uC7s%|Jt#Y zq3+ydw-BMVv#Eq2zY=jld6f`z$TZEaYm|@E9~Ar)=~XP=iU0rr07*qoM6N<$g4J@| Ar2qf` literal 0 HcmV?d00001 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)"