added ability to change to a different screen (background)

This commit is contained in:
2014-09-16 16:46:30 -07:00
parent 1dccf1538e
commit 37af5dc53e
5 changed files with 84 additions and 48 deletions

View File

@@ -72,8 +72,12 @@
(let [delta-x (- target-x from-x)
delta-y (- target-y from-y)
distance (dist from-x from-y target-x target-y)
moved-x (* 1.5 (/ delta-x distance))
moved-y (* 1.5 (/ delta-y distance))]
moved-x (if (= 0.0 distance)
0
(* 1.5 (/ delta-x distance)))
moved-y (if (= 0.0 distance)
0
(* 1.5 (/ delta-y distance)))]
(if (< distance 1)
(do (swap! targets-left rest)
entities)
@@ -149,3 +153,24 @@
(put! c entities)
entities)))
(reset! entities (<!! c))))
(defn transition-background [entities new-background [x y]]
(let [c (chan)]
(put! (get-in @entities [:actions :channel])
(reify
IAction
(begin [this screen entities]
(-> entities
(assoc-in [:background] (get-in entities [:backgrounds new-background]))
(assoc-in [:ego :x] x)
(assoc-in [:ego :y] y)))
(continue [this screen entities] entities)
(done? [this screen entities]
true)
(terminate [this screen entities]
(put! c entities)
entities)))
(reset! entities (<!! c))))