diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..21a713d Binary files /dev/null and b/.DS_Store differ diff --git a/two_player_cleaning_game/.DS_Store b/two_player_cleaning_game/.DS_Store new file mode 100644 index 0000000..cb0c768 Binary files /dev/null and b/two_player_cleaning_game/.DS_Store differ diff --git a/two_player_cleaning_game/assets/player.aseprite b/two_player_cleaning_game/assets/player.aseprite index 97cc154..2d2c619 100644 Binary files a/two_player_cleaning_game/assets/player.aseprite and b/two_player_cleaning_game/assets/player.aseprite differ diff --git a/two_player_cleaning_game/assets/player.png b/two_player_cleaning_game/assets/player.png index ca62b72..973060b 100644 Binary files a/two_player_cleaning_game/assets/player.png and b/two_player_cleaning_game/assets/player.png differ diff --git a/two_player_cleaning_game/assets/ui.aseprite b/two_player_cleaning_game/assets/ui.aseprite deleted file mode 100644 index 99fa7e8..0000000 Binary files a/two_player_cleaning_game/assets/ui.aseprite and /dev/null differ diff --git a/two_player_cleaning_game/assets/ui.png b/two_player_cleaning_game/assets/ui.png deleted file mode 100644 index 0abe1e2..0000000 Binary files a/two_player_cleaning_game/assets/ui.png and /dev/null differ diff --git a/two_player_cleaning_game/main.fnl b/two_player_cleaning_game/main.fnl index 007bb31..586c65f 100644 --- a/two_player_cleaning_game/main.fnl +++ b/two_player_cleaning_game/main.fnl @@ -2,50 +2,20 @@ (local levels (. (require "levels.fnl") :levels)) (local bump (require "bump")) -;; colors -(lambda color [full-r full-g full-b] - (let [(r g b) (love.math.colorFromBytes full-r full-g full-b)] - [r g b] -)) -(local color-pallet { - :cream (color 255 238 204) - :dark-purple (color 70 66 94) - :dark-pink (color 255 105 115) - :dark-blue (color 21 120 140) - :light-blue (color 0 185 190) - :light-pink (color 255 176 163) - :black [0 0 0] - :black-half-tone [0 0 0 0.25] -}) - -(fn reset-color [] - "reset color to white (no tinting)" - (love.graphics.setColor 1 1 1)) - -(lambda set-color [color] - "set color to the given color from the color pallet" - (love.graphics.setColor (unpack (. color-pallet color)))) - ;; global vars (var player-art nil) ; 25x50 pixels each player is 25x25 (var dust-sprite nil) ; 35x35 pixels -(var ui-bg nil) (var walls-sprite nil) (var walls-batch nil) (var wall-quads nil) -(local screen - (let [scale 2 canvas-w 800 canvas-h 450] - { :screen-w (* canvas-w scale) - :screen-h (* canvas-h scale) - :canvas-w canvas-w - :canvas-h canvas-h - :scale scale - :canvas nil})) (local camera {:x 0 :y 0}) -(local debug false) +(local debug true) (local collider-debug-boxes []) (local bump-world (bump.newWorld 25)) -(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 :rot 0 }) +(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 }) +;; Screen Size +(local screen-width 800) +(local screen-height 600) ; 16:9 (Modern Widescreen - Recommended)** ; - **640x360** ← Best middle ground ; - 800x450 @@ -58,20 +28,18 @@ ; - 1024x768 (fn love.load [] - (love.window.setMode screen.screen-w screen.screen-h) - (tset screen :canvas (love.graphics.newCanvas screen.canvas-w screen.canvas-h)) + (love.window.setMode screen-width screen-height) (bump-world:add player player.x player.y player.w player.h) ;; load world images (set walls-sprite (love.graphics.newImage "assets/walls.png")) (set walls-batch (love.graphics.newSpriteBatch walls-sprite 2500)) - (set ui-bg (love.graphics.newImage "assets/ui.png")) ;; load wall quads (set wall-quads []) - (let [(w h) (: walls-sprite :getDimensions)] + (let [(h w) (: walls-sprite :getDimensions)] (for [i 0 19 1] - (table.insert wall-quads (love.graphics.newQuad (* i 25) 0 25 25 w h)))) + (table.insert wall-quads (love.graphics.newQuad (* i 25) 0 25 25 h w)))) ;; load tiles (each [_ row (pairs (. levels :level01 :tiles))] (each [_ tile (pairs row)] @@ -89,26 +57,11 @@ {:x (+ x collider.x) :y (+ y collider.y) :width collider.width :height collider.height}) )))) - (set player-art - (let [ - player-sprite (love.graphics.newImage "assets/player.png") - (w h) (player-sprite:getDimensions)] - { - :player-sprite player-sprite - :player1 { - :quads { - :n (love.graphics.newQuad 0 0 25 25 w h) - :s (love.graphics.newQuad 25 0 25 25 w h) - :ne (love.graphics.newQuad 50 0 25 25 w h) - :e (love.graphics.newQuad 75 0 25 25 w h) - :se (love.graphics.newQuad 100 0 25 25 w h) - :sw (love.graphics.newQuad 125 0 25 25 w h) - :w (love.graphics.newQuad 150 0 25 25 w h) - :nw (love.graphics.newQuad 175 0 25 25 w h) - } - } - } - )) + (set player-art { + :player-sprite (love.graphics.newImage "assets/player.png") + :player1-quad (love.graphics.newQuad 0 0 25 25 50 25) + :player2-quad (love.graphics.newQuad 25 0 25 25 50 25) + }) (set dust-sprite (love.graphics.newImage "assets/dust_001.png")) ; (print (fennel.view game-state)) @@ -122,120 +75,63 @@ 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)] + [r g b] +)) + +(local off-white (color 237 230 200)) +(local black [0 0 0]) +(local black-half-tone [0 0 0 0.25]) (fn draw-world [] - (reset-color) + (love.graphics.setColor 1 1 1) ; reset color to white (no tinting) (love.graphics.draw walls-batch) - ;; draw collider debug boxes - (when debug - (set-color :black) - (each [_ collider (pairs collider-debug-boxes)] - (love.graphics.rectangle "line" collider.x collider.y collider.width collider.height)))) - -(fn love.update [dt] - ; move / rotate player - (let [ - d (love.keyboard.isDown :d) - a (love.keyboard.isDown :a) - e (love.keyboard.isDown :e) - q (love.keyboard.isDown :q)] - - (case [d a e q] - [true false false false] (tset player :rot (+ player.rot (* dt 2))) - [false true false false] (tset player :rot (- player.rot (* dt 2))) - [false false true false] (tset player :rot (- player.rot (* dt 2))) - [false false false true] (tset player :rot (+ player.rot (* dt 2))) - ) - - (if (or d a e q) - (let [ - dir-fn (if (or d a) #(+ $1 $2) #(- $1 $2)) - new-x (dir-fn player.x (* player.speed dt (math.cos player.rot))) - new-y (dir-fn player.y (* player.speed dt (math.sin player.rot))) - (x y) (bump-world:move player new-x new-y)] - (tset player :x x) - (tset player :y y)))) - - ;; Update camera to follow player (keep player centered on screen) - (tset camera :x (- player.x (/ screen.canvas-w 2))) - (tset camera :y (- player.y (/ screen.canvas-h 2))) - ) - -(fn draw-ui [] - (love.graphics.push) - (love.graphics.translate 0 400) - (let [font (love.graphics.newFont 10) font-small (love.graphics.newFont 6)] - (set-color :cream) - (love.graphics.rectangle "fill" 0 0 screen.canvas-w 100) - (reset-color) - (love.graphics.draw ui-bg 0 0) - (set-color :dark-purple) - (love.graphics.setFont font) - (love.graphics.print "Battery:" 20 6) - (set-color :light-blue) - (love.graphics.rectangle "fill" 72 12 (* 152 (/ player.battery 100)) 4) - (love.graphics.setFont font-small) - (set-color :dark-purple) - (love.graphics.print "100%" 229 2) - (set-color :light-pink) - (love.graphics.print "125%" 267 2) - (love.graphics.print "125%" 306 2) - (love.graphics.print "150%" 345 2) - (love.graphics.print "200%" 382 2) - (set-color :dark-purple) - (love.graphics.line 0 0 screen.canvas-w 0) - ) - (love.graphics.pop) ) +(fn love.update [dt] + (let [deltas { :dx 0 :dy 0}] + (if (love.keyboard.isDown :right) + (tset deltas :dx (* player.speed dt)) + (if (love.keyboard.isDown :left) + (tset deltas :dx (* (* -1 player.speed) dt)))) + (if (love.keyboard.isDown :down) + (tset deltas :dy (* player.speed dt)) + (if (love.keyboard.isDown :up) + (tset deltas :dy (* (* -1 player.speed) dt)))) + (if (or (not= 0 deltas.dx) (not= 0 deltas.dy)) + (let [(x y) (bump-world:move player (+ player.x deltas.dx) (+ player.y deltas.dy))] + ; (print (fennel.view { :msg "Moving player" :x x :y y})) + (tset player :x x) + (tset player :y y)))) -(lambda angle-to-direction [angle] - "Convert angle (radians) to compass direction keyword" - (local tau (* 2 math.pi)) - ; Normalize angle to 0-2π range - (local normalized (% (+ angle tau) tau)) - ; Offset by 22.5° (π/8) so section boundaries align with directions - (local offset (+ normalized (/ math.pi 8))) - ; Find which 45° section (π/4) it falls into - (local section (math.floor (/ offset (/ math.pi 4)))) - ; Map to compass directions - (local directions [:e :se :s :sw :w :nw :n :ne]) - (. directions (+ (% section 8) 1))) - -(fn draw-player [] - "draw player sprite and hitbox" - (reset-color) - (love.graphics.draw - player-art.player-sprite - (. player-art.player1.quads (angle-to-direction player.rot)) - player.x player.y) - ;; draw player hitbox and direction line - (when debug - (set-color :black) - (love.graphics.rectangle "line" player.x player.y player.w player.h) - (love.graphics.push) - (let [ox (+ player.x (/ 25 2)) oy (+ player.y (/ 25 2))] - (love.graphics.translate ox oy) - (love.graphics.rotate player.rot) - (love.graphics.line 0 0 35 0)) - (love.graphics.pop) - )) + ;; Update camera to follow player (keep player centered on screen) + (tset camera :x (- player.x (/ screen-width 2))) + (tset camera :y (- player.y (/ screen-height 2))) + ) (fn love.draw [] - (love.graphics.setCanvas screen.canvas) (love.graphics.clear) - (set-color :cream) - (love.graphics.rectangle "fill" 0 0 screen.canvas-w screen.canvas-h) - (love.graphics.push) ; stores the default coordinate system (love.graphics.translate (* -1 camera.x) (* -1 camera.y)) (draw-world) - (draw-player) - (love.graphics.pop) - (draw-ui) - (love.graphics.setCanvas) - (reset-color) - (love.graphics.draw screen.canvas 0 0 0 screen.scale screen.scale)) + ;; draw player + (love.graphics.draw + (. player-art :player-sprite) + (. player-art :player1-quad) + player.x player.y) + ;; draw player hitbox + (when debug + (love.graphics.setColor (unpack black)) ; reset color to white (no tinting) + (love.graphics.rectangle "line" player.x player.y player.w player.h)) + + + ;; draw collider debug boxes + (when debug + (love.graphics.setColor (unpack black)) ; reset color to white (no tinting) + (each [_ collider (pairs collider-debug-boxes)] + (love.graphics.rectangle "line" collider.x collider.y collider.width collider.height))) +) ; (love.graphics.print "Hello from Fennel!\nPress any key to quit" 10 10)) (fn love.keypressed [key] nil )