adding camera panning. nice.

This commit is contained in:
2015-02-19 11:24:32 -08:00
parent dfdfcd7914
commit e517fffbd4
6 changed files with 179 additions and 116 deletions

View File

@@ -11,6 +11,8 @@
[advent.actions :as actions]
[advent.screens.dialogue :as dialogue]
[advent.utils :as utils]
[advent.tween :as tween]
[advent.tween :as tween]
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion Animation]
@@ -84,6 +86,43 @@
~@forms
(change-script-state ~entities false)))))
(defn pan-to [screen entities x y scale-fn]
(let [target-zoom (min 1.0 (max 0.85 (scale-fn [x y])))
current-zoom (get-in entities [:cam :zoom] 1.0)
;; don't zoom if it's a subtle difference
target-zoom (if (< (Math/abs (- target-zoom current-zoom))
0.07)
current-zoom
target-zoom)
target-x (min (- 320 (* 160.0 target-zoom))
(max (* 160.0 target-zoom)
x))
target-y (min (- 240 (* 120.0 target-zoom))
(max (* 120.0 target-zoom)
y))]
(-> entities
(assoc-in [:tweens :cam-zoom]
(tween/tween :cam-zoom screen
[:cam :zoom]
(get-in entities [:cam :zoom] 1.0)
target-zoom
3.0
:ease tween/ease-in-out-quadratic))
(assoc-in [:tweens :cam-x]
(tween/tween :cam-x screen
[:cam :x]
(get-in entities [:cam :x] 160.0)
target-x
3.0
:ease tween/ease-in-out-quadratic))
(assoc-in [:tweens :cam-y]
(tween/tween :cam-y screen
[:cam :y]
(get-in entities [:cam :y] 120.0)
target-y
3.0
:ease tween/ease-in-out-quadratic)))))
(defn jump-to [screen entities entity [x y] update-baseline?]
(let [scale-fn (-> entities :room :scale-fn)
@@ -116,6 +155,8 @@
(update-in entities [:room :entities target-id] (comp #(start-animation screen % :stand) (if face #(assoc % :facing face) identity))))
(defn walk-straight-to [entities target-id [final-x final-y] & {:keys [update-baseline? face speed anim override-dir stop?]}]
(let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id])
final-x (int final-x)
@@ -123,7 +164,9 @@
update-baseline? (if (nil? update-baseline?) true update-baseline?)]
(run-action entities
(begin [this screen entities]
entities)
(if (= :ego target-id)
(pan-to screen entities final-x final-y (get-in entities [:room :scale-fn]))
entities))
(continue [this screen entities]
(let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id])]
@@ -221,7 +264,9 @@
(if (seq path)
(run-action entities
(begin [this screen entities]
entities)
(if (= :ego target-id)
(pan-to screen entities final-x final-y (get-in entities [:room :scale-fn]))
entities))
(continue [this screen entities]
(let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id])
@@ -474,7 +519,8 @@
duration (or duration 2.0)]
(run-action entities
(begin [this screen entities]
(assoc-in entities [:tweens :fade-out-music] (utils/tween :fade-out-music screen [:volume :value] 1.0 0.0 duration)))
(assoc-in entities [:tweens :fade-out-music]
(tween/tween :fade-out-music screen [:volume :value] 1.0 0.0 duration)))
(continue [this screen entities]
entities)
@@ -507,9 +553,9 @@
(doseq [[k] (get-in entities [:room :timers])]
(remove-timer! screen k))
(as-> entities e
(assoc-in e [:tweens :fade-out] (utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 0.5))
(assoc-in e [:tweens :fade-out] (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 0.5))
(if music-changed?
(assoc-in e [:tweens :fade-out-music] (utils/tween :fade-out-music screen [:volume :value] 1.0 0.0 0.5))
(assoc-in e [:tweens :fade-out-music] (tween/tween :fade-out-music screen [:volume :value] 1.0 0.0 0.5))
e)
(assoc-in e [:cursor :current] :main)))
@@ -537,9 +583,13 @@
(assoc-in e [:room] (get-in entities [:rooms new-background]))
(assoc-in e [:room :entities :ego] ego)
(assoc-in e [:state :last-room] new-background)
(assoc-in e [:tweens :fade-in] (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 0.5))
(assoc-in e [:tweens :fade-in] (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 0.5))
(update-in e [:tweens] dissoc :cam-zoom :cam-x :cam-y)
(assoc-in e [:cam :x] 160)
(assoc-in e [:cam :y] 120)
(assoc-in e [:cam :zoom] 1.0)
(if music-changed?
(assoc-in e [:tweens :fade-in-music] (utils/tween :fade-in-music screen [:volume :value] 0.0 1.0 0.5))
(assoc-in e [:tweens :fade-in-music] (tween/tween :fade-in-music screen [:volume :value] 0.0 1.0 0.5))
e))
new-music (get-music (get-in entities [:room :music]) (get-in entities [:state :time]))
apply-state (get-in entities [:room :apply-state])

View File

@@ -3,6 +3,7 @@
[advent.actions :as actions]
[advent.screens.items :as items]
[advent.utils :as utils]
[advent.tween :as tween]
[clojure.zip :as zip]
[clojure.set :as set]
[clojure.string :as str]
@@ -19,9 +20,9 @@
(sound! (sound "inside-house/disappear.ogg") :play)
(-> entities
(assoc-in [:tweens :bloodclot-head-appear]
(utils/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 0.0 1.0 1.0 :power 4.0))
(tween/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 0.0 1.0 1.0 :ease tween/ease-in-quadratic))
(assoc-in [:tweens :bloodclot-appear]
(utils/tween :bloodclot-appear screen [:room :entities :bloodclot :opacity] 0.0 1.0 1.0 :power 4.0))))
(tween/tween :bloodclot-appear screen [:room :entities :bloodclot :opacity] 0.0 1.0 1.0 :ease tween/ease-in-quadratic))))
(continue [this screen entities]
entities)

