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

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

View File

@@ -72,8 +72,12 @@
(let [delta-x (- target-x from-x) (let [delta-x (- target-x from-x)
delta-y (- target-y from-y) delta-y (- target-y from-y)
distance (dist from-x from-y target-x target-y) distance (dist from-x from-y target-x target-y)
moved-x (* 1.5 (/ delta-x distance)) moved-x (if (= 0.0 distance)
moved-y (* 1.5 (/ delta-y distance))] 0
(* 1.5 (/ delta-x distance)))
moved-y (if (= 0.0 distance)
0
(* 1.5 (/ delta-y distance)))]
(if (< distance 1) (if (< distance 1)
(do (swap! targets-left rest) (do (swap! targets-left rest)
entities) entities)
@@ -149,3 +153,24 @@
(put! c entities) (put! c entities)
entities))) entities)))
(reset! entities (<!! c)))) (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))))

View File

@@ -114,33 +114,8 @@
(merge params {:collision (advent.pathfind/map-from-resource collision) (merge params {:collision (advent.pathfind/map-from-resource collision)
:interactions interactions-as-list}))) :interactions interactions-as-list})))
(defscreen scene (defn backgrounds []
:on-show {:outside-house (make-background :interactions
(fn [screen entities]
(update! screen :renderer (stage) :camera (orthographic))
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
sheep (animation 0.15 (for [i (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 9 10 (repeat 25 11) (repeat 15 12)])]
(aget sheep-sheet 0 i)))
background (texture "bg5.png")
background-trees (texture "background-trees.png")
house (texture "house.png")
overdirt (texture "overdirt.png")
music (sound "town-music.mp3")
;;_ (sound! music :loop)
]
{
:actions {:object nil
:channel (chan)
:current nil
:started? false}
:cursor {:id "cursor"
:current :main
:last :main
:override nil}
:sheep (assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep)
:background (make-background :interactions
{:door {:box [258 100 281 160] {:door {:box [258 100 281 160]
:script (actions/get-script :script (actions/get-script
entities entities
@@ -172,15 +147,51 @@
:left-dir {:box [0 40 20 140] :left-dir {:box [0 40 20 140]
:script (actions/get-script :script (actions/get-script
entities entities
(actions/walk-to entities :ego [0 80])) (actions/walk-to entities :ego [0 80])
(actions/transition-background entities :behind-house [310 80]))
:cursor :left}} :cursor :left}}
:layers [(assoc (texture "bg5.png") :x 0 :y 0 :baseline 0)
:layers [(assoc background :x 0 :y 0 :baseline 0) (assoc (texture "house.png") :x 0 :y 0 :baseline 122)
(assoc house :x 0 :y 0 :baseline 122) (assoc (texture "overdirt.png") :x 0 :y 0 :baseline 240)
(assoc overdirt :x 0 :y 0 :baseline 240) (assoc (texture "background-trees.png") :x 0 :y 0 :baseline 44)]
(assoc background-trees :x 0 :y 0 :baseline 44)]
:collision "outsidehouse/collision.png" :collision "outsidehouse/collision.png"
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00)) :scale-fn (scaler-fn-with-baseline 110 0.10 1.00))
:behind-house (make-background :interactions
{:right-dir {:box [300 40 320 140]
:script (actions/get-script
entities
(actions/walk-to entities :ego [310 80])
(actions/transition-background entities :outside-house [0 80]))
:cursor :right}}
:layers [(assoc (texture "behindhouse/background.png") :x 0 :y 0 :baseline 0)]
:collision "behindhouse/collision.png"
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))})
(defscreen scene
:on-show
(fn [screen entities]
(update! screen :renderer (stage) :camera (orthographic))
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
sheep (animation 0.15 (for [i (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 9 10 (repeat 25 11) (repeat 15 12)])]
(aget sheep-sheet 0 i)))
music (sound "town-music.mp3")
;;_ (sound! music :loop)
backgrounds (backgrounds)
]
{:backgrounds backgrounds
:actions {:object nil
:channel (chan)
:current nil
:started? false}
:cursor {:id "cursor"
:current :main
:last :main
:override nil}
:sheep (assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep)
:background (:outside-house backgrounds)
:ego (get-ego screen) :ego (get-ego screen)
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 9000) :fps (assoc (label "0" (color :white) ) :x 5 :baseline 9000)
})) }))