get battery charging via pads working
This commit is contained in:
parent
753e6ace68
commit
4540542f13
1 changed files with 31 additions and 9 deletions
|
|
@ -88,20 +88,26 @@
|
||||||
(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}
|
||||||
]
|
pad1 {:x (- x 25) :y y :width 25 :height 25}
|
||||||
|
pad2 {:x (+ x 25) :y y :width 25 :height 25}
|
||||||
|
pad3 {:x x :y (+ y 25) :width 25 :height 25}]
|
||||||
(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})
|
(table.insert collider-debug-boxes {: x : y :width 25 :height 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 (- self.x 25) self.y)
|
(love.graphics.draw objects.sprite objects.quads.charging-pad pad1.x pad1.y)
|
||||||
(love.graphics.draw objects.sprite objects.quads.charging-pad (+ self.x 25) self.y)
|
(love.graphics.draw objects.sprite objects.quads.charging-pad pad2.x pad2.y)
|
||||||
(love.graphics.draw objects.sprite objects.quads.charging-pad self.x (+ self.y 25))
|
(love.graphics.draw objects.sprite objects.quads.charging-pad pad3.x pad3.y)
|
||||||
)
|
)
|
||||||
(bump-world:add {: x : y :name :charging-pad :behavior :hover} (- x 25) y 25 25)
|
(lambda pad-hover-cb [self dt]
|
||||||
|
(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)
|
||||||
(table.insert collider-debug-boxes {:x (- x 25) : y :width 25 :height 25})
|
(table.insert collider-debug-boxes {:x (- x 25) : y :width 25 :height 25})
|
||||||
(bump-world:add {: x : y :name :charging-pad :behavior :hover} (+ x 25) y 25 25)
|
(bump-world:add {: x : y :name :charging-pad :behavior :hover :hover-cb pad-hover-cb} (+ x 25) y 25 25)
|
||||||
(bump-world:add {: x : y :name :charging-pad :behavior :hover} x (+ y 25) 25 25)
|
(table.insert collider-debug-boxes {:x (+ x 25) : y :width 25 :height 25})
|
||||||
|
(bump-world:add {: x : y :name :charging-pad :behavior :hover :hover-cb pad-hover-cb} x (+ y 25) 25 25)
|
||||||
|
(table.insert collider-debug-boxes {:x x :y (+ y 25) :width 25 :height 25})
|
||||||
(table.insert objects.list station)))
|
(table.insert objects.list station)))
|
||||||
|
|
||||||
(fn load-objects []
|
(fn load-objects []
|
||||||
|
|
@ -197,13 +203,29 @@ 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)
|
||||||
(tset player :battery (- player.battery (* dt 2))))))
|
(set player.battery (- player.battery (* dt 2))))))
|
||||||
;; 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.canvas-w 2)))
|
||||||
(tset camera :y (- player.y (/ screen.canvas-h 2))))
|
(tset camera :y (- player.y (/ screen.canvas-h 2)))
|
||||||
|
|
||||||
|
(let
|
||||||
|
[(items len) (bump-world:queryRect player.x player.y 25 25 #(= $1.behavior "hover"))]
|
||||||
|
(each [_ item (pairs items)]
|
||||||
|
(item:hover-cb dt))))
|
||||||
|
|
||||||
(fn draw-ui []
|
(fn draw-ui []
|
||||||
(love.graphics.push)
|
(love.graphics.push)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue