progress.

This commit is contained in:
Bryce Covert
2016-08-01 08:55:48 -07:00
parent bab004ab87
commit 9139a37119
3 changed files with 57 additions and 27 deletions

View File

@@ -172,7 +172,7 @@
(actions/walk-to entities :ego [242 49] :face :right) (actions/walk-to entities :ego [242 49] :face :right)
(actions/play-animation entities :ego :reach) (actions/play-animation entities :ego :reach)
(actions/add-entity entities :teddy (get-in @entities [:room :teddy])) (actions/add-entity entities :teddy (get-in @entities [:room :teddy]))
(actions/remove-item entities :portrait)) (actions/remove-item entities :teddy))
(defn has-to-return-teddy? [entities] (defn has-to-return-teddy? [entities]
(and (actions/has-item? entities :teddy) (and (actions/has-item? entities :teddy)

View File

@@ -891,25 +891,34 @@ void main ()
(defn get-animation-point [^Animation animation total-time] (defn get-looped-animation-point [^Animation animation total-time]
(loop [time total-time] (loop [time total-time]
(if (> (- time (animation! animation :get-animation-duration)) 0) (if (> (- time (animation! animation :get-animation-duration)) 0)
(recur (- time (animation! animation :get-animation-duration))) (recur (- time (animation! animation :get-animation-duration)))
time))) time)))
(defn animate [entity screen] (defn animate [{:keys [anim anim-loop? anim-merges anim-start] :or {anim-loop? true} :as entity} {:keys [delta-time total-time] :or {delta-time 0} :as screen}]
(merge entity (animation->texture (update-in screen [:total-time] #(- % (:anim-start entity))) (let [current-frame-index (animation! ^Animation anim :get-key-frame-index
(:anim entity)) (if anim-loop?
{:current-frame-index (animation! ^Animation (:anim entity) :get-key-frame-index (get-animation-point (:anim entity) (- (:total-time screen) (:anim-start entity)))) (get-looped-animation-point anim (- total-time anim-start))
:previous-frame-index (animation! ^Animation (:anim entity) :get-key-frame-index (get-animation-point (:anim entity) (- (:total-time screen) (:anim-start entity) (or (:delta-time screen) 0)))) (- total-time anim-start)))
:origin-x (or (get-in entity [:anim-origins (:anim entity) 0]) previous-frame-index (animation! ^Animation anim :get-key-frame-index
(:base-origin-x entity) (if anim-loop?
(:origin-x entity)) (get-looped-animation-point anim (- total-time anim-start delta-time))
:origin-y (or (get-in entity [:anim-origins (:anim entity) 1]) (- total-time anim-start delta-time)))]
(:base-origin-y entity) (merge entity (animation->texture (update-in screen [:total-time] #(- % anim-start))
(:origin-y entity))} anim
(or (get-in entity [:anim-merges (:anim entity)]) anim-loop?)
(get-in entity [:anim-merges :default])))) {:current-frame-index current-frame-index
:previous-frame-index previous-frame-index
:origin-x (or (get-in entity [:anim-origins anim 0])
(:base-origin-x entity)
(:origin-x entity))
:origin-y (or (get-in entity [:anim-origins anim 1])
(:base-origin-y entity)
(:origin-y entity))}
(or (get-in entity [:anim-merges anim])
(get-in entity [:anim-merges :default])))))
(defn get-layers [entities] (defn get-layers [entities]
@@ -1318,10 +1327,10 @@ void main ()
(filter identity))] (filter identity))]
(utils/stop-music snd))) (utils/stop-music snd)))
:on-mouse-moved #_#_:on-mouse-moved
mouse-moved mouse-moved
:on-touch-dragged #_#_:on-touch-dragged
mouse-moved mouse-moved
:on-touch-down :on-touch-down
@@ -1633,10 +1642,14 @@ void main ()
(appear-transition state-data :show :none) (appear-transition state-data :show :none)
(reify ITransition (reify ITransition
(start-transition [this screen entities] (start-transition [this screen entities]
(screen! scene :on-click-inventory)
(update-in entities [:inventory] (fn [i] (actions/start-animation screen i :closing)))) (update-in entities [:inventory] (fn [i] (actions/start-animation screen i :closing))))
(transition-done? [this screen entities] true)) (transition-done? [this screen entities] true))
(appear-transition state-data :hide :in)])) (appear-transition state-data :hide :in)
(reify ITransition
(start-transition [this screen entities]
(dissoc entities :selected-item))
(transition-done? [this screen entities]
true))]))
(defmethod transition-hud [:acquire :none] (defmethod transition-hud [:acquire :none]
[screen entities state state-data] [screen entities state state-data]
@@ -1650,11 +1663,15 @@ void main ()
(defmethod transition-hud [:selected :acquire] (defmethod transition-hud [:selected :acquire]
[screen entities state state-data] [screen entities state state-data]
(accept-state entities state state-data)) (accept-state entities state state-data
[(appear-transition (get-in entities [:inv-fsm :state-data]) :hide :none)
(appear-transition state-data :show :none)
(appear-transition state-data :hide :in)]))
(defmethod transition-hud [:aquiring :acquire] (defmethod transition-hud [:acquire :selected]
[screen entities state state-data] [screen entities state state-data]
(accept-state entities state state-data)) (accept-state entities state state-data
[(appear-transition state-data :show :out)]))
(defn fsm-busy? [entities] (defn fsm-busy? [entities]
(seq (get-in entities [:inv-fsm :transition-steps]))) (seq (get-in entities [:inv-fsm :transition-steps])))
@@ -1708,6 +1725,7 @@ void main ()
:open (doto (utils/make-anim-seq "open-inventory" [42 56] 0.055 (flatten [(range 6) 6 7 8 7 ])) :open (doto (utils/make-anim-seq "open-inventory" [42 56] 0.055 (flatten [(range 6) 6 7 8 7 ]))
(animation! :set-play-mode (play-mode :normal))) (animation! :set-play-mode (play-mode :normal)))
:anim (utils/make-anim "inventory.png" [42 56] 0.1 [0]) :anim (utils/make-anim "inventory.png" [42 56] 0.1 [0])
:anim-loop? false
:default (utils/make-anim "inventory.png" [42 56] 0.1 [0]) :default (utils/make-anim "inventory.png" [42 56] 0.1 [0])
:opened (utils/make-anim-seq "open-inventory" [42 56] 0.1 [7]) :opened (utils/make-anim-seq "open-inventory" [42 56] 0.1 [7])
:closing (doto (utils/make-anim-seq "open-inventory" [42 56] 0.055 [7 7 7 7 7 7 7 9 10 11 12 0]) :closing (doto (utils/make-anim-seq "open-inventory" [42 56] 0.055 [7 7 7 7 7 7 7 9 10 11 12 0])
@@ -1780,9 +1798,13 @@ void main ()
(-> entities (-> entities
(update-in [:inv-fsm :pending-states] conj [:remove item]) (update-in [:inv-fsm :pending-states] conj [:remove item])
(update-in [:inv-fsm] (fn [{:keys [state state-data] :as fsm}] (update-in [:inv-fsm] (fn [{:keys [state state-data] :as fsm}]
(if (and (= state :selected) (= item state-data)) (cond
(and (= state :selected) (= item state-data))
(update-in fsm [:pending-states] conj [:none state-data]) (update-in fsm [:pending-states] conj [:none state-data])
(update-in fsm [:pending-states] conj [state state-data])))))) (= state :selected)
(update-in fsm [:pending-states] conj [state state-data])
:else
(update-in fsm [:pending-states] conj [:none state-data]))))))
:on-return-item :on-return-item
(fn [screen [ entities]] (fn [screen [ entities]]
@@ -1803,13 +1825,21 @@ void main ()
(transition-hud screen entities :selected cursor) (transition-hud screen entities :selected cursor)
(transition-hud screen entities :none nil)))) (transition-hud screen entities :none nil))))
:on-mouse-moved :on-touch-down
(fn [screen [entities]]
(let [[x y] (utils/unproject screen)
hovered-inventory? ((:mouse-in? (:inventory entities)) x y)
hovered-close? (utils/intersects? (:close entities) [x y])
hovered-save? (utils/intersects? (:save entities) [x y])]
(screen! scene :hud-active? :hud-active? (or hovered-close? hovered-inventory? hovered-save?))))
#_#_:on-mouse-moved
(fn [screen [entities]] (fn [screen [entities]]
(let [[x y] (utils/unproject screen) (let [[x y] (utils/unproject screen)
hovered-inventory? ((:mouse-in? (:inventory entities)) x y) hovered-inventory? ((:mouse-in? (:inventory entities)) x y)
hovered-close? (utils/intersects? (:close entities) [x y]) hovered-close? (utils/intersects? (:close entities) [x y])
hovered-save? (utils/intersects? (:save entities) [x y])] hovered-save? (utils/intersects? (:save entities) [x y])]
(screen! scene :hud-active? :hud-active? (or hovered-close? hovered-inventory? hovered-save?))
(cond (and hovered-inventory? (hud-interactable?)) (cond (and hovered-inventory? (hud-interactable?))
(as-> entities entities (as-> entities entities
(grow-hud screen entities :inventory true) (grow-hud screen entities :inventory true)

View File

@@ -361,7 +361,7 @@
(let [current-action (get-in entities [:fg-actions :current]) (let [current-action (get-in entities [:fg-actions :current])
is-script-running (get-in entities [:fg-actions :script-running?])] is-script-running (get-in entities [:fg-actions :script-running?])]
(and is-script-running (and is-script-running
(= :none (get-in entities [:fg-actions :last-skip-type]))))) (not= :end (get-in entities [:fg-actions :last-skip-type])))))
(defn update-override [{:keys [^FitViewport viewport] :as screen} entities] (defn update-override [{:keys [^FitViewport viewport] :as screen} entities]
(let [raw-pos (get-in entities [:cursor :last-pos]) (let [raw-pos (get-in entities [:cursor :last-pos])