multibucket, better collisions
This commit is contained in:
parent
a7bb98983c
commit
945614d3b4
|
@ -39,7 +39,7 @@
|
||||||
(tbl.extend state
|
(tbl.extend state
|
||||||
{:bomber {:x 200}
|
{:bomber {:x 200}
|
||||||
:bombs []
|
:bombs []
|
||||||
:bucket {:x 200 :count 3}
|
:bucket {:count 3}
|
||||||
:level 1
|
:level 1
|
||||||
:state :waiting
|
:state :waiting
|
||||||
:scene :ingame}))
|
:scene :ingame}))
|
||||||
|
@ -77,9 +77,15 @@
|
||||||
xoffset (/ bucketw 2)
|
xoffset (/ bucketw 2)
|
||||||
buckety 200
|
buckety 200
|
||||||
image (make-image bucketw bucketh #(gfx.drawRoundRect 0 0 bucketw bucketh radius))]
|
image (make-image bucketw bucketh #(gfx.drawRoundRect 0 0 bucketw bucketh radius))]
|
||||||
(defsprite :bucket #(doto $1 (with-image image 0.5 0) (with-collision 1 2)))
|
(defsprite :bucket #(doto $1 (with-image image 0.5 0) (with-collision 1 2))))
|
||||||
(draw:defmethod :bucket (fn [_ {: x}]
|
|
||||||
(doto (sprite :bucket) (: :moveTo x buckety)))))
|
(fn lose-life [ctx]
|
||||||
|
(let [count ctx.bucket.count]
|
||||||
|
(set ctx.bucket.count (- count 1))
|
||||||
|
(cache.destroy :bucket count)
|
||||||
|
(destroy-all :bombs ctx)
|
||||||
|
(set ctx.bombs [])
|
||||||
|
(set ctx.state :waiting)))
|
||||||
|
|
||||||
(update:defmethod :bucket (fn [_ bucket]
|
(update:defmethod :bucket (fn [_ bucket]
|
||||||
(let [crank (playdate.getCrankPosition)
|
(let [crank (playdate.getCrankPosition)
|
||||||
|
@ -88,11 +94,9 @@
|
||||||
(> ratio 1) 1
|
(> ratio 1) 1
|
||||||
ratio)
|
ratio)
|
||||||
x (* (/ (+ ratio 1) 2) screenw)]
|
x (* (/ (+ ratio 1) 2) screenw)]
|
||||||
(set bucket.x x))
|
(for [ibucket 1 bucket.count]
|
||||||
(let [collisions (: (sprite :bucket) :overlappingSprites)]
|
(let [buckety (- 220 (* (- ibucket 1) 25))]
|
||||||
(each [_ spr (ipairs collisions)]
|
(doto (sprite :bucket ibucket) (: :moveTo x buckety)))))))
|
||||||
(print "poof")
|
|
||||||
(set spr.bomb.defused true)))))
|
|
||||||
|
|
||||||
(fn drop-bomb [ctx]
|
(fn drop-bomb [ctx]
|
||||||
(table.insert ctx.bombs {:x ctx.bomber.x :y 30}))
|
(table.insert ctx.bombs {:x ctx.bomber.x :y 30}))
|
||||||
|
@ -105,22 +109,24 @@
|
||||||
(update:defmethod :bomber (fn [_ _ _ ctx]
|
(update:defmethod :bomber (fn [_ _ _ ctx]
|
||||||
(when (playdate.buttonJustPressed :a)
|
(when (playdate.buttonJustPressed :a)
|
||||||
(set ctx.state :bombing)
|
(set ctx.state :bombing)
|
||||||
(drop-bomb ctx))))
|
(drop-bomb ctx))
|
||||||
|
(when (playdate.buttonJustPressed :b)
|
||||||
|
(set ctx.bucket.count 3))))
|
||||||
|
|
||||||
(gfx.sprite.setBackgroundDrawingCallback #(gfx.drawLine 0 33 screenw 33))
|
(gfx.sprite.setBackgroundDrawingCallback #(gfx.drawLine 0 33 screenw 33))
|
||||||
|
|
||||||
(let [image (make-image 14 14 #(gfx.fillCircleAtPoint 7 7 7))]
|
(let [image (make-image 14 14 #(gfx.fillCircleAtPoint 7 7 7))]
|
||||||
(defsprite :bombs #(doto $1 (with-image image 0.5 0.5) (with-collision 2 1) (tset :bomb $3)))
|
(defsprite :bombs #(doto $1 (with-image image 0.5 0.5) (with-collision 2 1) (tset :bomb $3))))
|
||||||
(draw:defmethod :bombs (fn [_ {: x : y &as bomb}]
|
|
||||||
(doto (sprite :bombs bomb) (: :moveTo x y)))))
|
|
||||||
|
|
||||||
(fn bombspeed [ctx] (+ ctx.level 5))
|
(fn bombspeed [ctx] (+ ctx.level 3))
|
||||||
|
|
||||||
(update:defmethod :bombs (fn [_ bomb ibomb ctx]
|
(update:defmethod :bombs (fn [_ bomb ibomb ctx]
|
||||||
(when (= ctx.state :bombing)
|
(when (= ctx.state :bombing)
|
||||||
(set bomb.y (+ bomb.y (bombspeed ctx)))
|
(let [spr (doto (sprite :bombs bomb) (: :moveTo bomb.x bomb.y))
|
||||||
(when (or (> bomb.y screenh) bomb.defused)
|
(_ y _ count) (spr:moveWithCollisions bomb.x (+ bomb.y (bombspeed ctx)))]
|
||||||
(destroy-item :bombs bomb ctx ibomb)))))
|
(if (> count 0) (destroy-item :bombs bomb ctx ibomb)
|
||||||
|
(> y screenh) (lose-life ctx)
|
||||||
|
(set bomb.y y))))))
|
||||||
|
|
||||||
(fn scene-update [keys ctx]
|
(fn scene-update [keys ctx]
|
||||||
(do-to-children keys update ctx)
|
(do-to-children keys update ctx)
|
||||||
|
|
Loading…
Reference in a new issue