From d639efe10e4f778d49da4cf462f16be861d7404a Mon Sep 17 00:00:00 2001 From: Remington Covert Date: Tue, 21 Oct 2014 20:02:52 -0700 Subject: [PATCH] made a squatting animation --- desktop/src-common/advent/actions.clj | 28 ++++++++++++++++--- .../advent/screens/rooms/behind_house.clj | 1 + .../advent/screens/rooms/outside_castle.clj | 4 ++- desktop/src-common/advent/screens/scene.clj | 19 +++++++++++-- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 04431040..47741222 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -41,11 +41,14 @@ (assoc entity :scale-x (scale-fn [x y]) :scale-y (scale-fn [x y])) entity))) +(defn find-animation [entity anim] + (if (keyword? anim) + (or (get-in entity [(:facing entity) anim]) + (anim entity)) + anim)) + (defn start-animation [screen entity anim] - (let [new-anim (if (keyword? anim) - (or (get-in entity [(:facing entity) anim]) - (anim entity)) - anim)] + (let [new-anim (find-animation entity anim)] (if (and anim (not= new-anim (:anim entity))) (assoc entity :anim new-anim @@ -107,6 +110,23 @@ (can-skip? [this screen entities] false)))) +(defn play-animation [entities target-id anim] + (run-action entities + (begin [this screen entities] + (update-in entities [:room :entities target-id] #(start-animation screen % anim) )) + + (continue [this screen entities] entities) + + (done? [this screen entities] + (animation! (find-animation (get-in entities [:room :entities target-id ]) anim) + :is-animation-finished + (- (:total-time screen) (get-in entities [:room :entities target-id :anim-start])))) + + (terminate [this screen entities] + (stop screen entities target-id)) + (can-skip? [this screen entities] + false))) + (defn walk-to [entities target-id [final-x final-y] & [can-skip?]] (let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id]) final-x (int final-x) diff --git a/desktop/src-common/advent/screens/rooms/behind_house.clj b/desktop/src-common/advent/screens/rooms/behind_house.clj index cea0c0af..0fbbcc76 100644 --- a/desktop/src-common/advent/screens/rooms/behind_house.clj +++ b/desktop/src-common/advent/screens/rooms/behind_house.clj @@ -33,6 +33,7 @@ (actions/talk entities :ego "I've already got a junk ton of mushrooms.") (do (actions/walk-to entities :ego [242 75]) + (actions/play-animation entities :ego :squat) (actions/give entities items/mushrooms) (actions/talk entities :ego "Perfectly ripe mushrooms!"))))} :window {:box [103 44 130 140] diff --git a/desktop/src-common/advent/screens/rooms/outside_castle.clj b/desktop/src-common/advent/screens/rooms/outside_castle.clj index 559e10e6..db346d97 100644 --- a/desktop/src-common/advent/screens/rooms/outside_castle.clj +++ b/desktop/src-common/advent/screens/rooms/outside_castle.clj @@ -36,7 +36,9 @@ (actions/talk entities :ego "If I steal any more, I might get caught.") (do (actions/walk-to entities :ego [128 180]) - (actions/talk entities :ego "Hey! Carrots. No one will notice one missing.") + (actions/talk entities :ego "Hey! Carrots.") + (actions/play-animation entities :ego :squat) + (actions/talk entities :ego "No one will notice one missing.") (actions/give entities items/carrot))))} :peddler {:box [110 90 128 146] :script (actions/get-script diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 18d780f9..fa1d83c5 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -47,7 +47,6 @@ (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})] (if ((:mouse-in? (:inventory entities)) x y) (open-inventory screen entities) - (let [interaction (first (filter #((:mouse-in? %) entities x y) (get-in entities [:room :interactions]))) interacting-entity (first (filter #(and (:mouse-in? %) @@ -79,24 +78,38 @@ (let [player-sheet (texture! (texture "player.png") :split 18 36) talk-sheet (texture! (texture "ego/talk.png") :split 18 36) stand-sheet (texture! (texture "ego/stand.png") :split 18 36) + squat-sheet (texture! (texture "ego/squat.png") :split 18 36) walk-right (animation 0.075 (for [i (range 8)] (texture (aget player-sheet 0 i)))) stand-anim (animation 0.1 (for [i (flatten [(repeat 6 [(repeat 10 0) (repeat 3 1) (repeat 20 0)]) 3 4 5 5 5 6 5 6 5 6 5 4 3 ])] (texture (aget stand-sheet 0 i)))) talk-anim (animation 0.2 (for [i (range 8)] (texture (aget talk-sheet 0 i)))) + squat-anim (animation 0.05 (for [i [0 1 2 3 3 3 3 3 3 3 3 3 3 3 3 2 1] ] + (texture (aget squat-sheet 0 i)))) ego {:right {:walk walk-right :stand stand-anim - :talk talk-anim} + :talk talk-anim + :squat squat-anim} :left {:walk (utils/flip walk-right) :stand (utils/flip stand-anim) - :talk (utils/flip talk-anim)} + :talk (utils/flip talk-anim) + :squat (utils/flip squat-anim)} :baseline 95 :facing :right :origin-x 9 :origin-y 0 :scaled true + :mouse-in? (fn [entities x y] + (let [{entity-x :x entity-y :y region :object} (get-in entities [:room :entities :ego]) + width (.getRegionWidth region) + height (.getRegionHeight region)] + + ((zone/box entity-x entity-y (+ entity-x width) (+ entity-y height)) x y))) + :get-script (fn [cursor [x y]] + (case cursor + items/flask-with-cream-of-mushroom (actions/get-script entities (actions/talk entities :ego "Yuck. I filled it with backwash.")))) :x 150 :y 95 :id "ego"}] (actions/start-animation screen