Files
gitea-docker/desktop/src-common/advent/screens/rooms/dream.clj

271 lines
18 KiB
Clojure

(ns advent.screens.rooms.dream
(:require
[clojure.core.async :as a]
[advent.screens.rooms :as rooms]
[advent.screens.rooms.common :as common]
[advent.actions :as actions]
[advent.screens.items :as items]
[advent.tween :as tween]
[advent.utils :as utils]
[clojure.zip :as zip]
[clojure.set :as set]
[clojure.string :as str]
[play-clj.core :refer :all]
[play-clj.math :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(def walk-chan (a/chan))
(defn set-opacity [entities opacity tool-opacity]
(-> entities
(assoc-in [:room :layers 0 :opacity] opacity)
(assoc-in [:room :layers 1 :opacity] opacity)
(assoc-in [:room :layers 2 :opacity] opacity)
(assoc-in [:room :layers 3 :opacity] opacity)
(assoc-in [:room :layers 4 :opacity] opacity)
(assoc-in [:room :layers 5 :opacity] opacity)
(assoc-in [:room :layers 6 :opacity] opacity)
(assoc-in [:room :entities :sword :opacity] tool-opacity)
(assoc-in [:room :entities :broom :opacity] tool-opacity)
(assoc-in [:room :entities :shovel :opacity] tool-opacity)
(assoc-in [:room :entities :fairy-godfather :opacity] opacity)
(assoc-in [:room :entities :sign :opacity] opacity)
(assoc-in [:room :entities :plaque-1 :opacity] tool-opacity)
(assoc-in [:room :entities :plaque-2 :opacity] tool-opacity)
(assoc-in [:room :entities :plaque-3 :opacity] tool-opacity)))
(defn fade-in [entities]
(actions/run-action entities
(begin [this screen entities]
(-> entities
(assoc-in [:tweens :fade-in]
(tween/tween :fade-in screen [:room :layers 0 :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quintic))))
(continue [this screen entities]
(set-opacity entities (get-in entities [:room :layers 0 :opacity] ) 0.0))
(done? [this screen entities]
(= 1.0 (get-in entities [:room :layers 0 :opacity])))
(terminate [this screen entities]
entities)
(can-skip? [this screen entities]
false)))
(defn fade-in-tools [entities]
(actions/run-action entities
(begin [this screen entities]
(-> entities
(assoc-in [:tweens :fade-in]
(tween/tween :fade-in screen [:room :entities :sword :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quintic))))
(continue [this screen entities]
(set-opacity entities 1.0 (get-in entities [:room :entities :sword :opacity])))
(done? [this screen entities]
(= 1.0 (get-in entities [:room :entities :sword :opacity])))
(terminate [this screen entities]
entities)
(can-skip? [this screen entities]
false)))
(defn read-sword-plaque [entities]
(actions/walk-to entities :ego [168 76] :face :left)
(actions/talk entities :ego "There's a plaque here.")
(actions/play-animation entities :ego :squat)
(actions/do-dialogue entities
:ego "'A noble choice to be a knight,\nBe a hero, do what's right.'"
:ego "'There's no need to shove,\nTo find your true love,'"
:ego "'Because maidens love guys with might.'"
:ego "Awesome!"
:ego "If I become a knight, maybe Georgia McGorgeous will love me!")
(actions/stop-walking entities :ego :face :right)
(actions/do-dialogue entities
:fairy-godfather "Tick, I told you that you can't be a knight."
:fairy-godfather "I think you'd be much better suited for a more menial job."
:ego "Hey! Why can't I be a knight? It's my destiny!"
:ego "And plus, it's the only way to get Georgia McGorgeous to love me!"
:ego "And this plaque here says that maidens love knights."
:fairy-godfather "As long as you're under my watch, Tick, I forbid it!"
:fairy-godfather "And you're just not cut out for it!")
(actions/update-state entities #(update-in % [:plaques-read] conj :sword)))
(defn read-broom-plaque [entities]
(actions/walk-to entities :ego [267 70] :face :right)
(actions/talk entities :ego "There's a plaque here.")
(actions/play-animation entities :ego :squat)
(actions/do-dialogue entities
:ego "'Grab the broom, and sweep that dirt!\nSweep, and mop till your arms hurt.'"
:ego "'You'll smell like a hog,\nwith stench like a fog,'"
:ego "'So with you, no girl will flirt.'")
(actions/play-animation entities :ego :sigh)
(actions/talk entities :ego "So can I at least slay ghouls with this broom?")
(actions/stop-walking entities :ego :face :left)
(actions/do-dialogue entities :fairy-godfather "Not quite, young Tick."
:fairy-godfather "This weapon is used to fight a more persistent foe."
:fairy-godfather "Dust and grime!"
:fairy-godfather "Take the broom, and cast it into the pit of fate."
:fairy-godfather "Then you can fulfill your fate as a janitor.")
(actions/update-state entities #(update-in % [:plaques-read] conj :broom)))
(defn read-shovel-plaque [entities]
(actions/walk-to entities :ego [61 72] :face :left)
(actions/talk entities :ego "There's a plaque here.")
(actions/play-animation entities :ego :squat)
(actions/do-dialogue entities
:ego "'Choose the shovel, dig some holes,\ntis the boringest of roles,'"
:ego "'You can work by night,\nBut suffer a plight:'"
:ego "'Gals dislike guys who bury souls.'")
(actions/play-animation entities :ego :sigh)
(actions/do-dialogue entities
:fairy-godfather "Don't be dismayed, young Tick."
:fairy-godfather "Remember, these destinies can't be mistaken."
:ego "But it sounds so dull!")
(actions/update-state entities #(update-in % [:plaques-read] conj :shovel)))
(defn do-intro [entities]
(Thread/sleep 2000)
(actions/do-dialogue entities
:ego "What's going on?"
:ego "Who turned out the lights?"
:ego "I must be dreaming.")
(Thread/sleep 500)
(actions/talk entities :fairy-godfather "Taaaaaaaaaaaaaaaaaa-")
(particle-effect! (get-in @entities [:room :entities :magic]) :reset)
(particle-effect! (get-in @entities [:room :entities :magic]) :start)
(Thread/sleep 500)
(fade-in entities)
(Thread/sleep 100)
(actions/talk entities :fairy-godfather "-daaaaaaaaaaaaa!")
(Thread/sleep 2500)
(actions/do-dialogue entities :ego "Umm... What was that all about?"
:fairy-godfather "Welcome, young Tick, to the pit of fate."
:ego "Err, who are you?"
:ego "And how do you know my name?"
:fairy-godfather "Why, I'm your fairy godfather of course!"
:fairy-godfather "I've brought you here, Tick, to help choose your destiny."
:fairy-godfather "Today you will choose your trade."
:fairy-godfather "Let us see what your fate could bring!"
:fairy-godfather "Behold!")
(particle-effect! (get-in @entities [:room :entities :magic]) :reset)
(particle-effect! (get-in @entities [:room :entities :magic]) :start)
(fade-in-tools entities)
(Thread/sleep 2500)
(actions/do-dialogue entities :ego "What are these things?"
:fairy-godfather "These, young Tick, represent the potential destinies for your life."
:fairy-godfather "They have been selected since the dawn of time."
:fairy-godfather "These destinies are never mistaken."
:ego "Soo, I've been destined to be a shovel since the dawn of time?"
:fairy-godfather "No, no, no!")
(actions/update-entities entities #(update-in % [:room :entities :fairy-godfather] dissoc :path))
(actions/walk-straight-to entities :fairy-godfather [60 120] :speed 3.0 :update-baseline? false)
(actions/update-entities entities (fn [e] (update-in e [:room :entities :fairy-godfather] assoc :path (catmull-rom-spline (map #(apply vector-2* %) [[60 120] [60 124]]) true))))
(actions/do-dialogue entities :fairy-godfather "This shovel represents the job of grave-digger."
:fairy-godfather "A simple job, for a simple fellow."
:ego "Hey! "
:ego "I'm not simple.")
(actions/update-entities entities #(update-in % [:room :entities :fairy-godfather] dissoc :path))
(actions/walk-straight-to entities :fairy-godfather [240 120] :speed 3.0 :update-baseline? false)
(actions/update-entities entities (fn [e] (update-in e [:room :entities :fairy-godfather] assoc :path (catmull-rom-spline (map #(apply vector-2* %) [[240 120] [240 124]]) true))))
(actions/do-dialogue entities :fairy-godfather "Next, we have the broom, representing the humble job of a janitor."
:ego "I'm not going to be a janitor!"
:ego "I'm going to take the sword and be a knight?"
:fairy-godfather "Hmm? Sword?")
(actions/update-entities entities #(update-in % [:room :entities :fairy-godfather] dissoc :path))
(actions/walk-straight-to entities :fairy-godfather [170 120] :speed 3.0 :update-baseline? false)
(actions/update-entities entities (fn [e] (update-in e [:room :entities :fairy-godfather] assoc :path (catmull-rom-spline (map #(apply vector-2* %) [[170 120] [170 124]]) true))))
(actions/do-dialogue entities
:fairy-godfather "Sword...?"
:fairy-godfather "Uh, oh. That's not right."
:fairy-godfather "Ahem."
:fairy-godfather "You must choose between being a janitor and grave-digger."
:ego "But I want to be a knight!"
:ego "And you said that these destinies are never mistaken!"
:fairy-godfather "Nevermind that."
:fairy-godfather "Choose the broom or shovel, and cast it into the pit of fate."
:ego "But..."
:fairy-godfather "No buts.")
(actions/update-state entities #(assoc % :seen-intro? true)))
(defn make [screen]
(let [fairy-godfather-anim (utils/make-anim "dream/fairy-godfather.png" [63 77] 0.15 [0 1 2 3 2 1 0 1 4 3 2 1])
fairy-godfather-talk-anim (utils/make-anim "dream/fairy-godfather.png" [63 77] 0.15 [5 6 7 8 7 6])]
(rooms/make :music :town-1
:interactions {}
:layers [(assoc (texture "dream/clouds1.png") :x -10 :y 0 :baseline -1 :parallax 0.2 :scale-x 1.1 :scale-y 1.1)
(assoc (texture "dream/island.png") :x 180 :y 180 :baseline 0 :parallax 0.3 :scale-x 1.1 :scale-y 1.1)
(assoc (texture "dream/cliff.png") :x 50 :y 133 :baseline 1 :parallax 0.6 :scale-x 1.2 :scale-y 1.2)
(assoc (texture "dream/background.png") :x 0 :y 0 :baseline 2)
(assoc (texture "dream/corner-l.png") :x -10 :y -10 :baseline 240 :parallax 2.0 )
(assoc (texture "dream/corner-r.png") :x (- 320 80) :y -20 :baseline 240 :parallax 3.2)
(assoc (texture "dream/pedestals.png") :x 0 :y 0 :baseline 139)]
:entities {:magic (assoc (particle-effect "dream/magic") :x 160 :y 80 :baseline 240)
:clouds (assoc (particle-effect "dream/cloudy2") :x 160 :y 120 :baseline 241)
:sword (assoc (texture "dream/sword.png")
:x 144 :y 122 :baseline 139
:script (actions/get-script entities
(read-sword-plaque entities)))
:broom (assoc (texture "dream/broom.png") :x 286 :y 122
:path (catmull-rom-spline (map #(apply vector-2* %) [[286 122] [286 128]]) true)
:update-fn (partial utils/update-path-location 0.30)
:baseline 240
:script (actions/get-script entities
(if ((get-in @entities [:state :plaques-read]) :broom)
(do
(actions/walk-to entities :ego [267 70] :face :right)
(actions/play-animation entities :ego :sigh)
(actions/play-animation entities :ego :reach)
(actions/remove-entity entities :broom))
(read-broom-plaque entities))))
:shovel (assoc (texture "dream/shovel.png") :x 33 :y 122
:path (catmull-rom-spline (map #(apply vector-2* %) [[22 122] [22 128]]) true)
:update-fn (partial utils/update-path-location 0.33)
:baseline 240
:script (actions/get-script entities
(if ((get-in @entities [:state :plaques-read]) :shovel)
(do
(actions/walk-to entities :ego [61 72] :face :left)
(actions/play-animation entities :ego :sigh)
(actions/play-animation entities :ego :reach)
(actions/remove-entity entities :shovel))
(read-shovel-plaque entities))))
:sign (assoc (texture "dream/sign.png") :x 229 :y 33 :baseline 207)
:plaque-1 (assoc (texture "dream/plaque1.png") :x 39 :y 99 :baseline 139 :script (actions/get-script entities (read-shovel-plaque entities)))
:plaque-2 (assoc (texture "dream/plaque2.png") :x 147 :y 104 :baseline 139 :script (actions/get-script entities (read-sword-plaque entities)))
:plaque-3 (assoc (texture "dream/plaque3.png") :x 283 :y 98 :baseline 139 :script (actions/get-script entities (read-broom-plaque entities)))
:fairy-godfather (assoc (animation->texture screen fairy-godfather-anim)
:x 200 :y 130
:baseline 240
:anim fairy-godfather-anim :anim-start 0
:path (catmull-rom-spline (map #(apply vector-2* %) [[200 130] [200 134]]) true)
:left {:walk fairy-godfather-anim
:talk fairy-godfather-talk-anim
:stand fairy-godfather-anim}
:right {:walk (utils/flip fairy-godfather-anim)
:stand (utils/flip fairy-godfather-anim)
:talk (utils/flip fairy-godfather-talk-anim)}
:facing :left
:update-fn (fn [s es e] (if (:path e)
(utils/update-path-location 0.2 s es e)
e))
:script (actions/get-script entities
(actions/do-dialogue entities :fairy-godfather "Young Tick, you must choose your destiny!")))}
:collision "dream/collision.png"
:scale-fn (utils/scaler-fn-with-baseline 40 0.5 1.6)
:apply-state (fn [entities]
(if (get-in entities [:state :seen-intro?])
(set-opacity entities 1.0 1.0)
(set-opacity entities 0.0 0.0)))
:start-pos [140 55])))