animations in all directions.
This commit is contained in:
@@ -36,7 +36,8 @@
|
||||
|
||||
(defn start-animation [screen entity anim]
|
||||
(let [new-anim (if (keyword? anim)
|
||||
(anim entity)
|
||||
(or (get-in entity [(:facing entity) anim])
|
||||
(anim entity))
|
||||
anim)]
|
||||
(if (and anim (not= new-anim (:anim entity)))
|
||||
(assoc entity
|
||||
@@ -96,10 +97,12 @@
|
||||
entities)
|
||||
(update-in entities [:background :entities target-id]
|
||||
#(start-animation screen
|
||||
(jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
|
||||
(cond (< delta-x 0) :left
|
||||
(> delta-x 0) :right
|
||||
:else nil)))))))
|
||||
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
|
||||
:facing (cond (< delta-x 0) :left
|
||||
(> delta-x 0) :right
|
||||
:else (:facing %)))
|
||||
:walk
|
||||
))))))
|
||||
|
||||
(done? [this screen entities]
|
||||
(let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:background :entities target-id])]
|
||||
@@ -110,10 +113,11 @@
|
||||
@entities)))
|
||||
|
||||
(defn get-text-duration [text]
|
||||
(* (count (s/split text #" ")) 0.75))
|
||||
(* (count (s/split text #" ")) 0.5))
|
||||
|
||||
(defn talk [entities target-id text]
|
||||
(let [initial-time (atom nil)]
|
||||
(defn talk [entities target-id text & {:keys [stop?]}]
|
||||
(let [initial-time (atom nil)
|
||||
stop? (if (nil? stop?) true stop?)]
|
||||
(run-action entities
|
||||
(begin [this screen entities]
|
||||
(let [_ (swap! initial-time #(or % (:total-time screen)))
|
||||
@@ -136,7 +140,9 @@
|
||||
|
||||
(terminate [this screen entities]
|
||||
(run! dialogue/talking-screen :stop-talk :target-id target-id)
|
||||
(stop screen entities target-id)))))
|
||||
(if stop?
|
||||
(stop screen entities target-id)
|
||||
entities)))))
|
||||
|
||||
(defn give [entities target-id item]
|
||||
(run-action entities
|
||||
|
||||
@@ -71,14 +71,20 @@
|
||||
stand-sheet (texture! (texture "ego/stand.png") :split 18 36)
|
||||
walk-right (animation 0.075 (for [i (range 8)]
|
||||
(texture (aget player-sheet 0 i))))
|
||||
ego {:right walk-right
|
||||
:left (flip walk-right)
|
||||
:talk (animation 0.2 (for [i (range 8)]
|
||||
(texture (aget talk-sheet 0 i))))
|
||||
:stand (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))))
|
||||
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))))
|
||||
ego {:right {:walk walk-right
|
||||
:stand stand-anim
|
||||
:talk talk-anim}
|
||||
:left {:walk (flip walk-right)
|
||||
:stand (flip stand-anim)
|
||||
:talk (flip talk-anim)}
|
||||
|
||||
|
||||
:baseline 95
|
||||
:facing :right
|
||||
:origin-x 9
|
||||
:origin-y 0
|
||||
:scaled true
|
||||
@@ -86,7 +92,7 @@
|
||||
:x 150 :y 95
|
||||
:id "ego"}]
|
||||
(actions/start-animation screen
|
||||
(merge (animation->texture screen (:stand ego)) ego)
|
||||
(merge (animation->texture screen (:stand (:right ego))) ego)
|
||||
:stand)))
|
||||
|
||||
(defn update-from-script [screen {{:keys [current started? channel]} :actions :as entities}]
|
||||
@@ -200,14 +206,19 @@
|
||||
entities
|
||||
(actions/walk-to entities :ego [191 90])
|
||||
(actions/talk entities :ego "Hello there, peddler.")
|
||||
(actions/talk entities :peddler "Good day sir! Care to see any of my wares?")
|
||||
(actions/talk entities :peddler "Good day sir! Care to see any of my wares?" :stop? false)
|
||||
(actions/talk entities :peddler "I have only the choicest of wares.")
|
||||
(actions/talk entities :ego "What 'wares' are you selling?")
|
||||
(actions/talk entities :peddler "I have all types of wares...")
|
||||
(actions/talk entities :peddler "...I'm well stocked on used earplugs...")
|
||||
(actions/talk entities :peddler "...glass eyes, motivational tapes... ")
|
||||
(actions/talk entities :peddler "...and useful books like this:")
|
||||
(actions/talk entities :peddler "'Checkers Mastery in Less Than 10 Seconds'"))}}
|
||||
(actions/talk entities :peddler "I have the choicest of all types of wares..." :stop? false)
|
||||
(actions/talk entities :peddler "...I'm well stocked on used earplugs..." :stop? false)
|
||||
(actions/talk entities :peddler "...glass eyes, motivational tapes... " :stop? false)
|
||||
(actions/talk entities :peddler "...and useful books like this:" :stop? false)
|
||||
(actions/talk entities :peddler "'Checkers Mastery in Less Than 10 Seconds'")
|
||||
(actions/talk entities :ego "I sure ami interested on that book on checkers.")
|
||||
(actions/talk entities :peddler "An excellent selection! It is the choicest of checkers book you'll ever find." :stop? false)
|
||||
(actions/talk entities :peddler "This book will only set you back 75 sheckels.")
|
||||
(actions/talk entities :ego "But I haven't got any money!")
|
||||
(actions/talk entities :peddler "Then you won't have the choicest of checkers books."))}}
|
||||
:layers [(assoc (texture "outside-castle/background.png") :x 0 :y 0 :baseline 0)]
|
||||
:entities {:peddler (actions/start-animation screen
|
||||
(assoc (texture "outside-castle/peddler.png") :x 110 :y 90 :baseline 150 :anim nil
|
||||
@@ -225,7 +236,7 @@
|
||||
(update! screen :renderer (stage) :camera (orthographic))
|
||||
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
|
||||
music (sound "town-music.mp3")
|
||||
;; _ (sound! music :loop 0.20)
|
||||
_ (sound! music :loop 0.20)
|
||||
backgrounds (backgrounds screen)]
|
||||
{:backgrounds backgrounds
|
||||
:actions {:object nil
|
||||
|
||||
Reference in New Issue
Block a user