Compare commits
No commits in common. "8d4745832d2793cc2137a5150430c27c38cb7c7c" and "e0d19d5d61df7b899daaf61299db86e38ffc84d3" have entirely different histories.
8d4745832d
...
e0d19d5d61
7 changed files with 58 additions and 162 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
BIN
two_player_cleaning_game/.DS_Store
vendored
Normal file
BIN
two_player_cleaning_game/.DS_Store
vendored
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 436 B After Width: | Height: | Size: 355 B |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 574 B |
|
|
@ -2,50 +2,20 @@
|
||||||
(local levels (. (require "levels.fnl") :levels))
|
(local levels (. (require "levels.fnl") :levels))
|
||||||
(local bump (require "bump"))
|
(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
|
;; global vars
|
||||||
(var player-art nil) ; 25x50 pixels each player is 25x25
|
(var player-art nil) ; 25x50 pixels each player is 25x25
|
||||||
(var dust-sprite nil) ; 35x35 pixels
|
(var dust-sprite nil) ; 35x35 pixels
|
||||||
(var ui-bg nil)
|
|
||||||
(var walls-sprite nil)
|
(var walls-sprite nil)
|
||||||
(var walls-batch nil)
|
(var walls-batch nil)
|
||||||
(var wall-quads 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 camera {:x 0 :y 0})
|
||||||
(local debug false)
|
(local debug true)
|
||||||
(local collider-debug-boxes [])
|
(local collider-debug-boxes [])
|
||||||
(local bump-world (bump.newWorld 25))
|
(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)**
|
; 16:9 (Modern Widescreen - Recommended)**
|
||||||
; - **640x360** ← Best middle ground
|
; - **640x360** ← Best middle ground
|
||||||
; - 800x450
|
; - 800x450
|
||||||
|
|
@ -58,20 +28,18 @@
|
||||||
; - 1024x768
|
; - 1024x768
|
||||||
|
|
||||||
(fn love.load []
|
(fn love.load []
|
||||||
(love.window.setMode screen.screen-w screen.screen-h)
|
(love.window.setMode screen-width screen-height)
|
||||||
(tset screen :canvas (love.graphics.newCanvas screen.canvas-w screen.canvas-h))
|
|
||||||
(bump-world:add player player.x player.y player.w player.h)
|
(bump-world:add player player.x player.y player.w player.h)
|
||||||
|
|
||||||
;; load world images
|
;; load world images
|
||||||
(set walls-sprite (love.graphics.newImage "assets/walls.png"))
|
(set walls-sprite (love.graphics.newImage "assets/walls.png"))
|
||||||
(set walls-batch (love.graphics.newSpriteBatch walls-sprite 2500))
|
(set walls-batch (love.graphics.newSpriteBatch walls-sprite 2500))
|
||||||
(set ui-bg (love.graphics.newImage "assets/ui.png"))
|
|
||||||
|
|
||||||
;; load wall quads
|
;; load wall quads
|
||||||
(set wall-quads [])
|
(set wall-quads [])
|
||||||
(let [(w h) (: walls-sprite :getDimensions)]
|
(let [(h w) (: walls-sprite :getDimensions)]
|
||||||
(for [i 0 19 1]
|
(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
|
;; load tiles
|
||||||
(each [_ row (pairs (. levels :level01 :tiles))]
|
(each [_ row (pairs (. levels :level01 :tiles))]
|
||||||
(each [_ tile (pairs row)]
|
(each [_ tile (pairs row)]
|
||||||
|
|
@ -89,26 +57,11 @@
|
||||||
{:x (+ x collider.x) :y (+ y collider.y) :width collider.width :height collider.height})
|
{:x (+ x collider.x) :y (+ y collider.y) :width collider.width :height collider.height})
|
||||||
))))
|
))))
|
||||||
|
|
||||||
(set player-art
|
(set player-art {
|
||||||
(let [
|
:player-sprite (love.graphics.newImage "assets/player.png")
|
||||||
player-sprite (love.graphics.newImage "assets/player.png")
|
:player1-quad (love.graphics.newQuad 0 0 25 25 50 25)
|
||||||
(w h) (player-sprite:getDimensions)]
|
:player2-quad (love.graphics.newQuad 25 0 25 25 50 25)
|
||||||
{
|
})
|
||||||
: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 dust-sprite (love.graphics.newImage "assets/dust_001.png"))
|
(set dust-sprite (love.graphics.newImage "assets/dust_001.png"))
|
||||||
; (print (fennel.view game-state))
|
; (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))))
|
(print (if ok (fennel.view val) val))))
|
||||||
|
|
||||||
;; drawing
|
;; 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 []
|
(fn draw-world []
|
||||||
(reset-color)
|
(love.graphics.setColor 1 1 1) ; reset color to white (no tinting)
|
||||||
(love.graphics.draw walls-batch)
|
(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]
|
(fn love.update [dt]
|
||||||
; move / rotate player
|
(let [deltas { :dx 0 :dy 0}]
|
||||||
(let [
|
(if (love.keyboard.isDown :right)
|
||||||
d (love.keyboard.isDown :d)
|
(tset deltas :dx (* player.speed dt))
|
||||||
a (love.keyboard.isDown :a)
|
(if (love.keyboard.isDown :left)
|
||||||
e (love.keyboard.isDown :e)
|
(tset deltas :dx (* (* -1 player.speed) dt))))
|
||||||
q (love.keyboard.isDown :q)]
|
(if (love.keyboard.isDown :down)
|
||||||
|
(tset deltas :dy (* player.speed dt))
|
||||||
(case [d a e q]
|
(if (love.keyboard.isDown :up)
|
||||||
[true false false false] (tset player :rot (+ player.rot (* dt 2)))
|
(tset deltas :dy (* (* -1 player.speed) dt))))
|
||||||
[false true false false] (tset player :rot (- player.rot (* dt 2)))
|
(if (or (not= 0 deltas.dx) (not= 0 deltas.dy))
|
||||||
[false false true false] (tset player :rot (- player.rot (* dt 2)))
|
(let [(x y) (bump-world:move player (+ player.x deltas.dx) (+ player.y deltas.dy))]
|
||||||
[false false false true] (tset player :rot (+ player.rot (* dt 2)))
|
; (print (fennel.view { :msg "Moving player" :x x :y y}))
|
||||||
)
|
|
||||||
|
|
||||||
(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 :x x)
|
||||||
(tset player :y y))))
|
(tset player :y y))))
|
||||||
|
|
||||||
;; Update camera to follow player (keep player centered on screen)
|
;; Update camera to follow player (keep player centered on screen)
|
||||||
(tset camera :x (- player.x (/ screen.canvas-w 2)))
|
(tset camera :x (- player.x (/ screen-width 2)))
|
||||||
(tset camera :y (- player.y (/ screen.canvas-h 2)))
|
(tset camera :y (- player.y (/ screen-height 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)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
(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)
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
(fn love.draw []
|
(fn love.draw []
|
||||||
(love.graphics.setCanvas screen.canvas)
|
|
||||||
(love.graphics.clear)
|
(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))
|
(love.graphics.translate (* -1 camera.x) (* -1 camera.y))
|
||||||
(draw-world)
|
(draw-world)
|
||||||
(draw-player)
|
;; draw player
|
||||||
(love.graphics.pop)
|
(love.graphics.draw
|
||||||
(draw-ui)
|
(. player-art :player-sprite)
|
||||||
(love.graphics.setCanvas)
|
(. player-art :player1-quad)
|
||||||
(reset-color)
|
player.x player.y)
|
||||||
(love.graphics.draw screen.canvas 0 0 0 screen.scale screen.scale))
|
;; 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))
|
; (love.graphics.print "Hello from Fennel!\nPress any key to quit" 10 10))
|
||||||
|
|
||||||
(fn love.keypressed [key] nil )
|
(fn love.keypressed [key] nil )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue