add dev level and get info pads working
This commit is contained in:
parent
7e75b665f5
commit
276c7c562b
10 changed files with 246 additions and 13 deletions
|
|
@ -4,12 +4,18 @@
|
|||
(local levels (require "levels.fnl"))
|
||||
(local assets (require "src/assets.fnl"))
|
||||
|
||||
(lambda info-pad [x y name]
|
||||
(let [pad {: x : y : name :hitbox [x y 25 25]}
|
||||
(lambda info-pad [obj]
|
||||
(let [
|
||||
x obj.x
|
||||
y obj.y
|
||||
content obj.content
|
||||
pad {: x : y : content :hitbox [x y 25 25]}
|
||||
(w h) (assets.objects-sprite:getDimensions)]
|
||||
(lambda pad.load [self]
|
||||
(set self.quad (love.graphics.newQuad 75 0 25 25 w h)))
|
||||
|
||||
(lambda pad.on-hit [self]
|
||||
(beholder.trigger "NOTIFICATION" self.content))
|
||||
|
||||
(fn pad.draw-debug [self]
|
||||
(color.set-color :black)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
(local utils (require "src/utils.fnl"))
|
||||
(local beholder (require "libs/beholder"))
|
||||
(local color (require "src/colors.fnl"))
|
||||
(local levels (require "levels.fnl"))
|
||||
|
|
@ -25,9 +26,23 @@
|
|||
|
||||
(local width 19)
|
||||
(local height 15)
|
||||
(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 :rot 0 :hitbox [50 50 width height] })
|
||||
(local player {
|
||||
:x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 :rot 0
|
||||
:hitbox [50 50 width height]
|
||||
:init-move false ; nudge the player at start of game to trigger starting collisions
|
||||
})
|
||||
|
||||
|
||||
(lambda handle-collisions [cols]
|
||||
(each [_ col (pairs cols)]
|
||||
(when col.other.on-hit (col.other:on-hit))
|
||||
(beholder.trigger "PLAYER.HIT" col.other)))
|
||||
|
||||
(fn player.update [self dt]
|
||||
(when (= self.init-move false)
|
||||
(set self.init-move true)
|
||||
(let [(x y cols len) (bump-world:move self self.x self.y bump-filter)]
|
||||
(handle-collisions cols)))
|
||||
(let [
|
||||
d-key (love.keyboard.isDown :d)
|
||||
a-key (love.keyboard.isDown :a)
|
||||
|
|
@ -45,6 +60,7 @@
|
|||
new-x (dir-fn self.x (* self.speed dt (math.cos self.rot)))
|
||||
new-y (dir-fn self.y (* self.speed dt (math.sin self.rot)))
|
||||
(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))
|
||||
(if (> self.battery 0)
|
||||
|
|
|
|||
72
two_player_cleaning_game/src/levels/dev.fnl
Normal file
72
two_player_cleaning_game/src/levels/dev.fnl
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
(local bump (require "libs/bump"))
|
||||
(local color (require "src/colors.fnl"))
|
||||
(local nata (require "libs/nata"))
|
||||
(local utils (require "src/utils.fnl"))
|
||||
(local camera (require "src/systems/camera.fnl"))
|
||||
(local beholder (require "libs/beholder"))
|
||||
(local player (require "src/entities/player.fnl"))
|
||||
(local walls (require "src/systems/walls.fnl"))
|
||||
(local hud (require "src/systems/hud.fnl"))
|
||||
(local levels (require "levels.fnl"))
|
||||
(local info-pad (require "src/entities/info-pad.fnl"))
|
||||
|
||||
(lambda load-objects [level-key pool]
|
||||
(each [_ object (pairs (. levels :levels level-key :objects))]
|
||||
; (debug-print object)
|
||||
(case object.type
|
||||
"info_pad" (pool:queue (info-pad object))
|
||||
))
|
||||
)
|
||||
|
||||
(lambda collider-manager [bump-world]
|
||||
(local collider-manager {})
|
||||
(lambda collider-manager.addToGroup [self group-name entity]
|
||||
(when (= group-name :hitbox)
|
||||
; (utils.debug-print {:adding entity})
|
||||
(bump-world:add entity (unpack entity.hitbox))))
|
||||
collider-manager)
|
||||
|
||||
; (lambda register-notifications []
|
||||
; (beholder.observe "PLAYER.HIT" (lambda [other]
|
||||
; (when (= other.object-type :info-pad)
|
||||
; (beholder.trigger "NOTIFICATION" "[a] is left wheel forward [d] is right wheel forward"))
|
||||
; (utils.debug-print {: other}))))
|
||||
; (beholder.observe "PLAYER.HIT" :info-pad (lambda [info-pad-name]
|
||||
; (case info-pad-name
|
||||
; :controls (beholder.trigger "NOTIFICATION" "[a] is left wheel forward [d] is right wheel forward")
|
||||
; ))))
|
||||
|
||||
|
||||
(fn load [screen]
|
||||
; (register-notifications)
|
||||
(let [
|
||||
canvas (love.graphics.newCanvas screen.canvas-w screen.canvas-h)
|
||||
level-key :dev
|
||||
bump-world (bump.newWorld 25)
|
||||
pool (nata.new {
|
||||
:data {
|
||||
: screen
|
||||
: canvas
|
||||
: bump-world
|
||||
: level-key
|
||||
}
|
||||
:groups {
|
||||
; gravity = {filter = {'gravity'}},
|
||||
:hitbox {:filter [:hitbox]}
|
||||
; :post-draw {:filter [:post-draw]}
|
||||
}
|
||||
:systems [
|
||||
(nata:oop)
|
||||
(collider-manager bump-world)
|
||||
camera
|
||||
walls
|
||||
(hud {: screen})
|
||||
]
|
||||
})]
|
||||
(pool:queue (player {: bump-world : level-key}))
|
||||
(load-objects level-key pool)
|
||||
pool))
|
||||
|
||||
{
|
||||
: load
|
||||
}
|
||||
|
|
@ -26,8 +26,19 @@
|
|||
(bump-world:add entity (unpack entity.hitbox))))
|
||||
collider-manager)
|
||||
|
||||
(lambda register-notifications []
|
||||
(beholder.observe "PLAYER.HIT" (lambda [other]
|
||||
(when (= other.object-type :info-pad)
|
||||
(beholder.trigger "NOTIFICATION" "[a] is left wheel forward [d] is right wheel forward"))
|
||||
(utils.debug-print {: other}))))
|
||||
; (beholder.observe "PLAYER.HIT" :info-pad (lambda [info-pad-name]
|
||||
; (case info-pad-name
|
||||
; :controls (beholder.trigger "NOTIFICATION" "[a] is left wheel forward [d] is right wheel forward")
|
||||
; ))))
|
||||
|
||||
|
||||
(fn load [screen]
|
||||
(register-notifications)
|
||||
(let [
|
||||
canvas (love.graphics.newCanvas screen.canvas-w screen.canvas-h)
|
||||
bump-world (bump.newWorld 25)
|
||||
|
|
|
|||
|
|
@ -5,14 +5,39 @@
|
|||
(var screen nil)
|
||||
(local hud {
|
||||
:player-battery 0
|
||||
:notification nil
|
||||
:notification-life 0
|
||||
})
|
||||
|
||||
(lambda draw-notification [self]
|
||||
(when (and self.notification (> self.notification-life 0))
|
||||
(love.graphics.push)
|
||||
(love.graphics.translate 0 (- 400 20))
|
||||
(color.set-color :cream)
|
||||
(love.graphics.rectangle "fill" 0 0 screen.canvas-w 20)
|
||||
(color.set-color :dark-purple)
|
||||
(color.set-color :dark-purple)
|
||||
(love.graphics.line 0 0 screen.canvas-w 0)
|
||||
(love.graphics.setFont self.font)
|
||||
(love.graphics.print self.notification 3 3)
|
||||
(love.graphics.pop)))
|
||||
|
||||
(fn hud.load [self]
|
||||
(set self.font (love.graphics.newFont 10))
|
||||
(set self.font-small (love.graphics.newFont 6))
|
||||
|
||||
(beholder.observe "PLAYER.BATTERY" (lambda [bat]
|
||||
(set self.player-battery bat))))
|
||||
(set self.player-battery bat)))
|
||||
|
||||
(beholder.observe "NOTIFICATION" (lambda [text]
|
||||
(set self.notification text)
|
||||
; set life of notification to 5 seconds
|
||||
(set self.notification-life 5))))
|
||||
|
||||
|
||||
(lambda hud.update [self dt]
|
||||
(when (> self.notification-life 0)
|
||||
(set self.notification-life (- self.notification-life dt))))
|
||||
|
||||
(lambda draw-header [self]
|
||||
(color.set-color :cream)
|
||||
|
|
@ -55,7 +80,8 @@
|
|||
(fn hud.draw90 [self]
|
||||
(draw-side-walls self)
|
||||
(draw-footer self)
|
||||
(draw-header self))
|
||||
(draw-header self)
|
||||
(draw-notification self))
|
||||
|
||||
(lambda [{:screen s}]
|
||||
(set screen s)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue