started revamping actions some more for making interactions simple.

This commit is contained in:
=
2014-09-16 13:01:54 -07:00
parent c91e0d7f52
commit 0f7ac68195
2 changed files with 46 additions and 50 deletions

View File

@@ -24,18 +24,16 @@
(cursor-override [this]))
(defprotocol IInteractable
(interact [this screen entities location]))
(get-script [this location]))
(def default-interaction
(reify
IInteractable
(interact [_ screen entities [x y]]
(actions/get-script
(get-script [_ [x y]]
(actions/get-script entities
(actions/walk-to entities :ego [x y])))))
(defn find-override [screen entities [x y]]
(first (filter #(and (mouse-in? % [x y])
(satisfies? ICursorOverridable %))
@@ -51,10 +49,10 @@
:actions {:channel (chan) :current nil :started? false})
entities)
script (or (when interaction
(interact interaction screen entities [x y]))
(interact default-interaction screen entities [x y]))]
(get-script interaction [x y]))
(get-script default-interaction [x y]))]
(script (get-in entities [:actions :channel]))
(script entities)
entities))
(defn get-ego [screen]
@@ -108,8 +106,8 @@
(mouse-in? [_ location]
(apply (apply zone/box (:box spec)) location))
IInteractable
(interact [_ screen entities location]
((:script spec) entities))
(get-script [_ location]
(:script spec))
ICursorOverridable
(cursor-override [this] (:cursor spec)))
)]
@@ -144,39 +142,38 @@
:sheep (assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep)
:background (make-background :interactions
{:door {:box [258 100 281 160]
:script (fn [entities]
(actions/get-script
(actions/walk-to entities :ego [262 88])
(actions/talk entities :ego (str "Anyone home?"))))}
:script (actions/get-script
entities
(actions/walk-to entities :ego [262 88])
(actions/talk entities :ego (str "Anyone home?")))}
:sword {:box [274 55 305 88]
:script (fn [entities]
(actions/get-script
(actions/talk entities :ego (str "It's the coolest sword I've ever seen!"))
(actions/walk-to entities :ego [290 66])
(actions/talk entities :ego "Maybe I can pull it out.")))}
:script (actions/get-script
entities
(actions/talk entities :ego (str "It's the coolest sword I've ever seen!"))
(actions/walk-to entities :ego [290 66])
(actions/talk entities :ego "Maybe I can pull it out."))}
:sheep {:box [38 160 71 181]
:script (fn [entities]
(actions/get-script
(if ((get-in entities [:ego :inventory]) :wool)
(actions/talk entities :ego "The sheep has given me enough wool.")
(do (actions/give entities :ego :wool)
(actions/talk entities :ego "I guess his wool is shedding.")))))}
:script (actions/get-script
entities
(if ((get-in @entities [:ego :inventory]) :wool)
(actions/talk entities :ego "The sheep has given me enough wool.")
(do (actions/give entities :ego :wool)
(actions/talk entities :ego "I guess his wool is shedding."))))}
:right-dir {:box [300 131 320 224]
:script (fn [entities]
(actions/get-script
(actions/walk-to entities :ego [319 160])))
:script (actions/get-script
entities
(actions/walk-to entities :ego [319 160]))
:cursor :right}
:up-dir {:box [60 180 224 240]
:script (fn [entities]
(actions/get-script
(actions/walk-to entities :ego [137 204])))
:script (actions/get-script
entities
(actions/walk-to entities :ego [137 204]))
:cursor :up}
:left-dir {:box [0 40 20 140]
:script (fn [entities]
(actions/get-script
(actions/walk-to entities :ego [0 80])))
:cursor :left}}
:script (actions/get-script
entities
(actions/walk-to entities :ego [0 80]))
:cursor :left}}
:layers [(assoc background :x 0 :y 0 :baseline 0)
(assoc house :x 0 :y 0 :baseline 122)