diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 665f91ee..6a083e8b 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -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]))) diff --git a/desktop/src-common/advent/screens/rooms/outside_castle.clj b/desktop/src-common/advent/screens/rooms/outside_castle.clj index cd5f83ce..a66af65e 100644 --- a/desktop/src-common/advent/screens/rooms/outside_castle.clj +++ b/desktop/src-common/advent/screens/rooms/outside_castle.clj @@ -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 diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index da61f7d7..b899da40 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -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])))]