this makes the game feel good.
This commit is contained in:
@@ -86,8 +86,10 @@
|
||||
~@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])))
|
||||
(defn pan-to [screen entities x y scale-fn & [ease duration]]
|
||||
(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)
|
||||
|
||||
;; don't zoom if it's a subtle difference
|
||||
@@ -101,28 +103,32 @@
|
||||
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)))))
|
||||
(if (or (not= target-x (get-in entities [:cam :x]))
|
||||
(not= target-y (get-in entities [:cam :y]))
|
||||
(not= target-zoom (get-in entities [:cam :zoom])))
|
||||
(-> entities
|
||||
(assoc-in [:tweens :cam-zoom]
|
||||
(tween/tween :cam-zoom screen
|
||||
[:cam :zoom]
|
||||
(get-in entities [:cam :zoom] 1.0)
|
||||
target-zoom
|
||||
duration
|
||||
:ease ease))
|
||||
(assoc-in [:tweens :cam-x]
|
||||
(tween/tween :cam-x screen
|
||||
[:cam :x]
|
||||
(get-in entities [:cam :x] 160.0)
|
||||
target-x
|
||||
duration
|
||||
:ease ease))
|
||||
(assoc-in [:tweens :cam-y]
|
||||
(tween/tween :cam-y screen
|
||||
[:cam :y]
|
||||
(get-in entities [:cam :y] 120.0)
|
||||
target-y
|
||||
duration
|
||||
:ease ease)))
|
||||
entities)))
|
||||
|
||||
(defn jump-to [screen entities entity [x y] update-baseline?]
|
||||
(let [scale-fn (-> entities :room :scale-fn)
|
||||
@@ -587,7 +593,7 @@
|
||||
(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)
|
||||
(assoc-in e [:cam :zoom] 0.95)
|
||||
(if music-changed?
|
||||
(assoc-in e [:tweens :fade-in-music] (tween/tween :fade-in-music screen [:volume :value] 0.0 1.0 0.5))
|
||||
e))
|
||||
|
||||
@@ -488,6 +488,19 @@
|
||||
(if (:update-fn entity)
|
||||
[id ((:update-fn entity) screen entities 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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user