creating make-background, which should make making backgrounds easier.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.2 KiB |
@@ -37,22 +37,20 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn find-override [screen entities [x y]]
|
(defn find-override [screen entities [x y]]
|
||||||
(first (filter #(mouse-in? % [x y])
|
(first (filter #(and (mouse-in? % [x y])
|
||||||
(get-in entities [:background :mouse-overrides]))))
|
(satisfies? ICursorOverridable %))
|
||||||
|
(get-in entities [:background :interactions]))))
|
||||||
|
|
||||||
(defn left-click [screen entities]
|
(defn left-click [screen entities]
|
||||||
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
|
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
|
||||||
interaction (first (filter #(mouse-in? % [x y])
|
interaction (first (filter #(mouse-in? % [x y])
|
||||||
(get-in entities [:background :interactions])))
|
(get-in entities [:background :interactions])))
|
||||||
cursor-override (find-override screen entities [x y])
|
|
||||||
;; TODO - hacky way of resetting queue
|
;; TODO - hacky way of resetting queue
|
||||||
entities (if-let [current-action (get-in entities [:actions :current])]
|
entities (if-let [current-action (get-in entities [:actions :current])]
|
||||||
(assoc (actions/terminate current-action screen entities)
|
(assoc (actions/terminate current-action screen entities)
|
||||||
:actions {:channel (chan) :current nil :started? false})
|
:actions {:channel (chan) :current nil :started? false})
|
||||||
entities)
|
entities)
|
||||||
script (or (when cursor-override
|
script (or (when interaction
|
||||||
(interact cursor-override screen entities [x y]))
|
|
||||||
(when interaction
|
|
||||||
(interact interaction screen entities [x y]))
|
(interact interaction screen entities [x y]))
|
||||||
(interact default-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))
|
(input! :set-cursor-image (utils/cursor "cursor.png" (or override current)) 0 0))
|
||||||
(assoc-in entities [:cursor :last] (or override current)))
|
(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
|
(defscreen scene
|
||||||
:on-show
|
:on-show
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
@@ -116,7 +129,7 @@
|
|||||||
house (texture "house.png")
|
house (texture "house.png")
|
||||||
overdirt (texture "overdirt.png")
|
overdirt (texture "overdirt.png")
|
||||||
music (sound "town-music.mp3")
|
music (sound "town-music.mp3")
|
||||||
_ (sound! music :loop)
|
;;_ (sound! music :loop)
|
||||||
]
|
]
|
||||||
{
|
{
|
||||||
:actions {:object nil
|
:actions {:object nil
|
||||||
@@ -127,75 +140,50 @@
|
|||||||
: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)
|
:sheep (assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep)
|
||||||
:background (assoc {}
|
:background (make-background :interactions
|
||||||
:collision (advent.pathfind/map-from-resource "pathfind-test-big.png")
|
{:door {:box [258 100 281 160]
|
||||||
:baseline 0
|
:script (fn [entities]
|
||||||
:mouse-overrides [(reify
|
(actions/get-script
|
||||||
IMouseIn
|
(actions/walk-to entities :ego [262 88])
|
||||||
(mouse-in? [_ location]
|
(actions/talk entities :ego (str "Anyone home?"))))}
|
||||||
(apply (zone/box 300 131 320 224) location))
|
:sword {:box [274 55 305 88]
|
||||||
IInteractable
|
:script (fn [entities]
|
||||||
(interact [_ _ entities _]
|
(actions/get-script
|
||||||
(actions/get-script
|
(actions/talk entities :ego (str "It's the coolest sword I've ever seen!"))
|
||||||
(actions/walk-to entities :ego [319 160])))
|
(actions/walk-to entities :ego [290 66])
|
||||||
ICursorOverridable
|
(actions/talk entities :ego "Maybe I can pull it out.")))}
|
||||||
(cursor-override [_] :right))
|
:sheep {:box [38 160 71 181]
|
||||||
(reify
|
:script (fn [entities]
|
||||||
IMouseIn
|
(actions/get-script
|
||||||
(mouse-in? [_ location]
|
(if ((get-in entities [:ego :inventory]) :wool)
|
||||||
(apply (zone/box 60 180 224 240) location))
|
(actions/talk entities :ego "The sheep has given me enough wool.")
|
||||||
IInteractable
|
(do (actions/give entities :ego :wool)
|
||||||
(interact [_ _ entities _]
|
(actions/talk entities :ego "I guess his wool is shedding.")))))}
|
||||||
(actions/get-script
|
:right-dir {:box [300 131 320 224]
|
||||||
(actions/walk-to entities :ego [137 204])))
|
:script (fn [entities]
|
||||||
ICursorOverridable
|
(actions/get-script
|
||||||
(cursor-override [_] :up))
|
(actions/walk-to entities :ego [319 160])))
|
||||||
(reify
|
:cursor :right}
|
||||||
IMouseIn
|
:up-dir {:box [60 180 224 240]
|
||||||
(mouse-in? [_ location]
|
:script (fn [entities]
|
||||||
(apply (zone/box 0 40 20 140) location))
|
(actions/get-script
|
||||||
IInteractable
|
(actions/walk-to entities :ego [137 204])))
|
||||||
(interact [_ _ entities _]
|
:cursor :up}
|
||||||
(actions/get-script
|
|
||||||
(actions/walk-to entities :ego [0 80])))
|
:left-dir {:box [0 40 20 140]
|
||||||
ICursorOverridable
|
:script (fn [entities]
|
||||||
(cursor-override [_] :left))]
|
(actions/get-script
|
||||||
:interactions [(reify
|
(actions/walk-to entities :ego [0 80])))
|
||||||
IMouseIn
|
:cursor :left}}
|
||||||
(mouse-in? [_ location]
|
|
||||||
(apply (zone/box 258 100 281 160) location))
|
:layers [(assoc background :x 0 :y 0 :baseline 0)
|
||||||
IInteractable
|
(assoc house :x 0 :y 0 :baseline 122)
|
||||||
(interact [_ _ entities _]
|
(assoc overdirt :x 0 :y 0 :baseline 240)
|
||||||
(actions/get-script
|
(assoc background-trees :x 0 :y 0 :baseline 44)]
|
||||||
(actions/walk-to entities :ego [262 88])
|
:collision "outsidehouse/collision.png"
|
||||||
(actions/talk entities :ego (str "Anyone home?")))))
|
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))
|
||||||
(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)])
|
|
||||||
: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)
|
||||||
}))
|
}))
|
||||||
|
|||||||
Reference in New Issue
Block a user