making it so you can have other entities only on one screen (i.e., sheep)

This commit is contained in:
2014-09-16 16:56:36 -07:00
parent 153bd33824
commit 68317528a9

View File

@@ -114,72 +114,79 @@
(merge params {:collision (advent.pathfind/map-from-resource collision) (merge params {:collision (advent.pathfind/map-from-resource collision)
:interactions interactions-as-list}))) :interactions interactions-as-list})))
(defn backgrounds [] (defn backgrounds [screen]
{:outside-house (make-background :interactions (let [sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
{:door {:box [258 100 281 160] sheep (animation 0.15 (for [i (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 9 10 (repeat 25 11) (repeat 15 12)])]
:script (actions/get-script (aget sheep-sheet 0 i)))]
entities {:outside-house
(actions/walk-to entities :ego [262 88]) (make-background :interactions
(actions/talk entities :ego (str "Anyone home?")))} {:door {:box [258 100 281 160]
:sword {:box [274 55 305 88] :script (actions/get-script
:script (actions/get-script entities
entities (actions/walk-to entities :ego [262 88])
(actions/talk entities :ego (str "It's the coolest sword I've ever seen!")) (actions/talk entities :ego (str "Anyone home?")))}
(actions/walk-to entities :ego [290 66]) :sword {:box [274 55 305 88]
(actions/talk entities :ego "Maybe I can pull it out."))} :script (actions/get-script
:sheep {:box [38 160 71 181] entities
:script (actions/get-script (actions/talk entities :ego (str "It's the coolest sword I've ever seen!"))
entities (actions/walk-to entities :ego [290 66])
(if ((get-in @entities [:ego :inventory]) :wool) (actions/talk entities :ego "Maybe I can pull it out."))}
(actions/talk entities :ego "The sheep has given me enough wool.") :sheep {:box [38 160 71 181]
(do (actions/give entities :ego :wool) :script (actions/get-script
(actions/talk entities :ego "I guess his wool is shedding."))))} entities
:right-dir {:box [300 131 320 224] (if ((get-in @entities [:ego :inventory]) :wool)
:script (actions/get-script (actions/talk entities :ego "The sheep has given me enough wool.")
entities (do (actions/give entities :ego :wool)
(actions/walk-to entities :ego [319 160])) (actions/talk entities :ego "I guess his wool is shedding."))))}
:cursor :right} :right-dir {:box [300 131 320 224]
:up-dir {:box [60 180 224 240] :script (actions/get-script
:script (actions/get-script entities
entities (actions/walk-to entities :ego [319 160]))
(actions/walk-to entities :ego [137 204])) :cursor :right}
:cursor :up} :up-dir {:box [60 180 224 240]
:left-dir {:box [0 40 20 140] :script (actions/get-script
:script (actions/get-script entities
entities (actions/walk-to entities :ego [137 204]))
(actions/walk-to entities :ego [0 80]) :cursor :up}
(actions/transition-background entities :behind-house [310 80])) :left-dir {:box [0 40 20 140]
:cursor :left}} :script (actions/get-script
:layers [(assoc (texture "bg5.png") :x 0 :y 0 :baseline 0) entities
(assoc (texture "house.png") :x 0 :y 0 :baseline 122) (actions/walk-to entities :ego [0 80])
(assoc (texture "overdirt.png") :x 0 :y 0 :baseline 240) (actions/transition-background entities :behind-house [310 80]))
(assoc (texture "background-trees.png") :x 0 :y 0 :baseline 44)] :cursor :left}}
:collision "outsidehouse/collision.png" :layers [(assoc (texture "bg5.png") :x 0 :y 0 :baseline 0)
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00)) (assoc (texture "house.png") :x 0 :y 0 :baseline 122)
(assoc (texture "overdirt.png") :x 0 :y 0 :baseline 240)
(assoc (texture "background-trees.png") :x 0 :y 0 :baseline 44)]
:entities [(assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep)]
:collision "outsidehouse/collision.png"
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))
:behind-house (make-background :interactions :behind-house
{:right-dir {:box [300 40 320 140] (make-background :interactions
:script (actions/get-script {:right-dir {:box [300 40 320 140]
entities :script (actions/get-script
(actions/walk-to entities :ego [310 80]) entities
(actions/transition-background entities :outside-house [0 80])) (actions/walk-to entities :ego [310 80])
:cursor :right}} (actions/transition-background entities :outside-house [0 80]))
:layers [(assoc (texture "behindhouse/background.png") :x 0 :y 0 :baseline 0)] :cursor :right}}
:collision "behindhouse/collision.png" :layers [(assoc (texture "behindhouse/background.png") :x 0 :y 0 :baseline 0)]
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))}) :collision "behindhouse/collision.png"
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))}))
(defn animate [entity screen]
(if (:anim entity)
(merge entity (animation->texture screen (:anim entity)))
entity)
)
(defscreen scene (defscreen scene
:on-show :on-show
(fn [screen entities] (fn [screen entities]
(update! screen :renderer (stage) :camera (orthographic)) (update! screen :renderer (stage) :camera (orthographic))
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0) (let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
sheep (animation 0.15 (for [i (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 9 10 (repeat 25 11) (repeat 15 12)])]
(aget sheep-sheet 0 i)))
music (sound "town-music.mp3") music (sound "town-music.mp3")
_ (sound! music :loop) _ (sound! music :loop)
backgrounds (backgrounds) backgrounds (backgrounds screen)]
]
{:backgrounds backgrounds {:backgrounds backgrounds
:actions {:object nil :actions {:object nil
:channel (chan) :channel (chan)
@@ -189,8 +196,6 @@
:current :main :current :main
:last :main :last :main
:override nil} :override nil}
:sheep (assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep)
:background (:outside-house backgrounds) :background (:outside-house backgrounds)
:ego (get-ego screen) :ego (get-ego screen)
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 9000) :fps (assoc (label "0" (color :white) ) :x 5 :baseline 9000)
@@ -201,16 +206,11 @@
(clear!) (clear!)
(let [entities (update-cursor screen entities) (let [entities (update-cursor screen entities)
entities (update-from-script screen entities) entities (update-from-script screen entities)
entities (update-in entities [:background :entities] (fn [entities] (map #(animate % screen) entities)))
entities (update-in entities [:ego] #(animate % screen))
_ (label! (:fps entities) :set-text (str (game :fps))) all-entities (concat (vals entities) (get-in entities [:background :layers]) (get-in entities [:background :entities]))]
entities (if (get-in entities [:sheep :anim]) (label! (:fps entities) :set-text (str (game :fps)))
(update-in entities [:sheep] #(merge % (animation->texture screen (:anim %)))) (render! screen (sort-by :baseline all-entities))
entities)
entities (if (get-in entities [:ego :anim])
(update-in entities [:ego] #(merge % (animation->texture screen (:anim %))))
entities)]
(render! screen (sort-by :baseline (concat (vals entities) (get-in entities [:background :layers]))))
entities)) entities))
:on-resize (fn [screen entities] :on-resize (fn [screen entities]