adding camera panning. nice.

This commit is contained in:
2015-02-19 11:24:32 -08:00
parent dfdfcd7914
commit e517fffbd4
6 changed files with 179 additions and 116 deletions

View File

@@ -11,6 +11,8 @@
[advent.actions :as actions] [advent.actions :as actions]
[advent.screens.dialogue :as dialogue] [advent.screens.dialogue :as dialogue]
[advent.utils :as utils] [advent.utils :as utils]
[advent.tween :as tween]
[advent.tween :as tween]
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]]) [clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter] (:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion Animation] [com.badlogic.gdx.graphics.g2d TextureRegion Animation]
@@ -84,6 +86,43 @@
~@forms ~@forms
(change-script-state ~entities false))))) (change-script-state ~entities false)))))
(defn pan-to [screen entities x y scale-fn]
(let [target-zoom (min 1.0 (max 0.85 (scale-fn [x y])))
current-zoom (get-in entities [:cam :zoom] 1.0)
;; don't zoom if it's a subtle difference
target-zoom (if (< (Math/abs (- target-zoom current-zoom))
0.07)
current-zoom
target-zoom)
target-x (min (- 320 (* 160.0 target-zoom))
(max (* 160.0 target-zoom)
x))
target-y (min (- 240 (* 120.0 target-zoom))
(max (* 120.0 target-zoom)
y))]
(-> entities
(assoc-in [:tweens :cam-zoom]
(tween/tween :cam-zoom screen
[:cam :zoom]
(get-in entities [:cam :zoom] 1.0)
target-zoom
3.0
:ease tween/ease-in-out-quadratic))
(assoc-in [:tweens :cam-x]
(tween/tween :cam-x screen
[:cam :x]
(get-in entities [:cam :x] 160.0)
target-x
3.0
:ease tween/ease-in-out-quadratic))
(assoc-in [:tweens :cam-y]
(tween/tween :cam-y screen
[:cam :y]
(get-in entities [:cam :y] 120.0)
target-y
3.0
:ease tween/ease-in-out-quadratic)))))
(defn jump-to [screen entities entity [x y] update-baseline?] (defn jump-to [screen entities entity [x y] update-baseline?]
(let [scale-fn (-> entities :room :scale-fn) (let [scale-fn (-> entities :room :scale-fn)
@@ -116,6 +155,8 @@
(update-in entities [:room :entities target-id] (comp #(start-animation screen % :stand) (if face #(assoc % :facing face) identity)))) (update-in entities [:room :entities target-id] (comp #(start-animation screen % :stand) (if face #(assoc % :facing face) identity))))
(defn walk-straight-to [entities target-id [final-x final-y] & {:keys [update-baseline? face speed anim override-dir stop?]}] (defn walk-straight-to [entities target-id [final-x final-y] & {:keys [update-baseline? face speed anim override-dir stop?]}]
(let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id]) (let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id])
final-x (int final-x) final-x (int final-x)
@@ -123,7 +164,9 @@
update-baseline? (if (nil? update-baseline?) true update-baseline?)] update-baseline? (if (nil? update-baseline?) true update-baseline?)]
(run-action entities (run-action entities
(begin [this screen entities] (begin [this screen entities]
entities) (if (= :ego target-id)
(pan-to screen entities final-x final-y (get-in entities [:room :scale-fn]))
entities))
(continue [this screen entities] (continue [this screen entities]
(let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id])] (let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id])]
@@ -221,7 +264,9 @@
(if (seq path) (if (seq path)
(run-action entities (run-action entities
(begin [this screen entities] (begin [this screen entities]
entities) (if (= :ego target-id)
(pan-to screen entities final-x final-y (get-in entities [:room :scale-fn]))
entities))
(continue [this screen entities] (continue [this screen entities]
(let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id]) (let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id])
@@ -474,7 +519,8 @@
duration (or duration 2.0)] duration (or duration 2.0)]
(run-action entities (run-action entities
(begin [this screen entities] (begin [this screen entities]
(assoc-in entities [:tweens :fade-out-music] (utils/tween :fade-out-music screen [:volume :value] 1.0 0.0 duration))) (assoc-in entities [:tweens :fade-out-music]
(tween/tween :fade-out-music screen [:volume :value] 1.0 0.0 duration)))
(continue [this screen entities] (continue [this screen entities]
entities) entities)
@@ -507,9 +553,9 @@
(doseq [[k] (get-in entities [:room :timers])] (doseq [[k] (get-in entities [:room :timers])]
(remove-timer! screen k)) (remove-timer! screen k))
(as-> entities e (as-> entities e
(assoc-in e [:tweens :fade-out] (utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 0.5)) (assoc-in e [:tweens :fade-out] (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 0.5))
(if music-changed? (if music-changed?
(assoc-in e [:tweens :fade-out-music] (utils/tween :fade-out-music screen [:volume :value] 1.0 0.0 0.5)) (assoc-in e [:tweens :fade-out-music] (tween/tween :fade-out-music screen [:volume :value] 1.0 0.0 0.5))
e) e)
(assoc-in e [:cursor :current] :main))) (assoc-in e [:cursor :current] :main)))
@@ -537,9 +583,13 @@
(assoc-in e [:room] (get-in entities [:rooms new-background])) (assoc-in e [:room] (get-in entities [:rooms new-background]))
(assoc-in e [:room :entities :ego] ego) (assoc-in e [:room :entities :ego] ego)
(assoc-in e [:state :last-room] new-background) (assoc-in e [:state :last-room] new-background)
(assoc-in e [:tweens :fade-in] (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 0.5)) (assoc-in e [:tweens :fade-in] (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 0.5))
(update-in e [:tweens] dissoc :cam-zoom :cam-x :cam-y)
(assoc-in e [:cam :x] 160)
(assoc-in e [:cam :y] 120)
(assoc-in e [:cam :zoom] 1.0)
(if music-changed? (if music-changed?
(assoc-in e [:tweens :fade-in-music] (utils/tween :fade-in-music screen [:volume :value] 0.0 1.0 0.5)) (assoc-in e [:tweens :fade-in-music] (tween/tween :fade-in-music screen [:volume :value] 0.0 1.0 0.5))
e)) e))
new-music (get-music (get-in entities [:room :music]) (get-in entities [:state :time])) new-music (get-music (get-in entities [:room :music]) (get-in entities [:state :time]))
apply-state (get-in entities [:room :apply-state]) apply-state (get-in entities [:room :apply-state])

View File

@@ -3,6 +3,7 @@
[advent.actions :as actions] [advent.actions :as actions]
[advent.screens.items :as items] [advent.screens.items :as items]
[advent.utils :as utils] [advent.utils :as utils]
[advent.tween :as tween]
[clojure.zip :as zip] [clojure.zip :as zip]
[clojure.set :as set] [clojure.set :as set]
[clojure.string :as str] [clojure.string :as str]
@@ -19,9 +20,9 @@
(sound! (sound "inside-house/disappear.ogg") :play) (sound! (sound "inside-house/disappear.ogg") :play)
(-> entities (-> entities
(assoc-in [:tweens :bloodclot-head-appear] (assoc-in [:tweens :bloodclot-head-appear]
(utils/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 0.0 1.0 1.0 :power 4.0)) (tween/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 0.0 1.0 1.0 :ease tween/ease-in-quadratic))
(assoc-in [:tweens :bloodclot-appear] (assoc-in [:tweens :bloodclot-appear]
(utils/tween :bloodclot-appear screen [:room :entities :bloodclot :opacity] 0.0 1.0 1.0 :power 4.0)))) (tween/tween :bloodclot-appear screen [:room :entities :bloodclot :opacity] 0.0 1.0 1.0 :ease tween/ease-in-quadratic))))
(continue [this screen entities] (continue [this screen entities]
entities) entities)

View File

@@ -4,6 +4,7 @@
[advent.actions :as actions] [advent.actions :as actions]
[advent.screens.items :as items] [advent.screens.items :as items]
[advent.utils :as utils] [advent.utils :as utils]
[advent.tween :as tween]
[clojure.zip :as zip] [clojure.zip :as zip]
[clojure.set :as set] [clojure.set :as set]
[clojure.string :as str] [clojure.string :as str]
@@ -16,7 +17,8 @@
(defn taunt [screen entities] (defn taunt [screen entities]
(when (and (not (get-in entities [:actions :script-running?])) (when (and (not (get-in entities [:actions :script-running?]))
(get-in entities [:state :active?]) (get-in entities [:state :active?])
(not (get-in entities [:state :blergh-dead?]))) (not (get-in entities [:state :blergh-dead?]))
(not (actions/has-item? entities :magic-slingshot)))
((actions/get-script entities (actions/do-dialogue entities :bloodclot-head (rand-nth ["Come on, little man! Try and hit me!" ((actions/get-script entities (actions/do-dialogue entities :bloodclot-head (rand-nth ["Come on, little man! Try and hit me!"
"What's the matter? Cold feet?" "What's the matter? Cold feet?"
"Come here and fight me like man!" "Come here and fight me like man!"
@@ -24,6 +26,18 @@
"Pick up your weapon and fight!"]))) entities)) "Pick up your weapon and fight!"]))) entities))
nil) nil)
(defn shock [screen entities]
(when (and (not (get-in entities [:actions :script-running?]))
(get-in entities [:state :active?])
(not (get-in entities [:state :blergh-dead?]))
(actions/has-item? entities :magic-slingshot))
((actions/get-script entities
(sound! (sound "space/shock.ogg") :play)
(actions/play-animation entities :bloodclot-head :shoot :stop? false)
(actions/begin-animation entities :bloodclot-head :keep-shoot)
(actions/do-dialogue entities :bloodclot-head "Dang! Come a little closer!"))
entities))
nil)
(defn start-swing-if-necessary [screen e] (defn start-swing-if-necessary [screen e]
(if (and (not= (:anim e) :swing) (if (and (not= (:anim e) :swing)
@@ -34,7 +48,7 @@
(defn start-fade-if-necessary [e screen] (defn start-fade-if-necessary [e screen]
(if (and (nil? (get-in e [:tweens :flash])) (if (and (nil? (get-in e [:tweens :flash]))
(< (get-in e [:room :entities :ego :y]) 100)) (< (get-in e [:room :entities :ego :y]) 100))
(assoc-in e [:tweens :flash] (utils/tween :flash screen [:white-fade :opacity] 0.0 1.0 0.5 :power 3.0)) (assoc-in e [:tweens :flash] (tween/tween :flash screen [:white-fade :opacity] 0.0 1.0 0.5 :ease tween/ease-in-cubic))
e)) e))
(defn bloodclot-disappear [entities] (defn bloodclot-disappear [entities]
@@ -45,9 +59,9 @@
(sound! (sound "inside-house/disappear.ogg") :play) (sound! (sound "inside-house/disappear.ogg") :play)
(-> entities (-> entities
(assoc-in [:tweens :bloodclot-head-appear] (assoc-in [:tweens :bloodclot-head-appear]
(utils/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 1.0 0.0 1.0 :power 4.0)) (tween/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 1.0 0.0 1.0 :ease tween/ease-in-cubic))
(assoc-in [:tweens :bloodclot-appear] (assoc-in [:tweens :bloodclot-appear]
(utils/tween :bloodclot-appear screen [:room :entities :bloodclot :opacity] 1.0 0.0 1.0 :power 4.0)))) (tween/tween :bloodclot-appear screen [:room :entities :bloodclot :opacity] 1.0 0.0 1.0 :ease tween/ease-in-cubic))))
(continue [this screen entities] (continue [this screen entities]
entities) entities)
@@ -82,25 +96,25 @@
:scale-y 0.5 :scale-y 0.5
:opacity 0.5 :opacity 0.5
:baseline 240)) :baseline 240))
(assoc-in [:tweens :cloud-up] (utils/tween :cloud-up screen [:room :entities :cloud :y] (assoc-in [:tweens :cloud-up] (tween/tween :cloud-up screen [:room :entities :cloud :y]
(get-in entities [:room :entities :ego :y]) (get-in entities [:room :entities :ego :y])
(+ (get-in entities [:room :entities :ego :y]) 20) (+ (get-in entities [:room :entities :ego :y]) 20)
1.0)) 1.0))
(assoc-in [:tweens :cloud-fade] (utils/tween :cloud-fade screen [:room :entities :cloud :opacity] (assoc-in [:tweens :cloud-fade] (tween/tween :cloud-fade screen [:room :entities :cloud :opacity]
0.5 0.5
0.0 0.0
1.0)) 1.0))
(assoc-in [:tweens :cloud-grow] (utils/tween :cloud-grow screen [:room :entities :cloud :scale-y] (assoc-in [:tweens :cloud-grow] (tween/tween :cloud-grow screen [:room :entities :cloud :scale-y]
0.5 0.5
2.5 2.5
1.0)) 1.0))
(assoc-in [:tweens :cloud-grow-2] (utils/tween :cloud-grow-2 screen [:room :entities :cloud :scale-x] (assoc-in [:tweens :cloud-grow-2] (tween/tween :cloud-grow-2 screen [:room :entities :cloud :scale-x]
0.5 0.5
2.5 2.5
1.0)) 1.0))
(update-in [:room :entities :ego] (update-in [:room :entities :ego]
#(actions/start-animation screen % :jump)) #(actions/start-animation screen % :jump))
(assoc-in [:tweens :jump-pos] (utils/tween :jump-pos screen [:room :entities :ego :move-pct] 0.0 1.0 jump-duration :power 2)))) (assoc-in [:tweens :jump-pos] (tween/tween :jump-pos screen [:room :entities :ego :move-pct] 0.0 1.0 jump-duration :ease tween/ease-in-quadratic))))
(continue [this screen entities] (continue [this screen entities]
(let [v (vector-2 0 0) (let [v (vector-2 0 0)
@@ -122,7 +136,7 @@
(-> entities (-> entities
(update-in [:room :entities :ego] (update-in [:room :entities :ego]
#(actions/start-animation screen % :swing)) #(actions/start-animation screen % :swing))
(assoc-in [:tweens :swing-pos] (utils/tween :swing-pos screen [:room :entities :ego :move-pct] 0.0 1.0 swing-duration :power 10)))) (assoc-in [:tweens :swing-pos] (tween/tween :swing-pos screen [:room :entities :ego :move-pct] 0.0 1.0 swing-duration :ease tween/ease-in-dectic))))
(continue [this screen entities] (continue [this screen entities]
(let [v (vector-2 0 0) (let [v (vector-2 0 0)
@@ -143,7 +157,7 @@
false)) false))
(actions/run-action entities (actions/run-action entities
(begin [this screen entities] (begin [this screen entities]
(assoc-in entities [:tweens :flash] (utils/tween :flash screen [:white-fade :opacity] 1.0 0.0 3.0 :power 2.0))) (assoc-in entities [:tweens :flash] (tween/tween :flash screen [:white-fade :opacity] 1.0 0.0 3.0 :ease tween/ease-in-quadratic)))
(continue [this screen entities] (continue [this screen entities]
entities) entities)
@@ -172,7 +186,8 @@
:interactions :interactions
{} {}
:layers [(assoc (texture "space/background.png") :x 0 :y 0 :baseline 0)] :layers [(assoc (texture "space/background.png") :x 0 :y 0 :baseline 0)]
:timers {:taunt [10.0 8.0 taunt]} :timers {:taunt [10.0 8.0 taunt]
:shock [5.0 1.0 shock]}
:entities {:appear (assoc effect :entities {:appear (assoc effect
:x 240 :y 50 :x 240 :y 50
:baseline 200) :baseline 200)

View File

@@ -12,6 +12,7 @@
[advent.actions :as actions] [advent.actions :as actions]
[advent.zone :as zone] [advent.zone :as zone]
[advent.utils :as utils] [advent.utils :as utils]
[advent.tween :as tween]
[advent.screens.rooms :as rooms] [advent.screens.rooms :as rooms]
[advent.screens.rooms.common :as common] [advent.screens.rooms.common :as common]
[advent.screens.items :as items] [advent.screens.items :as items]
@@ -33,7 +34,7 @@
[advent.screens.inventory :refer [inventory-screen]] [advent.screens.inventory :refer [inventory-screen]]
[clojure.core.async :refer [put! <! <!! >! chan go thread take! alts!!]]) [clojure.core.async :refer [put! <! <!! >! chan go thread take! alts!!]])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter GL20 GL30] (:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter GL20 GL30]
[com.badlogic.gdx.graphics.g2d TextureRegion] [com.badlogic.gdx.graphics.g2d TextureRegion Animation]
[java.lang Object] [java.lang Object]
[com.badlogic.gdx Gdx])) [com.badlogic.gdx Gdx]))
@@ -65,7 +66,7 @@
((:mouse-in? (:inventory entities)) x y) ((:mouse-in? (:inventory entities)) x y)
(click-inventory screen entities) (click-inventory screen entities)
(utils/intersects? (:close entities) [x y]) (utils/intersects? (:close entities) [x y])
(assoc-in entities [:tweens :fade-out] (utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 :finish #(do (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen)) (assoc-in entities [:tweens :fade-out] (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 :finish #(do (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen))
%))) %)))
:else :else
@@ -341,7 +342,7 @@
(defn get-animation-point [animation total-time] (defn get-animation-point [^Animation animation total-time]
(loop [time total-time] (loop [time total-time]
(if (> (- time (animation! animation :get-animation-duration)) 0) (if (> (- time (animation! animation :get-animation-duration)) 0)
(recur (- time (animation! animation :get-animation-duration))) (recur (- time (animation! animation :get-animation-duration)))
@@ -391,7 +392,9 @@
:on-show :on-show
(fn [screen entities] (fn [screen entities]
(let [screen (assoc screen :total-time 0)] (let [screen (assoc screen :total-time 0)]
(update! screen :renderer (stage) :camera (orthographic)) (let [cam (orthographic)]
(set! (. cam zoom) 0.95)
(update! screen :renderer (stage) :camera cam)
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0) (let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
rooms {:inside-house (rooms.inside-house/make screen) rooms {:inside-house (rooms.inside-house/make screen)
:inside-stash (rooms.inside-stash/make screen) :inside-stash (rooms.inside-stash/make screen)
@@ -408,6 +411,8 @@
:outside-jail (rooms.outside-jail/make screen) :outside-jail (rooms.outside-jail/make screen)
:outside-castle (rooms.outside-castle/make screen)} :outside-castle (rooms.outside-castle/make screen)}
entities {:rooms rooms entities {:rooms rooms
:cam {:value cam
:object nil}
:musics {:object nil :musics {:object nil
:inside-antique (utils/make-music "inside-antique.ogg") :inside-antique (utils/make-music "inside-antique.ogg")
:town-1 (utils/make-music "town-music-1.ogg") :town-1 (utils/make-music "town-music-1.ogg")
@@ -443,8 +448,8 @@
:last :main :last :main
:override nil :override nil
:last-pos [0 0]} :last-pos [0 0]}
:tweens {:fade-in (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.5 :power 3.0) :tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.5 :ease tween/ease-in-cubic)
:fade-in-music (utils/tween :fade-in-music screen [:volume :value] 0.0 1.0 1.5 :power 3.0)} :fade-in-music (tween/tween :fade-in-music screen [:volume :value] 0.0 1.0 1.5 :ease tween/ease-in-cubic)}
:all-items (assoc items/items :object nil) :all-items (assoc items/items :object nil)
:room (as-> (get rooms (:last-room (get-state))) room :room (as-> (get rooms (:last-room (get-state))) room
(assoc-in room [:entities :ego] (get-ego screen (:start-pos room) ((:scale-fn room) (:start-pos room))))) (assoc-in room [:entities :ego] (get-ego screen (:start-pos room) ((:scale-fn room) (:start-pos room)))))
@@ -461,7 +466,7 @@
((actions/get-script entities (rooms.dream/do-intro entities)) entities)) ((actions/get-script entities (rooms.dream/do-intro entities)) entities))
(if-let [apply-state (get-in entities [:room :apply-state])] (if-let [apply-state (get-in entities [:room :apply-state])]
(apply-state entities) (apply-state entities)
entities)))) entities)))))
:on-render :on-render
(fn [screen [entities]] (fn [screen [entities]]
@@ -487,15 +492,19 @@
layers (get-layers entities) layers (get-layers entities)
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))] all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]
(set! (. (:value (:cam entities)) zoom) (:zoom (:cam entities) 1.0))
(set! (.. (:value (:cam entities)) position x) (:x (:cam entities) 160.0))
(set! (.. (:value (:cam entities)) position y) (:y (:cam entities) 120.0))
(play-key-sounds (get-in entities [:room :entities])) (play-key-sounds (get-in entities [:room :entities]))
(doseq [m (vals (get-in entities [:musics]))] (doseq [m (vals (get-in entities [:musics]))]
(when m (when m
(music! m :set-volume (get-in entities [:volume :value]) ))) (music! m :set-volume (get-in entities [:volume :value]))))
(label! (:fps entities) :set-text (str (game :fps))) (label! (:fps entities) :set-text (str (game :fps)))
(render! screen (sort-by :baseline all-entities)) (render! screen (sort-by :baseline all-entities))
#_(render! screen [(:fps entities)]) (render! screen [(:fps entities)])
entities)) entities))
:on-resize (fn [screen entities] :on-resize (fn [screen entities]

View File

@@ -4,6 +4,7 @@
[play-clj.utils :refer :all] [play-clj.utils :refer :all]
[play-clj.g2d :refer :all] [play-clj.g2d :refer :all]
[advent.utils :as utils] [advent.utils :as utils]
[advent.tween :as tween]
[advent.screens.scene :as scene] [advent.screens.scene :as scene]
[advent.screens.dialogue :as dialogue] [advent.screens.dialogue :as dialogue]
[advent.screens.title :as title] [advent.screens.title :as title]
@@ -52,9 +53,9 @@
:start-showing? false :start-showing? false
:start-playing start-playing :start-playing start-playing
:quit quit :quit quit
:tweens {:fade-in (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0 :tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
:finish #(do (utils/play-sound (:music %)) %) :finish #(do (utils/play-sound (:music %)) %)
:power 10.0)} :ease tween/ease-in-quadratic)}
})) }))
:on-render :on-render
@@ -79,22 +80,22 @@
(utils/intersects? (:start-playing entities) [x y]) (utils/intersects? (:start-playing entities) [x y])
(-> entities (-> entities
(assoc-in [:tweens :fade-out] (assoc-in [:tweens :fade-out]
(utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 2.0 (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0
:finish (fn [entities] :finish (fn [entities]
(utils/stop-sound (:music entities)) (utils/stop-sound (:music entities))
(set-screen! @(resolve 'advent.core/advent) scene/scene dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen safe/safe-screen) (set-screen! @(resolve 'advent.core/advent) scene/scene dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen safe/safe-screen)
entities) entities)
:power 3.0)) :ease tween/ease-in-cubic))
(assoc-in [:tweens :fade-out-music] (assoc-in [:tweens :fade-out-music]
(utils/tween :fade-out-music screen [:volume] 1.0 0.0 1.8))) (tween/tween :fade-out-music screen [:volume] 1.0 0.0 1.8)))
(utils/intersects? (:quit entities) [x y]) (utils/intersects? (:quit entities) [x y])
(-> entities (-> entities
(assoc-in [:tweens :fade-out] (assoc-in [:tweens :fade-out]
(utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 2.0 (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0
:finish (fn [entities] :finish (fn [entities]
(System/exit 0) (System/exit 0)
entities) entities)
:power 3.0))) :ease tween/ease-in-cubic)))
:else :else
nil))) nil)))

View File

@@ -125,20 +125,7 @@
(defn make-music [r] (defn make-music [r]
(doto (music r) (music! :set-looping true))) (doto (music r) (music! :set-looping true)))
(defn tween [id screen path start end duration & {:keys [finish power]}]
(let [power (or power 1.0)
finish (or finish identity)
start-time (or (:total-time screen) 0.0)
delta (- end start)]
(fn [e total-time]
(let [delta-time (- total-time start-time)
pct-done (min (/ delta-time duration) 1.0)
pct-done (Math/pow pct-done power)
e (assoc-in e path (+ start (* pct-done delta)))]
(if (= 1.0 pct-done)
(update-in (finish e) [:tweens] dissoc id)
e)
))))
(defn apply-tweens [screen entities tweens] (defn apply-tweens [screen entities tweens]
(reduce (fn [e f] (reduce (fn [e f]