better idle

This commit is contained in:
2015-03-03 06:59:38 -08:00
parent de27f437b9
commit 76db582221
3 changed files with 45 additions and 18 deletions

View File

@@ -86,6 +86,11 @@
~@forms ~@forms
(change-script-state ~entities false))))) (change-script-state ~entities false)))))
(defn bound-to-camera [x length zoom]
(min (- length (* length 0.5 zoom ))
(max (* length 0.5 zoom )
x)))
(defn pan-to [screen entities x y scale-fn & [ease duration]] (defn pan-to [screen entities x y scale-fn & [ease duration]]
(let [ease (or ease tween/ease-in-out-quadratic) (let [ease (or ease tween/ease-in-out-quadratic)
duration (or duration 3.0) duration (or duration 3.0)
@@ -97,12 +102,8 @@
0.07) 0.07)
current-zoom current-zoom
target-zoom) target-zoom)
target-x (min (- 320 (* 160.0 target-zoom )) target-x (bound-to-camera x 320 target-zoom)
(max (* 160.0 target-zoom ) target-y (bound-to-camera y 240 target-zoom)]
x))
target-y (min (- 240 (* 120.0 target-zoom ))
(max (* 120.0 target-zoom )
y))]
(if (or (not= target-x (get-in entities [:cam :x])) (if (or (not= target-x (get-in entities [:cam :x]))
(not= target-y (get-in entities [:cam :y])) (not= target-y (get-in entities [:cam :y]))
(not= target-zoom (get-in entities [:cam :zoom]))) (not= target-zoom (get-in entities [:cam :zoom])))

View File

@@ -290,8 +290,7 @@
(actions/play-animation entities :ego :squat) (actions/play-animation entities :ego :squat)
(actions/talk entities :ego "No one will notice one missing.") (actions/talk entities :ego "No one will notice one missing.")
(actions/give entities :carrot))))}} (actions/give entities :carrot))))}}
:layers {:day [(assoc (texture "outside-castle/background.png") :x 0 :y 0 :baseline 0) :layers {:day [(assoc (texture "outside-castle/background.png") :x 0 :y 0 :baseline 0)]
]
:night [(assoc (texture "outside-castle/background-dark.png") :x 0 :y 0 :baseline 0)] :night [(assoc (texture "outside-castle/background-dark.png") :x 0 :y 0 :baseline 0)]
:sunrise [(assoc (texture "outside-castle/background-sunrise.png") :x 0 :y 0 :baseline 0)]} :sunrise [(assoc (texture "outside-castle/background-sunrise.png") :x 0 :y 0 :baseline 0)]}
:entities {:peddler (actions/start-animation screen :entities {:peddler (actions/start-animation screen

View File

@@ -469,6 +469,26 @@
(.end batch)))) (.end batch))))
(defn shift-range-to-bounds [x1 x2 min max]
(println x1 x2 "->" (cond (and (< x1 min)
(> x2 max))
[min max]
(< x1 min)
[min (+ x2 (- min x1))]
(> x2 max)
[(- x1 (- x2 max)) max]
:else
[x1 x2]))
(cond (and (< x1 min)
(> x2 max))
[min max]
(< x1 min)
[min (+ x2 (- min x1))]
(> x2 max)
[(- x1 (- x2 max)) max]
:else
[x1 x2]))
(defscreen scene (defscreen scene
:on-timer :on-timer
(fn [screen [entities]] (fn [screen [entities]]
@@ -576,18 +596,25 @@
[id entity]))))) [id entity])))))
entities (if (and (nil? (get-in entities [:tweens :cam-x])) entities (if (and (nil? (get-in entities [:tweens :cam-x]))
(= 1 (rand-int 40))) (= 1 (rand-int 20)))
(actions/pan-to screen entities (if (= (rand-int 2) 1)
(+ (get-in entities [:room :entities :ego :x]) (actions/pan-to screen entities
(- (rand-int 20) 10)) (get-in entities [:room :entities :ego :x])
(+ (get-in entities [:room :entities :ego :y]) (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
(constantly (get-in entities [:room :entities :ego :scale-x])) 5.0)
tween/ease-in-out-quadratic (actions/pan-to screen entities
5.0) (+ (get-in entities [:cam :x] 0)
(- 10 (rand-int 20)))
(+ (get-in entities [:cam :y] 0)
(- 10 (rand-int 20)))
(constantly (get-in entities [:room :entities :ego :scale-x]))
tween/ease-in-out-quadratic
5.0))
entities) entities)
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])))]