actions.
This commit is contained in:
@@ -63,7 +63,7 @@
|
|||||||
(when (:anim target)
|
(when (:anim target)
|
||||||
(texture (animation! (:anim target) :get-key-frame 0.25))))))))
|
(texture (animation! (:anim target) :get-key-frame 0.25))))))))
|
||||||
|
|
||||||
(defn begin-walking [screen entities target-id [x y]]
|
(defn path-to-actions [screen entities target-id [x y]]
|
||||||
(let [entity (target-id entities)
|
(let [entity (target-id entities)
|
||||||
path (vec (take-nth 2 (advent.pathfind/visit-all
|
path (vec (take-nth 2 (advent.pathfind/visit-all
|
||||||
(:collision (:background entities))
|
(:collision (:background entities))
|
||||||
@@ -73,23 +73,25 @@
|
|||||||
(conj
|
(conj
|
||||||
(vec (map #(walk-to-fn % target-id) (conj path [x y])))
|
(vec (map #(walk-to-fn % target-id) (conj path [x y])))
|
||||||
(stop-fn target-id)))]
|
(stop-fn target-id)))]
|
||||||
(assoc entity :actions actions)))
|
actions))
|
||||||
|
|
||||||
(defn walk-click [screen entities [x y]]
|
(defn walk-click [screen entities [x y]]
|
||||||
(assoc entities :ego (begin-walking screen entities :ego [x y])))
|
(assoc-in entities [:ego :actions] (path-to-actions screen entities :ego [x y])))
|
||||||
|
|
||||||
(defn walk-override-click [screen entities [x y]]
|
(defn walk-override-click [screen entities [x y]]
|
||||||
(let [target-location (->> (get-in entities [:background :mouse-overrides])
|
(let [target-location (->> (get-in entities [:background :mouse-overrides])
|
||||||
(filter #((:mouse-in? %) x y))
|
(filter #((:mouse-in? %) x y))
|
||||||
first
|
first
|
||||||
:go-to)]
|
:go-to)]
|
||||||
(assoc entities :ego (begin-walking screen entities :ego target-location))))
|
(assoc-in entities [:ego :actions] (path-to-actions screen entities :ego target-location))))
|
||||||
|
|
||||||
(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)})
|
||||||
(if (get-in entities [:cursor :override])
|
interaction (first (filter #((:mouse-in? %) x y) (get-in entities [:background :interactions])))]
|
||||||
(walk-override-click screen entities [x y])
|
(cond (get-in entities [:cursor :override]) (walk-override-click screen entities [x y])
|
||||||
(walk-click screen entities [x y]))))
|
interaction ((:click-fn interaction) screen entities [x y])
|
||||||
|
|
||||||
|
:else (walk-click screen entities [x y]))))
|
||||||
|
|
||||||
(defn get-ego [screen]
|
(defn get-ego [screen]
|
||||||
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
||||||
@@ -109,8 +111,8 @@
|
|||||||
|
|
||||||
(defn update-ego [screen entities ego]
|
(defn update-ego [screen entities ego]
|
||||||
(if-let [action (first (:actions ego))]
|
(if-let [action (first (:actions ego))]
|
||||||
(:ego (action screen entities))
|
(action screen entities)
|
||||||
ego))
|
entities))
|
||||||
|
|
||||||
(defn scaler-fn-with-baseline [baseline minimum-size & [maximum-size]]
|
(defn scaler-fn-with-baseline [baseline minimum-size & [maximum-size]]
|
||||||
(let [maximum-size (or maximum-size 1.0)]
|
(let [maximum-size (or maximum-size 1.0)]
|
||||||
@@ -154,6 +156,15 @@
|
|||||||
{:mouse-in? (box-maker-fn 0 40 30 140)
|
{:mouse-in? (box-maker-fn 0 40 30 140)
|
||||||
:cursor-override 6
|
:cursor-override 6
|
||||||
:go-to [0 80]}]
|
:go-to [0 80]}]
|
||||||
|
:interactions [{:mouse-in? (box-maker-fn 258 100 281 160)
|
||||||
|
:click-fn (fn [screen entities [x y]]
|
||||||
|
(assoc-in entities [:ego :actions] (concat (path-to-actions screen entities :ego [262 80])
|
||||||
|
[(fn [screen entities]
|
||||||
|
(let [talk (assoc (label "Knock knock. Anyone home?" (color :white) ) :x 5 :y 100 :baseline 9000)]
|
||||||
|
(label! talk :set-font-scale 0.2)
|
||||||
|
(-> entities
|
||||||
|
(assoc :talking talk)
|
||||||
|
(update-in [:ego :actions] rest))))])))}]
|
||||||
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))
|
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))
|
||||||
:house (assoc house
|
:house (assoc house
|
||||||
:x 0 :y 0
|
:x 0 :y 0
|
||||||
@@ -171,7 +182,7 @@
|
|||||||
:on-render
|
:on-render
|
||||||
(fn [screen [entities]]
|
(fn [screen [entities]]
|
||||||
(clear!)
|
(clear!)
|
||||||
(let [entities (assoc entities :ego (update-ego screen entities (:ego entities)))
|
(let [entities (update-ego screen entities (:ego entities))
|
||||||
_ (label! (:fps entities) :set-text (str (game :fps)))
|
_ (label! (:fps entities) :set-text (str (game :fps)))
|
||||||
entities (if (get-in entities [:ego :anim])
|
entities (if (get-in entities [:ego :anim])
|
||||||
(update-in entities [:ego] #(merge % (animation->texture screen (:anim %))))
|
(update-in entities [:ego] #(merge % (animation->texture screen (:anim %))))
|
||||||
|
|||||||
Reference in New Issue
Block a user