made a squatting animation

This commit is contained in:
2014-10-21 20:02:52 -07:00
parent 6c1e7bfafd
commit d639efe10e
4 changed files with 44 additions and 8 deletions

View File

@@ -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)

View File

@@ -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]

View File

@@ -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

View File

@@ -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