progress on interactions with cursors

This commit is contained in:
Bryce Covert
2016-08-11 21:22:56 -07:00
parent a3536d7b0d
commit 626eb12f98
7 changed files with 133 additions and 89 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@@ -6,7 +6,7 @@
[com.badlogic.gdx.scenes.scene2d Actor Stage] [com.badlogic.gdx.scenes.scene2d Actor Stage]
[java.lang Object])) [java.lang Object]))
(defn make-entity [id entity] (defn make-entity [id {:keys [scripts script only-script] :as entity}]
(merge entity (merge entity
{:id id {:id id
:mouse-in? (fn [entities x y] :mouse-in? (fn [entities x y]
@@ -22,24 +22,41 @@
((zone/box entity-x entity-y ((zone/box entity-x entity-y
(+ entity-x (* width (or scale-x 1))) (+ entity-x (* width (or scale-x 1)))
(+ entity-y (* height (or scale-y 1)))) x y)))} (+ entity-y (* height (or scale-y 1)))) x y)))}
(when (or (:scripts entity) (:script entity)) (when (or script scripts only-script)
{:get-script (fn [cursor [x y]] {:get-script (fn [cursor [x y]]
(if (= :main cursor) (cond only-script
(:script entity) only-script
(when-let [scripts (:scripts entity)]
(or (scripts (:value cursor)) (scripts :default)))))}))) (= :main cursor)
script
scripts
(or (scripts (:value cursor)) (scripts :default))
:else
nil)
)})))
(defn make [& {:keys [collision interactions entities] :as params}] (defn make [& {:keys [collision interactions entities] :as params}]
(let [interactions-as-list (for [[id spec] interactions] (let [interactions-as-list (for [[id {:keys [script scripts only-script box] :as spec}] interactions]
(merge spec (merge spec
(when (:box spec) (when box
{:mouse-in? (fn [_ x y] {:mouse-in? (fn [_ x y]
((apply zone/box (:box spec)) x y))}) ((apply zone/box box) x y))})
{:get-script (fn [cursor [x y]] (when (or script scripts only-script)
(if (= :main cursor) {:get-script (fn [cursor [x y]]
(:script spec) (cond only-script
(when-let [scripts (:scripts spec)] only-script
(or (scripts (:value cursor)) (scripts :default)))))
:id id})) (= :main cursor)
script
scripts
(or (scripts (:value cursor)) (scripts :default))
:else
nil)
)})
{:id id}))
entities (into {} (for [[id entity] entities] entities (into {} (for [[id entity] entities]
[id (make-entity id entity)]))] [id (make-entity id entity)]))]
(merge params {:collision (advent.pathfind/map-from-resource collision) (merge params {:collision (advent.pathfind/map-from-resource collision)

View File

@@ -66,6 +66,7 @@
disappear-left {1 [:disappear 0.7]} disappear-left {1 [:disappear 0.7]}
} }
:night-profile :sprite :night-profile :sprite
:cursor :talk
:origin-x 0 :origin-x 0
:origin-y 0 :origin-y 0
:talk-color (color 0.95 0.3 1.0 1.0) :talk-color (color 0.95 0.3 1.0 1.0)

View File

@@ -629,7 +629,7 @@
:cauldron-sound {:object nil :sound (utils/load-sound "outsidehouse/cauldron.ogg")} :cauldron-sound {:object nil :sound (utils/load-sound "outsidehouse/cauldron.ogg")}
:interactions :interactions
{:door {:box [250 100 281 160] {:door {:box [250 100 281 160]
:script :only-script
(actions/get-script (actions/get-script
entities entities
(actions/walk-to entities :ego [257 90] :face :right :skip-type :end) (actions/walk-to entities :ego [257 90] :face :right :skip-type :end)
@@ -660,21 +660,21 @@
:cursor :right} :cursor :right}
:right-dir {:box [220 141 320 204] :right-dir {:box [220 141 320 204]
:script (actions/get-script :only-script (actions/get-script
entities entities
(actions/walk-to entities :ego [244 150] :skip-type :end) (actions/walk-to entities :ego [244 150] :skip-type :end)
(actions/transition-background entities :behind-house [122 140]) (actions/transition-background entities :behind-house [122 140])
(actions/walk-to entities :ego [172 122])) (actions/walk-to entities :ego [172 122]))
:cursor :right} :cursor :right}
:up-dir {:box [105 180 203 240] :up-dir {:box [105 180 203 240]
:script (actions/get-script :only-script (actions/get-script
entities entities
(actions/walk-to entities :ego [137 204] :skip-type :end) (actions/walk-to entities :ego [137 204] :skip-type :end)
(actions/transition-background entities :cat-tree [223 -51]) (actions/transition-background entities :cat-tree [223 -51])
(actions/walk-straight-to entities :ego [200 10])) (actions/walk-straight-to entities :ego [200 10]))
:cursor :up} :cursor :up}
:left-dir {:box [0 40 40 140] :left-dir {:box [0 40 40 140]
:script (actions/get-script :only-script (actions/get-script
entities entities
(walk-to-castle entities)) (walk-to-castle entities))
:cursor :left}} :cursor :left}}
@@ -697,6 +697,7 @@
[:stand 1] sheep-1 [:stand 1] sheep-1
[:stand 2] sheep-2 [:stand 2] sheep-2
[:stand 3] sheep-3 [:stand 3] sheep-3
:cursor :hand
:origin-y 3 :origin-y 3
:origin-x 6 :origin-x 6
:scale-x (scaler [38 160]) :scale-x (scaler [38 160])
@@ -785,7 +786,7 @@
:outside-particles (common/make-outside-particles) :outside-particles (common/make-outside-particles)
:magic (assoc (doto (particle-effect "particles/magic") ) :magic (assoc (particle-effect "particles/magic")
:x 153 :x 153
:y 105 :y 105
:baseline 238) :baseline 238)
@@ -796,19 +797,20 @@
:anim-sound-frames {door {1 [:door-sound 0.1]}} :anim-sound-frames {door {1 [:door-sound 0.1]}}
) )
:lamb (assoc (utils/get-texture "outsidehouse/lamb.png") :lamb (assoc (utils/get-texture "outsidehouse/lamb.png")
:x 10 :y 163 :baseline 77 :cursor :look
:right {:stand (animation 0.1 [lamb-stand]) :x 10 :y 163 :baseline 77
:walk lamb-walk} :right {:stand (animation 0.1 [lamb-stand])
:walk lamb-walk}
:left {:stand (utils/flip (animation 0.1 [lamb-stand]))
:walk (utils/flip lamb-walk)} :left {:stand (utils/flip (animation 0.1 [lamb-stand]))
:scale-x (scaler [10 163]) :walk (utils/flip lamb-walk)}
:scale-y (scaler [10 163]) :scale-x (scaler [10 163])
:script (actions/get-script entities :scale-y (scaler [10 163])
(actions/talk entities :ego "Aww, it's a newborn lamb!")) :script (actions/get-script entities
:scripts {:carrot (actions/get-script entities (actions/talk entities :ego "I think it's still nursing.")) (actions/talk entities :ego "Aww, it's a newborn lamb!"))
:grass (actions/get-script entities (actions/talk entities :ego "I think it's still nursing.")) :scripts {:carrot (actions/get-script entities (actions/talk entities :ego "I think it's still nursing."))
:sword (actions/get-script entities (actions/talk entities :ego "I prefer to let the butcher make lamb chops."))}) :grass (actions/get-script entities (actions/talk entities :ego "I think it's still nursing."))
:sword (actions/get-script entities (actions/talk entities :ego "I prefer to let the butcher make lamb chops."))})
:butterfly (assoc (animation->texture screen butterfly-stand) :butterfly (assoc (animation->texture screen butterfly-stand)
:x 161 :x 161
:y 218 :y 218
@@ -823,6 +825,7 @@
a (catmull-rom-spline! ^CatmullRomSpline (:path entity) :value-at v pos-f)] a (catmull-rom-spline! ^CatmullRomSpline (:path entity) :value-at v pos-f)]
(assoc entity :x (vector-2! v :x) :y (vector-2! v :y)))))} (assoc entity :x (vector-2! v :x) :y (vector-2! v :y)))))}
:cauldron (rooms/make-entity :cauldron (assoc (animation->texture screen cauldron) :cauldron (rooms/make-entity :cauldron (assoc (animation->texture screen cauldron)
:cursor :look
:x 139 :y 73 :baseline 167 :x 139 :y 73 :baseline 167
:anim cauldron :anim cauldron
:anim-start 0 :anim-start 0
@@ -832,6 +835,7 @@
:scripts put-something-in-cauldron)) :scripts put-something-in-cauldron))
:charcoal (rooms/make-entity :charcoal :charcoal (rooms/make-entity :charcoal
(assoc (animation->texture screen charcoal) (assoc (animation->texture screen charcoal)
:cursor :hand
:anim charcoal :anim charcoal
:anim-start 0 :anim-start 0
:night-profile :none :night-profile :none
@@ -854,6 +858,7 @@
:wizard "Good job, Tick."))}})) :wizard "Good job, Tick."))}}))
:note (rooms/make-entity :note (assoc (utils/get-texture "outsidehouse/note.png") :note (rooms/make-entity :note (assoc (utils/get-texture "outsidehouse/note.png")
:x 277 :y 74 :baseline 160 :x 277 :y 74 :baseline 160
:cursor :hand
:night-profile :none :night-profile :none
:script (actions/get-script entities :script (actions/get-script entities
(actions/walk-to entities :ego [280 80] :face :right) (actions/walk-to entities :ego [280 80] :face :right)

View File

@@ -221,7 +221,8 @@ void main ()
(get-in entities [:room :interactions]))) ) (get-in entities [:room :interactions]))) )
(defn get-interacting-entity [entities x y] (defn get-interacting-entity [entities x y]
(let [interactable-entities (if (= (doto (get-selected-inventory-item) (#(log/info "clicked with " %)) ) :main) (let [interactable-entities (if (= (doto (get-selected-inventory-item)
(#(log/info "clicked with " %)) ) :main)
(vals (dissoc (get-in entities [:room :entities]) :ego)) (vals (dissoc (get-in entities [:room :entities]) :ego))
(vals (get-in entities [:room :entities]))) (vals (get-in entities [:room :entities])))
interacting-entity (first (sort-by (comp - :baseline) interacting-entity (first (sort-by (comp - :baseline)
@@ -248,13 +249,13 @@ void main ()
(or (= (get-in entities [:cursor :down-target]) (or (= (get-in entities [:cursor :down-target])
(or (:id interacting-entity) (:id interaction) nil)) (or (:id interacting-entity) (:id interaction) nil))
(get-in entities [:cursor :came-from-inventory?]))) (get-in entities [:cursor :came-from-inventory?])))
((or (when (and interacting-entity (not (:cursor interaction))) ((or (when (and (not (:override-cursor interaction))
interacting-entity)
(do (screen! hud :on-start-script {}) (do (screen! hud :on-start-script {})
((:get-script interacting-entity) (get-script-selector entities) [x y]))) ((:get-script interacting-entity) (get-script-selector entities) [x y])))
(when interaction (when interaction
(do (screen! hud :on-start-script {}) (do (screen! hud :on-start-script {})
((:get-script interaction) (or (when (:cursor interaction) :main) ((:get-script interaction) (get-script-selector entities)
(get-script-selector entities))
[x y]))) [x y])))
((:get-script default-interaction) (get-script-selector entities) [x y])) entities)) ((:get-script default-interaction) (get-script-selector entities) [x y])) entities))
@@ -878,17 +879,35 @@ void main ()
entities) entities)
entities)) entities))
(defn update-cursor [screen {{:keys [override last active was-active]} :cursor :as entities}] (defn translate-depressed [cursor depressed?]
(if (= 0.0 (get-in entities [:fade :opacity])) (if depressed?
(let [new-current (or override (get-selected-inventory-item) :main)] (get {:hand :hand-depressed
(when-not (and (= new-current :talk :talk-depressed
last) :look :look-depressed} cursor cursor)
(= active was-active)) cursor))
(let [image-path (if active "cursor_light.png" "cursor.png")]
(graphics! :set-cursor (utils/cursor image-path (or (:cursor new-current) new-current))))) (defn update-cursor [{:keys [total-time] :as screen} {{:keys [override last depressed? time-changed] :or {time-changed 0}} :cursor :as entities}]
(update-in entities [:cursor ] assoc :last new-current (let [new-current (or override (get-selected-inventory-item) :main)
:was-active active)) time-changed (double time-changed)
entities)) total-time (double total-time)]
(cond
(not= 0.0 (get-in entities [:fade :opacity]))
entities
(< (unchecked-subtract total-time time-changed) 0.15)
entities
(= [new-current depressed?] last)
entities
:else
(do
(graphics! :set-cursor (utils/cursor "cursor.png" (translate-depressed (or (:cursor new-current) new-current)
depressed?)))
(update-in entities [:cursor ] assoc
:last [new-current depressed?]
:time-changed total-time))
)))
(defn get-looped-animation-point ^double [^Animation animation ^double total-time] (defn get-looped-animation-point ^double [^Animation animation ^double total-time]
@@ -1236,7 +1255,7 @@ void main ()
:on-resume (fn [screen {{:keys [current override last active was-active]} :cursor :as entities} options] :on-resume (fn [screen {{:keys [current override last active was-active]} :cursor :as entities} options]
(let [current (or override (get-selected-inventory-item) :main) (let [current (or override (get-selected-inventory-item) :main)
image-path (if active "cursor_light.png" "cursor.png")] image-path "cursor.png"]
(graphics! :set-cursor (utils/cursor image-path (or (:cursor current) current)))) (graphics! :set-cursor (utils/cursor image-path (or (:cursor current) current))))
(doseq [[k [start time fn]] (get-in entities [:room :timers])] (doseq [[k [start time fn]] (get-in entities [:room :timers])]
(add-timer! screen k start time))) (add-timer! screen k start time)))
@@ -1337,7 +1356,7 @@ void main ()
(set! (. camera zoom) (:zoom (:cam entities))) (set! (. camera zoom) (:zoom (:cam entities)))
(set! (.. camera position x) (:x (:cam entities) 160.0)) (set! (.. camera position x) (:x (:cam entities) 160.0))
(set! (.. camera position y) (:y (:cam entities) 120.0))) (set! (.. camera position y) (:y (:cam entities) 120.0)))
(let [#_#_entities (utils/update-override screen entities options) (let [entities (utils/update-override screen entities options)
entities (play-key-sounds screen entities) entities (play-key-sounds screen entities)
entities (update-current-sound-vols! entities) entities (update-current-sound-vols! entities)
entities (remove-ended-sounds screen entities)] entities (remove-ended-sounds screen entities)]
@@ -1371,6 +1390,7 @@ void main ()
(when (utils/contains-point? (.getScreenX viewport) (.getScreenY viewport) (when (utils/contains-point? (.getScreenX viewport) (.getScreenY viewport)
(.getScreenWidth viewport) (.getScreenHeight viewport) (.getScreenWidth viewport) (.getScreenHeight viewport)
input-x input-y) input-x input-y)
; TODO: override cursor when started in black
(when (and (= (button-code :left) (when (and (= (button-code :left)
(:button options)) (:button options))
(get-in entities [:state :active?]) (get-in entities [:state :active?])
@@ -1379,22 +1399,31 @@ void main ()
(let [[x y] (utils/unproject screen options) (let [[x y] (utils/unproject screen options)
interaction (get-interaction entities x y) interaction (get-interaction entities x y)
interacting-entity (get-interacting-entity entities x y)] interacting-entity (get-interacting-entity entities x y)]
(assoc-in entities [:cursor :down-target] (or (:id interacting-entity ) (:id interaction) nil)))))) (-> entities
(assoc-in [:cursor :depressed?] true)
(assoc-in [:cursor :down-target] (or (:id interacting-entity ) (:id interaction) nil)))))))
:on-touch-up (fn [{:keys [^FitViewport viewport] :as screen} entities {:keys [input-x input-y] :as options}] :on-touch-up (fn [{:keys [^FitViewport viewport] :as screen} entities {:keys [input-x input-y] :as options}]
(let [entities (assoc-in entities [:cursor :depressed?] false)]
(when (utils/contains-point? (.getScreenX viewport) (.getScreenY viewport) (cond
(.getScreenWidth viewport) (.getScreenHeight viewport) (not (utils/contains-point? (.getScreenX viewport) (.getScreenY viewport)
input-x input-y) (.getScreenWidth viewport) (.getScreenHeight viewport)
(if (= (button-code :right) input-x input-y))
(:button options)) entities
(do
(screen! hud :on-return-item {})) (= (button-code :right)
(when (and (get-in entities [:state :active?]) (:button options))
(or (not (get-in entities [:state :hud-active?])) (do (screen! hud :on-return-item {})
(get-in entities [:fg-actions :script-running?])) entities)
(= 0.0 (get-in entities [:fade :opacity])))
(left-click screen entities options))))) (and (get-in entities [:state :active?])
(or (not (get-in entities [:state :hud-active?]))
(get-in entities [:fg-actions :script-running?]))
(= 0.0 (get-in entities [:fade :opacity])))
(left-click screen entities options)
:else
entities)))
:on-deactivate (fn [screen entities options] :on-deactivate (fn [screen entities options]
(assoc-in entities [:state :active?] false)) (assoc-in entities [:state :active?] false))

View File

@@ -45,13 +45,13 @@
(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)})]
(log/info (:input-x screen) (:input-y screen) "->" x y))) (log/info (:input-x screen) (:input-y screen) "->" x y)))
(def ^:const +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :charcoal :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot :active-main :shovel :broom :tune]) (def ^:const +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :charcoal :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot :active-main :shovel :broom :tune :hand :hand-depressed :talk :talk-depressed :look :look-depressed])
(def settings (atom {:music-volume 50.0 (def settings (atom {:music-volume 50.0
:sound-volume 75.0 :sound-volume 75.0
:fullscreen true})) :fullscreen true}))
(def selected-save (atom nil)) (defonce selected-save (atom nil))
(defn current-music-volume [& [^double factor]] (defn current-music-volume [& [^double factor]]
(-> (Math/pow (unchecked-multiply (:music-volume @settings) 0.01) 2) (-> (Math/pow (unchecked-multiply (:music-volume @settings) 0.01) 2)
@@ -271,8 +271,7 @@
(assoc entity :x (vector-2! v :x) :y (vector-2! v :y))))))) (assoc entity :x (vector-2! v :x) :y (vector-2! v :y)))))))
(defn path-point [speed screen entities entity] (defn path-point [speed screen entities entity]
(* (- (:total-time screen) (:path-start-time entity 0.0)) speed) (* (- (:total-time screen) (:path-start-time entity 0.0)) speed))
)
(defn update-path-location [speed screen entities entity] (defn update-path-location [speed screen entities entity]
(if (:path entity) (if (:path entity)
@@ -291,10 +290,10 @@
(filter #(and (:mouse-in? %) (filter #(and (:mouse-in? %)
((:mouse-in? %) entities x y) ((:mouse-in? %) entities x y)
(not= "ego" (:id %)) (not= "ego" (:id %))
(:script %)) (:get-script %))
(vals (get-in entities [:room :entities]))) (vals (get-in entities [:room :entities])))
(filter #(and ((:mouse-in? %) entities x y) (filter #(and ((:mouse-in? %) entities x y)
(:script %)) (:get-script %))
(get-in entities [:room :interactions]))))) (get-in entities [:room :interactions])))))
(defn hovering-ego [entities [x y]] (defn hovering-ego [entities [x y]]
@@ -388,7 +387,8 @@
(.getScreenWidth viewport) (.getScreenHeight viewport) (.getScreenWidth viewport) (.getScreenHeight viewport)
(first raw-pos) (last raw-pos))) (first raw-pos) (last raw-pos)))
hovering-ego (hovering-ego entities last-pos) hovering-ego (hovering-ego entities last-pos)
current (get-in entities [:cursor :current])] current (get-in entities [:cursor :current])
selected-inventory-item (@(resolve 'advent.screens.scene/get-selected-inventory-item))]
(cond (cond
out-of-bounds out-of-bounds
@@ -397,35 +397,27 @@
(not (get-in entities [:state :active?])) (not (get-in entities [:state :active?]))
(-> entities (-> entities
(assoc-in [:cursor :override] nil) (assoc-in [:cursor :override] nil))
(assoc-in [:cursor :active] false))
(is-unstoppable-script-running screen entities) (is-unstoppable-script-running screen entities)
(-> entities (-> entities
(assoc-in [:cursor :override] :hourglass) (assoc-in [:cursor :override] :hourglass))
(assoc-in [:cursor :active] false))
(get-in entities [:state :hud-active?]) (get-in entities [:state :hud-active?])
(-> entities (-> entities
(assoc-in [:cursor :override] nil) (assoc-in [:cursor :override] nil))
(assoc-in [:cursor :active] false))
(and hovering-ego (not @(resolve 'advent.screens.scene/get-selected-inventory-item))) (and mouse-override (:only-script mouse-override))
(-> entities (assoc-in entities [:cursor :override] (:cursor mouse-override))
(assoc-in [:cursor :override] (or (:cursor mouse-override) (when (#{:main :active-main} (get-in entities [:cursor :last])) :active-main)))
(assoc-in [:cursor :active] true)) selected-inventory-item
(assoc-in entities [:cursor :override] selected-inventory-item)
mouse-override mouse-override
(-> entities (assoc-in entities [:cursor :override] (:cursor mouse-override))
(assoc-in [:cursor :override] (or (:cursor mouse-override) (when (#{:main :active-main} (get-in entities [:cursor :last])) :active-main)))
(assoc-in [:cursor :active] true))
:else :else
(-> entities (assoc-in entities [:cursor :override] :main))))
(assoc-in [:cursor :override] nil)
(assoc-in [:cursor :active] false)))))
(def default-night-merge {:r 0.08 :g 0.1 :b 0.36 :multiply-amount 1.0 :hue-amount 1.0}) (def default-night-merge {:r 0.08 :g 0.1 :b 0.36 :multiply-amount 1.0 :hue-amount 1.0})
(def default-night-merge-sprite {:r 0.08 :g 0.1 :b 0.36 :multiply-amount 0.3 :hue-amount 0.4}) (def default-night-merge-sprite {:r 0.08 :g 0.1 :b 0.36 :multiply-amount 0.3 :hue-amount 0.4})