diff --git a/desktop/resources/cursor.png b/desktop/resources/cursor.png index d87b759e..5c6b7c01 100644 Binary files a/desktop/resources/cursor.png and b/desktop/resources/cursor.png differ diff --git a/desktop/resources/pathfind-test-big.png b/desktop/resources/pathfind-test-big.png deleted file mode 100644 index c2c63c56..00000000 Binary files a/desktop/resources/pathfind-test-big.png and /dev/null differ diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index d2afd4d0..55feda52 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -37,22 +37,20 @@ (defn find-override [screen entities [x y]] - (first (filter #(mouse-in? % [x y]) - (get-in entities [:background :mouse-overrides])))) + (first (filter #(and (mouse-in? % [x y]) + (satisfies? ICursorOverridable %)) + (get-in entities [:background :interactions])))) (defn left-click [screen entities] (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)}) interaction (first (filter #(mouse-in? % [x y]) (get-in entities [:background :interactions]))) - cursor-override (find-override screen entities [x y]) ;; TODO - hacky way of resetting queue entities (if-let [current-action (get-in entities [:actions :current])] (assoc (actions/terminate current-action screen entities) :actions {:channel (chan) :current nil :started? false}) entities) - script (or (when cursor-override - (interact cursor-override screen entities [x y])) - (when interaction + script (or (when interaction (interact interaction screen entities [x y])) (interact default-interaction screen entities [x y]))] @@ -103,6 +101,21 @@ (input! :set-cursor-image (utils/cursor "cursor.png" (or override current)) 0 0)) (assoc-in entities [:cursor :last] (or override current))) +(defn make-background [& {:keys [collision interactions] :as params}] + (let [interactions-as-list (for [[id spec] interactions] + (reify + IMouseIn + (mouse-in? [_ location] + (apply (apply zone/box (:box spec)) location)) + IInteractable + (interact [_ screen entities location] + ((:script spec) entities)) + ICursorOverridable + (cursor-override [this] (:cursor spec))) + )] + (merge params {:collision (advent.pathfind/map-from-resource collision) + :interactions interactions-as-list}))) + (defscreen scene :on-show (fn [screen entities] @@ -116,7 +129,7 @@ house (texture "house.png") overdirt (texture "overdirt.png") music (sound "town-music.mp3") - _ (sound! music :loop) + ;;_ (sound! music :loop) ] { :actions {:object nil @@ -127,75 +140,50 @@ :current :main :last :main :override nil} + :sheep (assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep) - :background (assoc {} - :collision (advent.pathfind/map-from-resource "pathfind-test-big.png") - :baseline 0 - :mouse-overrides [(reify - IMouseIn - (mouse-in? [_ location] - (apply (zone/box 300 131 320 224) location)) - IInteractable - (interact [_ _ entities _] - (actions/get-script - (actions/walk-to entities :ego [319 160]))) - ICursorOverridable - (cursor-override [_] :right)) - (reify - IMouseIn - (mouse-in? [_ location] - (apply (zone/box 60 180 224 240) location)) - IInteractable - (interact [_ _ entities _] - (actions/get-script - (actions/walk-to entities :ego [137 204]))) - ICursorOverridable - (cursor-override [_] :up)) - (reify - IMouseIn - (mouse-in? [_ location] - (apply (zone/box 0 40 20 140) location)) - IInteractable - (interact [_ _ entities _] - (actions/get-script - (actions/walk-to entities :ego [0 80]))) - ICursorOverridable - (cursor-override [_] :left))] - :interactions [(reify - IMouseIn - (mouse-in? [_ location] - (apply (zone/box 258 100 281 160) location)) - IInteractable - (interact [_ _ entities _] - (actions/get-script - (actions/walk-to entities :ego [262 88]) - (actions/talk entities :ego (str "Anyone home?"))))) - (reify - IMouseIn - (mouse-in? [_ location] - (apply (zone/box 274 55 305 88) location)) - IInteractable - (interact [_ screen 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.")))) - (reify - IMouseIn - (mouse-in? [_ location] - (apply (zone/box 38 160 71 181) location)) - IInteractable - (interact [_ screen 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."))))))] - :scale-fn (scaler-fn-with-baseline 110 0.10 1.00) - :layers [(assoc background :x 0 :y 0 :baseline 0) - (assoc house :x 0 :y 0 :baseline 122) - (assoc overdirt :x 0 :y 0 :baseline 240) - (assoc background-trees :x 0 :y 0 :baseline 44)]) + :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?"))))} + :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.")))} + :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.")))))} + :right-dir {:box [300 131 320 224] + :script (fn [entities] + (actions/get-script + (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]))) + :cursor :up} + + :left-dir {:box [0 40 20 140] + :script (fn [entities] + (actions/get-script + (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) + (assoc overdirt :x 0 :y 0 :baseline 240) + (assoc background-trees :x 0 :y 0 :baseline 44)] + :collision "outsidehouse/collision.png" + :scale-fn (scaler-fn-with-baseline 110 0.10 1.00)) :ego (get-ego screen) :fps (assoc (label "0" (color :white) ) :x 5 :baseline 9000) }))