show active state of charging pads
This commit is contained in:
parent
4540542f13
commit
99f73315b3
3 changed files with 28 additions and 25 deletions
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 457 B After Width: | Height: | Size: 549 B |
|
|
@ -56,6 +56,9 @@
|
||||||
(print (fennel.view obj)))
|
(print (fennel.view obj)))
|
||||||
|
|
||||||
(local collider-debug-boxes [])
|
(local collider-debug-boxes [])
|
||||||
|
(lambda add-collider-debug-box [x y w h]
|
||||||
|
(table.insert collider-debug-boxes {: x : y :width w :height h}))
|
||||||
|
|
||||||
(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 :battery 100 :rot 0 })
|
||||||
|
|
||||||
|
|
@ -87,33 +90,42 @@
|
||||||
|
|
||||||
(lambda create-charging-station [x y]
|
(lambda create-charging-station [x y]
|
||||||
(let [
|
(let [
|
||||||
station {: x : y :type :charging-station}
|
station {: x : y :type :charging-station :active-pads {1 false 2 false 3 false}}
|
||||||
pad1 {:x (- x 25) :y y :width 25 :height 25}
|
pads {
|
||||||
pad2 {:x (+ x 25) :y y :width 25 :height 25}
|
1 {:x (- x 25) :y y :width 25 :height 25 :light-x (+ x 5)}
|
||||||
pad3 {:x x :y (+ y 25) :width 25 :height 25}]
|
3 {:x (+ x 25) :y y :width 25 :height 25 :light-x (+ x 5 6 6)}
|
||||||
|
2 {:x x :y (+ y 25) :width 25 :height 25 :light-x (+ x 5 6)}
|
||||||
|
}]
|
||||||
(bump-world:add {: x : y :name :charging-station :behavior :block} x y 25 25)
|
(bump-world:add {: x : y :name :charging-station :behavior :block} x y 25 25)
|
||||||
(table.insert collider-debug-boxes {: x : y :width 25 :height 25})
|
(add-collider-debug-box x y 25 25)
|
||||||
(fn station.draw [self]
|
(fn station.draw [self]
|
||||||
(reset-color)
|
(reset-color)
|
||||||
(love.graphics.draw objects.sprite objects.quads.charging-station self.x self.y)
|
(love.graphics.draw objects.sprite objects.quads.charging-station self.x self.y)
|
||||||
(love.graphics.draw objects.sprite objects.quads.charging-pad pad1.x pad1.y)
|
(for [i 1 3 1]
|
||||||
(love.graphics.draw objects.sprite objects.quads.charging-pad pad2.x pad2.y)
|
(let [pad (. pads i)]
|
||||||
(love.graphics.draw objects.sprite objects.quads.charging-pad pad3.x pad3.y)
|
(if (. self.active-pads i)
|
||||||
|
(do (love.graphics.draw objects.sprite objects.quads.charging-pad-active pad.x pad.y)
|
||||||
|
(set-color :light-pink)
|
||||||
|
(love.graphics.rectangle "fill" pad.light-x (+ y 18) 2 2)
|
||||||
|
(reset-color))
|
||||||
|
(love.graphics.draw objects.sprite objects.quads.charging-pad pad.x pad.y))))
|
||||||
)
|
)
|
||||||
(lambda pad-hover-cb [self dt]
|
(lambda pad-hover-cb [self dt]
|
||||||
|
(tset station.active-pads self.id true)
|
||||||
(when (< player.battery 100) (set player.battery (+ player.battery (* dt 6)))))
|
(when (< player.battery 100) (set player.battery (+ player.battery (* dt 6)))))
|
||||||
(bump-world:add {: x : y :name :charging-pad :behavior :hover :hover-cb pad-hover-cb} (- x 25) y 25 25)
|
(lambda station.update [self _dt]
|
||||||
(table.insert collider-debug-boxes {:x (- x 25) : y :width 25 :height 25})
|
(set self.active-pads {1 false 2 false 3 false}))
|
||||||
(bump-world:add {: x : y :name :charging-pad :behavior :hover :hover-cb pad-hover-cb} (+ x 25) y 25 25)
|
(for [i 1 3 1]
|
||||||
(table.insert collider-debug-boxes {:x (+ x 25) : y :width 25 :height 25})
|
(let [pad (. pads i)]
|
||||||
(bump-world:add {: x : y :name :charging-pad :behavior :hover :hover-cb pad-hover-cb} x (+ y 25) 25 25)
|
(bump-world:add {:name :charging-pad :behavior :hover :hover-cb pad-hover-cb :id i} pad.x pad.y 25 25)
|
||||||
(table.insert collider-debug-boxes {:x x :y (+ y 25) :width 25 :height 25})
|
(add-collider-debug-box pad.x pad.y 25 25)))
|
||||||
(table.insert objects.list station)))
|
(table.insert objects.list station)))
|
||||||
|
|
||||||
(fn load-objects []
|
(fn load-objects []
|
||||||
(set objects.sprite (love.graphics.newImage "assets/objects.png"))
|
(set objects.sprite (love.graphics.newImage "assets/objects.png"))
|
||||||
(let [(w h) (objects.sprite:getDimensions)]
|
(let [(w h) (objects.sprite:getDimensions)]
|
||||||
(set objects.quads.charging-pad (love.graphics.newQuad 0 0 25 25 w h))
|
(set objects.quads.charging-pad (love.graphics.newQuad 0 0 25 25 w h))
|
||||||
|
(set objects.quads.charging-pad-active (love.graphics.newQuad 50 0 25 25 w h))
|
||||||
(set objects.quads.charging-station (love.graphics.newQuad 25 0 25 25 w h)))
|
(set objects.quads.charging-station (love.graphics.newQuad 25 0 25 25 w h)))
|
||||||
|
|
||||||
(each [_ row (pairs (. levels :level01 :tiles))]
|
(each [_ row (pairs (. levels :level01 :tiles))]
|
||||||
|
|
@ -182,6 +194,8 @@ while 1 do love.event.push('stdin', io.read('*line')) end") :start))
|
||||||
|
|
||||||
|
|
||||||
(fn love.update [dt]
|
(fn love.update [dt]
|
||||||
|
(each [_ obj (pairs objects.list)]
|
||||||
|
(obj:update dt))
|
||||||
; move / rotate player
|
; move / rotate player
|
||||||
(let [
|
(let [
|
||||||
d-key (love.keyboard.isDown :d)
|
d-key (love.keyboard.isDown :d)
|
||||||
|
|
@ -203,17 +217,6 @@ while 1 do love.event.push('stdin', io.read('*line')) end") :start))
|
||||||
col-filter-fn (lambda [item other]
|
col-filter-fn (lambda [item other]
|
||||||
(if (= other.behavior "block") :slide :cross))
|
(if (= other.behavior "block") :slide :cross))
|
||||||
(x y cols len) (bump-world:move player new-x new-y col-filter-fn)]
|
(x y cols len) (bump-world:move player new-x new-y col-filter-fn)]
|
||||||
; (each [_ col (pairs cols)]
|
|
||||||
; (when (= col.other.behavior "hover")
|
|
||||||
; (col.other:hover-cb dt)
|
|
||||||
; (debug-print col)
|
|
||||||
|
|
||||||
; ))
|
|
||||||
|
|
||||||
; (debug-print col))
|
|
||||||
; (when (. col.other :hover-cb)
|
|
||||||
; (col.other:hover-cb dt)
|
|
||||||
; ))
|
|
||||||
(tset player :x x)
|
(tset player :x x)
|
||||||
(tset player :y y))
|
(tset player :y y))
|
||||||
(if (> player.battery 0)
|
(if (> player.battery 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue