this makes the game feel good.

This commit is contained in:
2015-02-19 12:33:09 -08:00
parent c6dc550e1f
commit 163f5b9376
2 changed files with 44 additions and 25 deletions

View File

@@ -86,8 +86,10 @@
~@forms ~@forms
(change-script-state ~entities false))))) (change-script-state ~entities false)))))
(defn pan-to [screen entities x y scale-fn] (defn pan-to [screen entities x y scale-fn & [ease duration]]
(let [target-zoom (min 1.0 (max 0.85 (scale-fn [x y]))) (let [ease (or ease tween/ease-in-out-quadratic)
duration (or duration 3.0)
target-zoom (min 0.95 (max 0.75 (scale-fn [x y])))
current-zoom (get-in entities [:cam :zoom] 1.0) current-zoom (get-in entities [:cam :zoom] 1.0)
;; don't zoom if it's a subtle difference ;; don't zoom if it's a subtle difference
@@ -101,28 +103,32 @@
target-y (min (- 240 (* 120.0 target-zoom)) target-y (min (- 240 (* 120.0 target-zoom))
(max (* 120.0 target-zoom) (max (* 120.0 target-zoom)
y))] y))]
(-> entities (if (or (not= target-x (get-in entities [:cam :x]))
(assoc-in [:tweens :cam-zoom] (not= target-y (get-in entities [:cam :y]))
(tween/tween :cam-zoom screen (not= target-zoom (get-in entities [:cam :zoom])))
[:cam :zoom] (-> entities
(get-in entities [:cam :zoom] 1.0) (assoc-in [:tweens :cam-zoom]
target-zoom (tween/tween :cam-zoom screen
3.0 [:cam :zoom]
:ease tween/ease-in-out-quadratic)) (get-in entities [:cam :zoom] 1.0)
(assoc-in [:tweens :cam-x] target-zoom
(tween/tween :cam-x screen duration
[:cam :x] :ease ease))
(get-in entities [:cam :x] 160.0) (assoc-in [:tweens :cam-x]
target-x (tween/tween :cam-x screen
3.0 [:cam :x]
:ease tween/ease-in-out-quadratic)) (get-in entities [:cam :x] 160.0)
(assoc-in [:tweens :cam-y] target-x
(tween/tween :cam-y screen duration
[:cam :y] :ease ease))
(get-in entities [:cam :y] 120.0) (assoc-in [:tweens :cam-y]
target-y (tween/tween :cam-y screen
3.0 [:cam :y]
:ease tween/ease-in-out-quadratic))))) (get-in entities [:cam :y] 120.0)
target-y
duration
:ease ease)))
entities)))
(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)
@@ -587,7 +593,7 @@
(update-in e [:tweens] dissoc :cam-zoom :cam-x :cam-y) (update-in e [:tweens] dissoc :cam-zoom :cam-x :cam-y)
(assoc-in e [:cam :x] 160) (assoc-in e [:cam :x] 160)
(assoc-in e [:cam :y] 120) (assoc-in e [:cam :y] 120)
(assoc-in e [:cam :zoom] 1.0) (assoc-in e [:cam :zoom] 0.95)
(if music-changed? (if music-changed?
(assoc-in e [:tweens :fade-in-music] (tween/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))

View File

@@ -488,6 +488,19 @@
(if (:update-fn entity) (if (:update-fn entity)
[id ((:update-fn entity) screen entities entity)] [id ((:update-fn entity) screen entities entity)]
[id entity]))))) [id entity])))))
entities (if (and (nil? (get-in entities [:tweens :cam-x]))
(= 1 (rand-int 40)))
(actions/pan-to screen entities
(+ (get-in entities [:room :entities :ego :x])
(- (rand-int 20) 10))
(+ (get-in entities [:room :entities :ego :y])
(- (rand-int 20) 10))
(constantly (get-in entities [:room :entities :ego :scale-x]))
tween/ease-in-out-quadratic
5.0)
entities)
layers (get-layers entities) layers (get-layers entities)