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
(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]]
(let [ease (or ease tween/ease-in-out-quadratic)
duration (or duration 3.0)
@@ -97,12 +102,8 @@
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))]
target-x (bound-to-camera x 320 target-zoom)
target-y (bound-to-camera y 240 target-zoom)]
(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])))

View File

@@ -290,8 +290,7 @@
(actions/play-animation entities :ego :squat)
(actions/talk entities :ego "No one will notice one missing.")
(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)]
:sunrise [(assoc (texture "outside-castle/background-sunrise.png") :x 0 :y 0 :baseline 0)]}
:entities {:peddler (actions/start-animation screen

View File

@@ -469,6 +469,26 @@
(.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
:on-timer
(fn [screen [entities]]
@@ -576,18 +596,25 @@
[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)
(= 1 (rand-int 20)))
(if (= (rand-int 2) 1)
(actions/pan-to screen entities
(get-in entities [:room :entities :ego :x])
(get-in entities [:room :entities :ego :y])
(constantly (get-in entities [:room :entities :ego :scale-x]))
tween/ease-in-out-quadratic
5.0)
(actions/pan-to screen entities
(+ (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)
layers (get-layers entities)
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]