View File

@@ -4,6 +4,7 @@
[advent.actions :as actions]
[advent.screens.items :as items]
[advent.utils :as utils]
[advent.tween :as tween]
[clojure.zip :as zip]
[clojure.set :as set]
[clojure.string :as str]
@@ -16,7 +17,8 @@
(defn taunt [screen entities]
(when (and (not (get-in entities [:actions :script-running?]))
(get-in entities [:state :active?])
(not (get-in entities [:state :blergh-dead?])))
(not (get-in entities [:state :blergh-dead?]))
(not (actions/has-item? entities :magic-slingshot)))
((actions/get-script entities (actions/do-dialogue entities :bloodclot-head (rand-nth ["Come on, little man! Try and hit me!"
"What's the matter? Cold feet?"
"Come here and fight me like man!"
@@ -24,6 +26,18 @@
"Pick up your weapon and fight!"]))) entities))
nil)
(defn shock [screen entities]
(when (and (not (get-in entities [:actions :script-running?]))
(get-in entities [:state :active?])
(not (get-in entities [:state :blergh-dead?]))
(actions/has-item? entities :magic-slingshot))
((actions/get-script entities
(sound! (sound "space/shock.ogg") :play)
(actions/play-animation entities :bloodclot-head :shoot :stop? false)
(actions/begin-animation entities :bloodclot-head :keep-shoot)
(actions/do-dialogue entities :bloodclot-head "Dang! Come a little closer!"))
entities))
nil)
(defn start-swing-if-necessary [screen e]
(if (and (not= (:anim e) :swing)
@@ -34,7 +48,7 @@
(defn start-fade-if-necessary [e screen]
(if (and (nil? (get-in e [:tweens :flash]))
(< (get-in e [:room :entities :ego :y]) 100))
(assoc-in e [:tweens :flash] (utils/tween :flash screen [:white-fade :opacity] 0.0 1.0 0.5 :power 3.0))
(assoc-in e [:tweens :flash] (tween/tween :flash screen [:white-fade :opacity] 0.0 1.0 0.5 :ease tween/ease-in-cubic))
e))
(defn bloodclot-disappear [entities]
@@ -45,9 +59,9 @@
(sound! (sound "inside-house/disappear.ogg") :play)
(-> entities
(assoc-in [:tweens :bloodclot-head-appear]
(utils/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 1.0 0.0 1.0 :power 4.0))
(tween/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 1.0 0.0 1.0 :ease tween/ease-in-cubic))
(assoc-in [:tweens :bloodclot-appear]
(utils/tween :bloodclot-appear screen [:room :entities :bloodclot :opacity] 1.0 0.0 1.0 :power 4.0))))
(tween/tween :bloodclot-appear screen [:room :entities :bloodclot :opacity] 1.0 0.0 1.0 :ease tween/ease-in-cubic))))
(continue [this screen entities]
entities)
@@ -82,25 +96,25 @@
:scale-y 0.5
:opacity 0.5
:baseline 240))
(assoc-in [:tweens :cloud-up] (utils/tween :cloud-up screen [:room :entities :cloud :y]
(assoc-in [:tweens :cloud-up] (tween/tween :cloud-up screen [:room :entities :cloud :y]
(get-in entities [:room :entities :ego :y])
(+ (get-in entities [:room :entities :ego :y]) 20)
1.0))
(assoc-in [:tweens :cloud-fade] (utils/tween :cloud-fade screen [:room :entities :cloud :opacity]
(assoc-in [:tweens :cloud-fade] (tween/tween :cloud-fade screen [:room :entities :cloud :opacity]
0.5
0.0
1.0))
(assoc-in [:tweens :cloud-grow] (utils/tween :cloud-grow screen [:room :entities :cloud :scale-y]
(assoc-in [:tweens :cloud-grow] (tween/tween :cloud-grow screen [:room :entities :cloud :scale-y]
0.5
2.5
1.0))
(assoc-in [:tweens :cloud-grow-2] (utils/tween :cloud-grow-2 screen [:room :entities :cloud :scale-x]
(assoc-in [:tweens :cloud-grow-2] (tween/tween :cloud-grow-2 screen [:room :entities :cloud :scale-x]
0.5
2.5
1.0))
(update-in [:room :entities :ego]
#(actions/start-animation screen % :jump))
(assoc-in [:tweens :jump-pos] (utils/tween :jump-pos screen [:room :entities :ego :move-pct] 0.0 1.0 jump-duration :power 2))))
(assoc-in [:tweens :jump-pos] (tween/tween :jump-pos screen [:room :entities :ego :move-pct] 0.0 1.0 jump-duration :ease tween/ease-in-quadratic))))
(continue [this screen entities]
(let [v (vector-2 0 0)
@@ -122,7 +136,7 @@
(-> entities
(update-in [:room :entities :ego]
#(actions/start-animation screen % :swing))
(assoc-in [:tweens :swing-pos] (utils/tween :swing-pos screen [:room :entities :ego :move-pct] 0.0 1.0 swing-duration :power 10))))
(assoc-in [:tweens :swing-pos] (tween/tween :swing-pos screen [:room :entities :ego :move-pct] 0.0 1.0 swing-duration :ease tween/ease-in-dectic))))
(continue [this screen entities]
(let [v (vector-2 0 0)
@@ -143,7 +157,7 @@
false))
(actions/run-action entities
(begin [this screen entities]
(assoc-in entities [:tweens :flash] (utils/tween :flash screen [:white-fade :opacity] 1.0 0.0 3.0 :power 2.0)))
(assoc-in entities [:tweens :flash] (tween/tween :flash screen [:white-fade :opacity] 1.0 0.0 3.0 :ease tween/ease-in-quadratic)))
(continue [this screen entities]
entities)
@@ -172,7 +186,8 @@
:interactions
{}
:layers [(assoc (texture "space/background.png") :x 0 :y 0 :baseline 0)]
:timers {:taunt [10.0 8.0 taunt]}
:timers {:taunt [10.0 8.0 taunt]
:shock [5.0 1.0 shock]}
:entities {:appear (assoc effect
:x 240 :y 50
:baseline 200)

View File

@@ -12,6 +12,7 @@
[advent.actions :as actions]
[advent.zone :as zone]
[advent.utils :as utils]
[advent.tween :as tween]
[advent.screens.rooms :as rooms]
[advent.screens.rooms.common :as common]
[advent.screens.items :as items]
@@ -33,7 +34,7 @@
[advent.screens.inventory :refer [inventory-screen]]
[clojure.core.async :refer [put! <! <!! >! chan go thread take! alts!!]])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter GL20 GL30]
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.graphics.g2d TextureRegion Animation]
[java.lang Object]
[com.badlogic.gdx Gdx]))
@@ -65,7 +66,7 @@
((:mouse-in? (:inventory entities)) x y)
(click-inventory screen entities)
(utils/intersects? (:close entities) [x y])
(assoc-in entities [:tweens :fade-out] (utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 :finish #(do (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen))
(assoc-in entities [:tweens :fade-out] (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 :finish #(do (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen))
%)))
:else
@@ -341,7 +342,7 @@
(defn get-animation-point [animation total-time]
(defn get-animation-point [^Animation animation total-time]
(loop [time total-time]
(if (> (- time (animation! animation :get-animation-duration)) 0)
(recur (- time (animation! animation :get-animation-duration)))
@@ -391,77 +392,81 @@
:on-show
(fn [screen entities]
(let [screen (assoc screen :total-time 0)]
(update! screen :renderer (stage) :camera (orthographic))
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
rooms {:inside-house (rooms.inside-house/make screen)
:inside-stash (rooms.inside-stash/make screen)
:outside-house (rooms.outside-house/make screen)
:behind-house (rooms.behind-house/make screen)
:cat-tree (rooms.cat-tree/make screen)
:inside-castle (rooms.inside-castle/make screen)
:space (rooms.space/make screen)
:inside-cafeteria (rooms.inside-cafeteria/make screen)
:inside-antique (rooms.inside-antique/make screen)
:inside-jail (rooms.inside-jail/make screen)
:dream (rooms.dream/make screen)
:castle-gate (rooms.castle-gate/make screen)
:outside-jail (rooms.outside-jail/make screen)
:outside-castle (rooms.outside-castle/make screen)}
entities {:rooms rooms
:musics {:object nil
:inside-antique (utils/make-music "inside-antique.ogg")
:town-1 (utils/make-music "town-music-1.ogg")
:town-2 (utils/make-music "town-music-2.ogg")
:inside-fangald (utils/make-music "inside-fangald.ogg")
:fight (utils/make-music "megaboss.mp3")
:pull-sword (utils/make-music "pull-sword.ogg")
:night (utils/make-music "night.ogg")}
:state (get-state)
:fade (assoc (texture "black.png")
:scale-x 20
:scale-y 20
:baseline 9500
:opacity 0.0)
:white-fade (assoc (texture "white.png")
:scale-x 20
:scale-y 20
:baseline 9500
:opacity 0.0)
:actions {:object nil
:channel (chan)
:current nil
:script-running? false
:started? false}
:volume {:object nil
:value 0.0}
:music-override {:object nil
:value nil}
:close (assoc (texture "close.png") :x 304 :y 224 :width 16 :height 16 :baseline 9000)
:cursor {:id "cursor"
:current :main
:last :main
:override nil
:last-pos [0 0]}
:tweens {:fade-in (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.5 :power 3.0)
:fade-in-music (utils/tween :fade-in-music screen [:volume :value] 0.0 1.0 1.5 :power 3.0)}
:all-items (assoc items/items :object nil)
:room (as-> (get rooms (:last-room (get-state))) room
(assoc-in room [:entities :ego] (get-ego screen (:start-pos room) ((:scale-fn room) (:start-pos room)))))
:inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000
:mouse-in? (zone/box 278 0 320 42))
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 0)}]
(music! (utils/get-current-music entities) :set-volume (get-in entities [:volume :value]))
(let [cam (orthographic)]
(set! (. cam zoom) 0.95)
(update! screen :renderer (stage) :camera cam)
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
rooms {:inside-house (rooms.inside-house/make screen)
:inside-stash (rooms.inside-stash/make screen)
:outside-house (rooms.outside-house/make screen)
:behind-house (rooms.behind-house/make screen)
:cat-tree (rooms.cat-tree/make screen)
:inside-castle (rooms.inside-castle/make screen)
:space (rooms.space/make screen)
:inside-cafeteria (rooms.inside-cafeteria/make screen)
:inside-antique (rooms.inside-antique/make screen)
:inside-jail (rooms.inside-jail/make screen)
:dream (rooms.dream/make screen)
:castle-gate (rooms.castle-gate/make screen)
:outside-jail (rooms.outside-jail/make screen)
:outside-castle (rooms.outside-castle/make screen)}
entities {:rooms rooms
:cam {:value cam
:object nil}
:musics {:object nil
:inside-antique (utils/make-music "inside-antique.ogg")
:town-1 (utils/make-music "town-music-1.ogg")
:town-2 (utils/make-music "town-music-2.ogg")
:inside-fangald (utils/make-music "inside-fangald.ogg")
:fight (utils/make-music "megaboss.mp3")
:pull-sword (utils/make-music "pull-sword.ogg")
:night (utils/make-music "night.ogg")}
:state (get-state)
:fade (assoc (texture "black.png")
:scale-x 20
:scale-y 20
:baseline 9500
:opacity 0.0)
:white-fade (assoc (texture "white.png")
:scale-x 20
:scale-y 20
:baseline 9500
:opacity 0.0)
:actions {:object nil
:channel (chan)
:current nil
:script-running? false
:started? false}
:volume {:object nil
:value 0.0}
:music-override {:object nil
:value nil}
:close (assoc (texture "close.png") :x 304 :y 224 :width 16 :height 16 :baseline 9000)
:cursor {:id "cursor"
:current :main
:last :main
:override nil
:last-pos [0 0]}
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.5 :ease tween/ease-in-cubic)
:fade-in-music (tween/tween :fade-in-music screen [:volume :value] 0.0 1.0 1.5 :ease tween/ease-in-cubic)}
:all-items (assoc items/items :object nil)
:room (as-> (get rooms (:last-room (get-state))) room
(assoc-in room [:entities :ego] (get-ego screen (:start-pos room) ((:scale-fn room) (:start-pos room)))))
:inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000
:mouse-in? (zone/box 278 0 320 42))
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 0)}]
(music! (utils/get-current-music entities) :set-volume (get-in entities [:volume :value]))
(utils/play-sound (get-in entities [:musics (actions/get-music (get-in entities [:room :music]) (get-in entities [:state :time]))]))
(utils/play-sound (get-in entities [:musics (actions/get-music (get-in entities [:room :music]) (get-in entities [:state :time]))]))
(doseq [[k [start time fn]] (get-in entities [:room :timers])]
(add-timer! screen k start time))
#_(when (not (get-in entities [:state :seen-intro?]))
((actions/get-script entities (rooms.dream/do-intro entities)) entities))
(if-let [apply-state (get-in entities [:room :apply-state])]
(apply-state entities)
entities))))
(doseq [[k [start time fn]] (get-in entities [:room :timers])]
(add-timer! screen k start time))
#_(when (not (get-in entities [:state :seen-intro?]))
((actions/get-script entities (rooms.dream/do-intro entities)) entities))
(if-let [apply-state (get-in entities [:room :apply-state])]
(apply-state entities)
entities)))))
:on-render
(fn [screen [entities]]
@@ -487,15 +492,19 @@
layers (get-layers entities)
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]
(set! (. (:value (:cam entities)) zoom) (:zoom (:cam entities) 1.0))
(set! (.. (:value (:cam entities)) position x) (:x (:cam entities) 160.0))
(set! (.. (:value (:cam entities)) position y) (:y (:cam entities) 120.0))
(play-key-sounds (get-in entities [:room :entities]))
(doseq [m (vals (get-in entities [:musics]))]
(when m
(music! m :set-volume (get-in entities [:volume :value]) )))
(music! m :set-volume (get-in entities [:volume :value]))))
(label! (:fps entities) :set-text (str (game :fps)))
(render! screen (sort-by :baseline all-entities))
#_(render! screen [(:fps entities)])
(render! screen [(:fps entities)])
entities))
:on-resize (fn [screen entities]

View File

@@ -4,6 +4,7 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[advent.utils :as utils]
[advent.tween :as tween]
[advent.screens.scene :as scene]
[advent.screens.dialogue :as dialogue]
[advent.screens.title :as title]
@@ -52,9 +53,9 @@
:start-showing? false
:start-playing start-playing
:quit quit
:tweens {:fade-in (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
:finish #(do (utils/play-sound (:music %)) %)
:power 10.0)}
:ease tween/ease-in-quadratic)}
}))
:on-render
@@ -79,22 +80,22 @@
(utils/intersects? (:start-playing entities) [x y])
(-> entities
(assoc-in [:tweens :fade-out]
(utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 2.0
(tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0
:finish (fn [entities]
(utils/stop-sound (:music entities))
(set-screen! @(resolve 'advent.core/advent) scene/scene dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen safe/safe-screen)
entities)
:power 3.0))
:ease tween/ease-in-cubic))
(assoc-in [:tweens :fade-out-music]
(utils/tween :fade-out-music screen [:volume] 1.0 0.0 1.8)))
(tween/tween :fade-out-music screen [:volume] 1.0 0.0 1.8)))
(utils/intersects? (:quit entities) [x y])
(-> entities
(assoc-in [:tweens :fade-out]
(utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 2.0
(tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0
:finish (fn [entities]
(System/exit 0)
entities)
:power 3.0)))
:ease tween/ease-in-cubic)))
:else
nil)))

View File

@@ -125,20 +125,7 @@
(defn make-music [r]
(doto (music r) (music! :set-looping true)))
(defn tween [id screen path start end duration & {:keys [finish power]}]
(let [power (or power 1.0)
finish (or finish identity)
start-time (or (:total-time screen) 0.0)
delta (- end start)]
(fn [e total-time]
(let [delta-time (- total-time start-time)
pct-done (min (/ delta-time duration) 1.0)
pct-done (Math/pow pct-done power)
e (assoc-in e path (+ start (* pct-done delta)))]
(if (= 1.0 pct-done)
(update-in (finish e) [:tweens] dissoc id)
e)
))))
(defn apply-tweens [screen entities tweens]
(reduce (fn [e f]