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.screens.dialogue :as dialogue]
[advent.utils :as utils]
[advent.tween :as tween]
[advent.tween :as tween]
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion Animation]
@@ -84,6 +86,43 @@
~@forms
(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?]
(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))))
(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])
final-x (int final-x)
@@ -123,7 +164,9 @@
update-baseline? (if (nil? update-baseline?) true update-baseline?)]
(run-action 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]
(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)
(run-action 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]
(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)]
(run-action 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]
entities)
@@ -507,9 +553,9 @@
(doseq [[k] (get-in entities [:room :timers])]
(remove-timer! screen k))
(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?
(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)
(assoc-in e [:cursor :current] :main)))
@@ -537,9 +583,13 @@
(assoc-in e [:room] (get-in entities [:rooms new-background]))
(assoc-in e [:room :entities :ego] ego)
(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?
(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))
new-music (get-music (get-in entities [:room :music]) (get-in entities [:state :time]))
apply-state (get-in entities [:room :apply-state])