Compare commits
No commits in common. "31fb931c4ae71c4a463cbe189ac9a00619393cd7" and "eadc1392efb62d40a73fde58da3149ce18e17a29" have entirely different histories.
31fb931c4a
...
eadc1392ef
12 changed files with 14 additions and 245 deletions
|
|
@ -2,12 +2,6 @@
|
|||
|
||||
A two-player cooperative cleaning game built with [Fennel](https://fennel-lang.org/) and [Löve 2D](https://www.love2d.org/).
|
||||
|
||||
The Löve2d Fennel setup is based on https://git.sr.ht/~benthor/absolutely-minimal-love2d-fennel/tree/master/item/README.md
|
||||
|
||||
Color pallet is ["curiosities", Created by sukinapan](https://lospec.com/palette-list/curiosities).
|
||||
|
||||
And though this is a git repo I use [Jujutsu](https://docs.jj-vcs.dev/latest/) for version control.
|
||||
|
||||
## Setup
|
||||
|
||||
1. Install LÖVE 2D following the [Getting Started guide](https://love2d.org/wiki/Getting_Started)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,3,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2147483651,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2147483651,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
(var pool nil)
|
||||
|
||||
(love.graphics.setDefaultFilter :nearest :nearest)
|
||||
(local screen
|
||||
(let [scale 2 canvas-w 800 canvas-h 450]
|
||||
{ :screen-w (* canvas-w scale)
|
||||
|
|
@ -78,6 +77,7 @@
|
|||
|
||||
(fn love.load []
|
||||
(love.window.setMode screen.screen-w screen.screen-h)
|
||||
; (tset screen :canvas (love.graphics.newCanvas screen.canvas-w screen.canvas-h))
|
||||
(set pool (level.load screen))
|
||||
(pool:flush)
|
||||
(pool:emit :load)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
:light-blue (color 0 185 190)
|
||||
:light-pink (color 255 176 163)
|
||||
:black [0 0 0]
|
||||
:white [255 255 255]
|
||||
:black-half-tone [0 0 0 0.25]
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,6 @@
|
|||
(lambda bump-filter [item other]
|
||||
(if (= other.behavior "block") :slide :cross))
|
||||
|
||||
(lambda vision-bump-filter [other]
|
||||
(= other.behavior "block"))
|
||||
|
||||
(lambda angle-to-direction [angle]
|
||||
"Convert angle (radians) to compass direction keyword"
|
||||
(local tau (* 2 math.pi))
|
||||
|
|
@ -31,7 +28,6 @@
|
|||
(local height 15)
|
||||
(local player {
|
||||
:x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 :rot 0
|
||||
:vision-pts []
|
||||
:hitbox [50 50 width height]
|
||||
:init-move false ; nudge the player at start of game to trigger starting collisions
|
||||
})
|
||||
|
|
@ -42,54 +38,6 @@
|
|||
(when col.other.on-hit (col.other:on-hit))
|
||||
(beholder.trigger "PLAYER.HIT" col.other)))
|
||||
|
||||
(lambda origin-pt [x y]
|
||||
(values (+ x (/ width 2)) (+ y (/ height 2))))
|
||||
|
||||
|
||||
(lambda player.cal-vision-points [self]
|
||||
(let [
|
||||
(ox oy) (origin-pt self.x self.y)
|
||||
pts []]
|
||||
(lambda add-pt [x y] (table.insert pts [x y]))
|
||||
(for [i 1 5]
|
||||
(add-pt (- ox (* i 5) 50) (- oy (- 50 (* i 5) ))))
|
||||
(for [i 1 10]
|
||||
(add-pt (- ox (* i 5)) (- oy 50)))
|
||||
(add-pt ox (- oy 50)) ; middle pt
|
||||
(for [i 1 10]
|
||||
(add-pt (+ ox (* i 5)) (- oy 50)))
|
||||
(for [i 1 5]
|
||||
(add-pt (+ ox (* i 5) 50) (- oy (- 50 (* i 5) ))))
|
||||
(table.sort pts (lambda [a b] (let [x1 (. a 1) x2 (. b 1)]
|
||||
(> x1 x2))))
|
||||
(icollect [_ pt (ipairs pts)]
|
||||
(let [
|
||||
[x y] pt
|
||||
(rx ry) (utils.rotate-pt x y ox oy self.rot)]
|
||||
[rx ry]))
|
||||
)
|
||||
)
|
||||
|
||||
(lambda player.cal-vision-poly [self]
|
||||
(let [pts (self:cal-vision-points)
|
||||
(ox oy) (origin-pt self.x self.y)
|
||||
poly-pts [ox oy]
|
||||
]
|
||||
(each [_ pt (ipairs pts)]
|
||||
(let [
|
||||
items (bump-world:querySegmentWithCoords ox oy (. pt 1) (. pt 2) vision-bump-filter)
|
||||
first-item (. items 1)]
|
||||
(if first-item
|
||||
(do
|
||||
(table.insert poly-pts (. first-item :x1))
|
||||
(table.insert poly-pts (. first-item :y1)))
|
||||
(do
|
||||
(table.insert poly-pts (. pt 1))
|
||||
(table.insert poly-pts (. pt 2))))))
|
||||
(set self.vision-pts poly-pts)
|
||||
))
|
||||
|
||||
|
||||
(fn player.update [self dt]
|
||||
(when (= self.init-move false)
|
||||
(set self.init-move true)
|
||||
|
|
@ -114,12 +62,10 @@
|
|||
(x y cols len) (bump-world:move self new-x new-y bump-filter)]
|
||||
(handle-collisions cols)
|
||||
(set self.x x)
|
||||
(set self.y y)
|
||||
(self:cal-vision-poly))
|
||||
(set self.y y))
|
||||
(if (> self.battery 0)
|
||||
(set self.battery (- self.battery (* dt 2))))))
|
||||
(beholder.trigger "PLAYER.POS" self.x self.y)
|
||||
(beholder.trigger "PLAYER.VISION" self.vision-pts)
|
||||
(beholder.trigger "PLAYER.BATTERY" self.battery))
|
||||
|
||||
(fn player.load [self]
|
||||
|
|
@ -152,19 +98,11 @@
|
|||
(. self.quads (angle-to-direction player.rot))
|
||||
(- self.x 3) (- self.y 7)))
|
||||
|
||||
|
||||
(lambda player.draw-vision-debug [self]
|
||||
"draw debug lines and points for player vision"
|
||||
(color.set-color :black)
|
||||
(when (> (length self.vision-pts) 2) (love.graphics.polygon "line" self.vision-pts))
|
||||
)
|
||||
|
||||
(fn player.draw-debug [self]
|
||||
"draw player hitbox and direction line"
|
||||
(color.set-color :black)
|
||||
(self:draw-vision-debug)
|
||||
(love.graphics.rectangle "line" self.x self.y width height)
|
||||
; (love.graphics.rectangle "line" self.x self.y 1 1)
|
||||
(love.graphics.rectangle "line" self.x self.y 1 1)
|
||||
(love.graphics.push)
|
||||
(let [ox (+ self.x (/ width 2)) oy (+ self.y (/ height 2))]
|
||||
(love.graphics.translate ox oy)
|
||||
|
|
|
|||
|
|
@ -8,11 +8,8 @@
|
|||
(local walls (require "src/systems/walls.fnl"))
|
||||
(local hud (require "src/systems/hud.fnl"))
|
||||
(local levels (require "levels.fnl"))
|
||||
(local fog-of-war (require "src/systems/fog_of_war.fnl"))
|
||||
(local radar (require "src/systems/radar.fnl"))
|
||||
(local info-pad (require "src/entities/info-pad.fnl"))
|
||||
|
||||
; TODO: refactor the args away. create a load method and get them from self.pool
|
||||
(lambda load-objects [level-key pool]
|
||||
(each [_ object (pairs (. levels :levels level-key :objects))]
|
||||
; (debug-print object)
|
||||
|
|
@ -21,10 +18,13 @@
|
|||
))
|
||||
)
|
||||
|
||||
(lambda collider-manager [bump-world]
|
||||
(local collider-manager {})
|
||||
(lambda collider-manager.addToGroup [self group-name entity]
|
||||
(when (= group-name :hitbox)
|
||||
(self.pool.data.bump-world:add entity (unpack entity.hitbox))))
|
||||
; (utils.debug-print {:adding entity})
|
||||
(bump-world:add entity (unpack entity.hitbox))))
|
||||
collider-manager)
|
||||
|
||||
; (lambda register-notifications []
|
||||
; (beholder.observe "PLAYER.HIT" (lambda [other]
|
||||
|
|
@ -57,11 +57,9 @@
|
|||
}
|
||||
:systems [
|
||||
(nata:oop)
|
||||
collider-manager
|
||||
(collider-manager bump-world)
|
||||
camera
|
||||
walls
|
||||
fog-of-war
|
||||
radar
|
||||
(hud {: screen})
|
||||
]
|
||||
})]
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
(local camera {:x 0 :y 0})
|
||||
|
||||
(fn camera.draw10 [self]
|
||||
(love.graphics.origin)
|
||||
(fn camera.draw2 [self]
|
||||
(love.graphics.push)
|
||||
(love.graphics.translate (* -1 self.x) (* -1 self.y)))
|
||||
|
||||
(fn camera.load [self]
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
(set self.y (- y (/ screen.canvas-h 2)))))))
|
||||
|
||||
(fn camera.draw89 [self]
|
||||
(love.graphics.origin)) ; reset camera translation
|
||||
(love.graphics.pop)) ; undo camera translation
|
||||
|
||||
(fn camera.draw99 [self]
|
||||
(let [screen self.pool.data.screen canvas self.pool.data.canvas]
|
||||
|
|
@ -29,7 +29,6 @@
|
|||
(let [screen self.pool.data.screen canvas self.pool.data.canvas]
|
||||
; use canvas
|
||||
(love.graphics.setCanvas canvas)
|
||||
; (love.graphics.setCanvas {: canvas :stencil true})
|
||||
; clear the screen
|
||||
(love.graphics.clear)
|
||||
(color.set-color :cream)
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
(local color (require "src/colors.fnl"))
|
||||
(local utils (require "src/utils.fnl"))
|
||||
(local beholder (require "libs/beholder"))
|
||||
(local levels (require "levels.fnl"))
|
||||
(local assets (require "src/assets.fnl"))
|
||||
|
||||
(local fow
|
||||
{
|
||||
:player-vision-pts []
|
||||
:player-pos [0 0]
|
||||
:player-quad nil
|
||||
:font nil
|
||||
:canvas nil })
|
||||
|
||||
(lambda fow.load [self]
|
||||
(let [(w h) (assets.player-sprite:getDimensions)]
|
||||
(set self.player-quad (love.graphics.newQuad 0 0 25 25 w h)))
|
||||
(set self.font (love.graphics.newFont 10))
|
||||
(set self.canvas (love.graphics.newCanvas 1000 1000))
|
||||
(beholder.observe "PLAYER.VISION" (lambda [pts]
|
||||
(set self.player-vision-pts pts)))
|
||||
(beholder.observe "PLAYER.POS" (lambda [x y]
|
||||
(set self.player-pos [x y])))
|
||||
(let [previousCanvas (love.graphics.getCanvas)]
|
||||
(love.graphics.setCanvas self.canvas)
|
||||
(color.set-color :dark-purple)
|
||||
(love.graphics.rectangle "fill" 0 0 1000 1000)
|
||||
(love.graphics.setCanvas previousCanvas)
|
||||
))
|
||||
|
||||
(lambda fow.draw9 [self]
|
||||
(let [
|
||||
previousCanvas (love.graphics.getCanvas)
|
||||
previousBlendMode (love.graphics.getBlendMode)
|
||||
[x y] self.player-pos]
|
||||
(love.graphics.setCanvas self.canvas)
|
||||
(love.graphics.clear)
|
||||
(color.set-color :dark-purple)
|
||||
(love.graphics.rectangle "fill" 0 0 1000 1000)
|
||||
(love.graphics.setBlendMode "replace")
|
||||
(love.graphics.setColor 0 0 0 0) ; transparent
|
||||
; draw player quad to uncover the player
|
||||
(love.graphics.push)
|
||||
(love.graphics.translate (- x 3) (- y 7))
|
||||
(love.graphics.polygon "fill" 3 11 3 17 7 21 17 21 21 17 21 11 17 7 7 7)
|
||||
(love.graphics.pop)
|
||||
; draw the vision cone
|
||||
(when (> (length self.player-vision-pts) 2)
|
||||
(love.graphics.polygon "fill" self.player-vision-pts))
|
||||
(love.graphics.setBlendMode previousBlendMode)
|
||||
(love.graphics.setCanvas previousCanvas)))
|
||||
|
||||
(lambda fow.draw80 [self]
|
||||
(color.reset-color)
|
||||
(love.graphics.draw self.canvas 0 0))
|
||||
|
||||
fow
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
(local color (require "src/colors.fnl"))
|
||||
(local utils (require "src/utils.fnl"))
|
||||
(local beholder (require "libs/beholder"))
|
||||
(local levels (require "levels.fnl"))
|
||||
(local assets (require "src/assets.fnl"))
|
||||
|
||||
(local radar
|
||||
{ :player-pos [0 0]
|
||||
:rot 0
|
||||
:speed 4 })
|
||||
|
||||
(lambda radar.load [self]
|
||||
(beholder.observe "PLAYER.POS" (lambda [x y]
|
||||
(set self.player-pos [x y]))))
|
||||
|
||||
(lambda radar.update [self dt]
|
||||
(set self.rot (+ self.rot (* (/ dt self.speed)))))
|
||||
|
||||
(lambda radar.draw81 [self]
|
||||
(let [
|
||||
w 19 h 15
|
||||
[x y] self.player-pos
|
||||
ox (+ x (/ w 2))
|
||||
oy (+ y (/ h 2))
|
||||
]
|
||||
(color.set-color :dark-pink)
|
||||
(love.graphics.push)
|
||||
(love.graphics.translate ox oy)
|
||||
(love.graphics.rotate self.rot)
|
||||
(love.graphics.setPointSize 2)
|
||||
(love.graphics.points 0 0)
|
||||
(love.graphics.circle "line" 0 0 150)
|
||||
(love.graphics.line 0 0 0 150)
|
||||
(love.graphics.pop)))
|
||||
|
||||
radar
|
||||
|
|
@ -6,7 +6,6 @@
|
|||
:quads []
|
||||
:batch nil
|
||||
:collider-debug-boxes []
|
||||
:debug-grid-canvas nil
|
||||
})
|
||||
|
||||
(lambda mirror-collider [collider]
|
||||
|
|
@ -19,17 +18,6 @@
|
|||
:height collider.height
|
||||
})
|
||||
|
||||
(fn draw-debug-grid []
|
||||
(let [f (love.graphics.newFont 6)]
|
||||
(love.graphics.setFont f)
|
||||
(for [x 0 100 1]
|
||||
(for [y 0 100 1]
|
||||
(let [x1 (* x 100)
|
||||
y1 (* y 100)]
|
||||
(love.graphics.line x1 y1 (+ x1 1000) y1)
|
||||
(love.graphics.line x1 y1 x1 (+ y1 1000))
|
||||
(love.graphics.print (.. (string.format "%d" x1) "," (string.format "%d" y1)) (+ x1 3) (+ y1 3)))))))
|
||||
|
||||
(fn walls.load [self]
|
||||
(set self.batch (love.graphics.newSpriteBatch assets.walls-sprite 2500))
|
||||
;; load quads
|
||||
|
|
@ -55,26 +43,15 @@
|
|||
(self.pool.data.bump-world:add {: x : y :name :wall :behavior :block} collider-x collider-y mirrored-collider.width mirrored-collider.height)
|
||||
(table.insert
|
||||
self.collider-debug-boxes
|
||||
{:x collider-x :y collider-y :width mirrored-collider.width :height mirrored-collider.height}))))))))
|
||||
|
||||
|
||||
(set self.debug-grid-canvas (love.graphics.newCanvas 1000 1000))
|
||||
(love.graphics.setCanvas self.debug-grid-canvas)
|
||||
(draw-debug-grid)
|
||||
(love.graphics.setCanvas)
|
||||
|
||||
)
|
||||
{:x collider-x :y collider-y :width mirrored-collider.width :height mirrored-collider.height})))))))))
|
||||
|
||||
(fn walls.draw49 [self]
|
||||
(color.reset-color)
|
||||
(love.graphics.draw self.batch))
|
||||
|
||||
|
||||
(fn walls.draw-debug [self]
|
||||
"draw collider debug boxes"
|
||||
(color.set-color :black)
|
||||
; (draw-debug-grid)
|
||||
(love.graphics.draw self.debug-grid-canvas 0 0)
|
||||
(each [_ collider (pairs self.collider-debug-boxes)]
|
||||
(love.graphics.rectangle "line" collider.x collider.y collider.width collider.height)))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,49 +1,6 @@
|
|||
; Radian constants at 30-degree increments
|
||||
(local deg-0 0)
|
||||
(local deg-30 (/ math.pi 6))
|
||||
(local deg-60 (/ math.pi 3))
|
||||
(local deg-90 (/ math.pi 2))
|
||||
(local deg-120 (* 2 (/ math.pi 3)))
|
||||
(local deg-150 (* 5 (/ math.pi 6)))
|
||||
(local deg-180 math.pi)
|
||||
(local deg-210 (* 7 (/ math.pi 6)))
|
||||
(local deg-240 (* 4 (/ math.pi 3)))
|
||||
(local deg-270 (* 3 (/ math.pi 2)))
|
||||
(local deg-300 (* 5 (/ math.pi 3)))
|
||||
(local deg-330 (* 11 (/ math.pi 6)))
|
||||
(local deg-360 (* 2 math.pi))
|
||||
|
||||
|
||||
(lambda debug-print [obj]
|
||||
(print (fennel.view obj)))
|
||||
|
||||
|
||||
(lambda rotate-pt [x y ox oy theta]
|
||||
(let [
|
||||
fix-theta (+ theta deg-90)
|
||||
cos-theta (math.cos fix-theta)
|
||||
sin-theta (math.sin fix-theta)
|
||||
translated-x (- x ox)
|
||||
translated-y (- y oy)
|
||||
rotated-x (- (* translated-x cos-theta) (* translated-y sin-theta))
|
||||
rotated-y (+ (* translated-x sin-theta) (* translated-y cos-theta))]
|
||||
(values (+ ox rotated-x) (+ oy rotated-y))))
|
||||
|
||||
|
||||
{
|
||||
: debug-print
|
||||
: rotate-pt
|
||||
: deg-0
|
||||
: deg-30
|
||||
: deg-60
|
||||
: deg-90
|
||||
: deg-120
|
||||
: deg-150
|
||||
: deg-180
|
||||
: deg-210
|
||||
: deg-240
|
||||
: deg-270
|
||||
: deg-300
|
||||
: deg-330
|
||||
: deg-360
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue