305 lines
24 KiB
Clojure
305 lines
24 KiB
Clojure
(ns advent.screens.rooms.outside-jail
|
|
(:require [advent.screens.rooms :as rooms]
|
|
[advent.screens.rooms.common :as common]
|
|
[advent.actions :as actions]
|
|
[advent.screens.items :as items]
|
|
[advent.utils :as utils]
|
|
[clojure.zip :as zip]
|
|
[play-clj.core :refer :all]
|
|
[play-clj.ui :refer :all]
|
|
[play-clj.utils :refer :all]
|
|
[play-clj.g2d :refer :all]))
|
|
|
|
(defn add-spear-if-necessary [entities]
|
|
(if (and (not (actions/has-obtained? entities :spear))
|
|
(get-in entities [:state :dropped-ball?]))
|
|
(assoc-in entities [:room :entities :spear] (get-in entities [:room :spear]))
|
|
entities))
|
|
|
|
(defn add-clock-if-necessary [entities]
|
|
(if (and (not (actions/has-obtained? entities :broken-clock))
|
|
(not (actions/has-item? entities :alarm-clock))
|
|
(actions/has-obtained? entities :alarm-clock))
|
|
(assoc-in entities [:room :entities :alarm-clock] (get-in entities [:room :alarm-clock]))
|
|
entities))
|
|
|
|
(defn add-rope-if-necessary [entities]
|
|
(if (and (actions/has-obtained? entities :rope)
|
|
(not (actions/has-item? entities :rope))
|
|
(get-in entities [:state :knows-about-stash?]))
|
|
(assoc-in entities [:room :entities :rope] (get-in entities [:room :rope]))
|
|
entities))
|
|
|
|
(defn make-night [entities]
|
|
(-> entities
|
|
(assoc-in [:room :entities :guard] (get-in entities [:room :guard]))
|
|
add-spear-if-necessary
|
|
add-clock-if-necessary
|
|
(assoc-in [:room :entities :stash] (get-in entities [:room :stash]))
|
|
add-rope-if-necessary))
|
|
|
|
(defn search-guard [entities]
|
|
(actions/walk-to entities :ego [121 75] :face :left)
|
|
(actions/play-animation entities :ego :squat)
|
|
(if (actions/has-obtained? entities :sack-lunch)
|
|
(actions/talk entities :ego "He doesn't have anything else on him.")
|
|
(do (actions/do-dialogue entities
|
|
:ego "He has a sack lunch here."
|
|
:ego "UGH! Gross! It's got blue cheese dressing on it!")
|
|
(actions/play-animation entities :ego :get-sick)
|
|
(actions/give entities :sack-lunch))))
|
|
|
|
(defn grab-spear [entities]
|
|
(actions/walk-to entities :ego [76 49] :face :left)
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/remove-entity entities :spear)
|
|
(actions/give entities :spear)
|
|
(actions/talk entities :ego "I guess he won't need this anymore."))
|
|
|
|
(defn interact-with-lever [entities]
|
|
(cond (get-in @entities [:room :entities :rope])
|
|
(do (actions/walk-to entities :ego [48 36] :face :left)
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/give entities :rope)
|
|
(actions/remove-entity entities :rope))
|
|
(get-in @entities [:state :knows-about-stash?])
|
|
(do
|
|
(actions/walk-to entities :ego [48 36] :face :left)
|
|
(actions/play-animation entities :ego :reach-start :stop? false)
|
|
(actions/play-animation entities :stash :open :stop? false)
|
|
(Thread/sleep 500)
|
|
(actions/play-animation entities :ego :reach-stop :stop? false)
|
|
(actions/play-animation entities :stash :close :stop? false)
|
|
(actions/talk entities :ego "That trapdoor closes as soon as I let the lever go!"))
|
|
(= (get-in @entities [:state :time]) :night)
|
|
(do
|
|
(actions/walk-to entities :ego [48 36] :face :left)
|
|
(actions/talk entities :ego "Looks like a candle to me."))
|
|
|
|
:else
|
|
(do
|
|
(actions/walk-to entities :ego [48 36] :face :left)
|
|
(actions/do-dialogue entities :ego "Just a candle."
|
|
:ego "It's just not lit during the day."))))
|
|
|
|
(defn try-to-go-in-stash [entities]
|
|
(when (get-in @entities [:room :entities :rope])
|
|
(actions/walk-to entities :ego [167 100] :face :right)
|
|
(actions/talk entities :ego "Here goes nothing!")
|
|
(actions/play-animation entities :ego :squat)
|
|
(actions/play-animation entities :stash :open :stop? false)
|
|
(actions/walk-straight-to entities :ego [212 97])
|
|
(actions/transition-background entities :inside-stash [118 96])
|
|
(actions/walk-straight-to entities :ego [142 96])
|
|
(actions/talk entities :ego "This must be Frankie Rockfist's secret stash!")))
|
|
|
|
(defn fountain-vol [entities]
|
|
(utils/proximity-volume entities [172 120] :scale 0.5))
|
|
|
|
(defn make [screen]
|
|
(let [guard-sheet (texture! (texture "inside-cafeteria/ladder-guard.png") :split 37 87)
|
|
guard-stand (animation 0.1 [(aget guard-sheet 0 0)])
|
|
guard-talk (animation 0.2 (for [i [0 0 0 0 1 0 0 1]] (aget guard-sheet 0 i)))
|
|
guard-sleep (utils/make-anim "outside-jail/guard-sleep.png" [43 67] 0.1 (range 4))
|
|
open-stash (utils/make-anim "outside-jail/open-stash.png" [58 41] 0.075 (reverse (range 5)))
|
|
close-stash (utils/make-anim "outside-jail/open-stash.png" [58 41] 0.075 (range 5))
|
|
candle-flame (utils/make-anim "outside-jail/candle.png" [20 25] 0.075 (range 4))
|
|
candle-aura (utils/make-anim (texture "outside-jail/candle-aura2.png") [135 135] 0.3 [0 1 2 1] )]
|
|
(rooms/make :music {:day :town-1 :night :night}
|
|
:interactions {:down-dir {:box [30 0 227 20]
|
|
:script (actions/get-script entities
|
|
(actions/walk-to entities :ego [159 5] :skip-type :end :stop? false)
|
|
(actions/walk-straight-to entities :ego [159 -20])
|
|
(actions/transition-background entities :inside-castle [92 150])
|
|
(actions/walk-straight-to entities :ego [79 145] :stop? false)
|
|
(actions/walk-to entities :ego [159 74] :skip-type :end))
|
|
:cursor :down}
|
|
:door {:box [22 42 46 124]
|
|
:script (actions/get-script entities
|
|
(if (= :night (get-in @entities [:state :time]))
|
|
(actions/talk entities :ego "I do NOT want to go back in there!")
|
|
(do (actions/walk-to entities :ego [50 46])
|
|
(actions/talk entities :warden "NO VISITORS!"))))}
|
|
:window {:box [62 175 80 212]
|
|
:script (actions/get-script entities
|
|
(actions/talk entities :ego "I wonder if anyone is prisoner up there?"))}
|
|
:sign {:box [5 173 61 199]
|
|
:script (actions/get-script entities
|
|
(actions/talk entities :ego "J.A.I.L. Jail. Can't you read?"))}
|
|
:my-house {:box [89 128 118 179]
|
|
:script (actions/get-script entities
|
|
(actions/talk entities :ego "That's my house. I'd rather play outside."))}
|
|
:sherrif-house {:box [138 143 160 168]
|
|
:script (actions/get-script entities
|
|
(actions/do-dialogue entities
|
|
:ego "That's the Sherrif's house."
|
|
:ego "He hates me."
|
|
:ego "All because I threw a rock through his window."
|
|
:ego "Or windows."
|
|
:ego "What's the big deal?"))}
|
|
:mchulk-house {:box [223 137 282 172]
|
|
:script (actions/get-script entities
|
|
(actions/do-dialogue entities
|
|
:ego "That's Captain McHulk's house!"
|
|
:ego "He's the mightiest knight in all of Remington."
|
|
:ego "If only I could be as strong as him one day."
|
|
))}
|
|
:stump {:box [205 68 251 89]
|
|
:script (actions/get-script entities
|
|
(actions/walk-to entities :ego [170 71] :face :right)
|
|
(actions/walk-straight-to entities :ego [188 71] :face :right)
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/update-entities entities #(assoc-in % [:room :entities :axe :opacity] 0.0))
|
|
(actions/play-animation entities :ego :axe-wood)
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/update-entities entities #(assoc-in % [:room :entities :axe :opacity] 1.0))
|
|
(actions/walk-straight-to entities :ego [170 71]))
|
|
:scripts {:alarm-clock (actions/get-script entities
|
|
(if (actions/has-item? entities :note-2)
|
|
(do
|
|
(actions/walk-to entities :ego [170 71] :face :right)
|
|
(actions/walk-straight-to entities :ego [188 71] :face :right)
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/remove-item entities :alarm-clock)
|
|
(actions/add-entity entities :alarm-clock (get-in @entities [:room :alarm-clock]))
|
|
(actions/update-entities entities #(assoc-in % [:room :entities :axe :opacity] 0.0))
|
|
(actions/play-animation entities :ego :axe)
|
|
|
|
(actions/talk entities :ego "It's split right down the middle!")
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/remove-entity entities :alarm-clock)
|
|
(actions/update-entities entities #(assoc-in % [:room :entities :axe :opacity] 1.0))
|
|
(actions/give entities :broken-clock)
|
|
(actions/walk-straight-to entities :ego [170 71]))
|
|
(actions/talk entities :ego "No reason to chop that!"))
|
|
)
|
|
:sword (actions/get-script entities (actions/talk entities :ego "I can just use the axe."))
|
|
:default (actions/get-script entities (actions/talk entities :ego "No reason to chop that!"))
|
|
:frog-legs (actions/get-script entities (actions/talk entities :ego "They're already chopped up!"))}}
|
|
:lever {:box [3 72 20 90]
|
|
:script (actions/get-script entities
|
|
(interact-with-lever entities))
|
|
:scripts {:rope (actions/get-script entities
|
|
(if (get-in @entities [:state :knows-about-stash?])
|
|
(do
|
|
(actions/walk-to entities :ego [48 36] :face :left)
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/remove-item entities :rope)
|
|
(actions/add-entity entities :rope (get-in @entities [:room :rope])))
|
|
(actions/talk entities :ego "Why would I want to burn that?")))
|
|
:recipe (actions/get-script entities
|
|
(if (= :night (get-in @entities [:state :time]))
|
|
(do
|
|
(actions/walk-to entities :ego [48 36] :face :left)
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/remove-item entities :recipe)
|
|
(actions/give entities :ash)
|
|
(actions/talk entities :ego "It burned up into ash."))
|
|
(actions/talk entities :ego "The candle's not lit right now.")))
|
|
:default (actions/get-script entities
|
|
(if (= :night (get-in @entities [:state :time]))
|
|
(actions/talk entities :ego "Why would I want to burn that?")
|
|
(actions/talk entities :ego "The candle's not lit right now.")))}}
|
|
:end-of-rope {:box [177 101 185 108]
|
|
:script (actions/get-script entities (try-to-go-in-stash entities))}
|
|
:fountain {:box [150 126 193 170]
|
|
:script (actions/get-script entities
|
|
(actions/walk-to entities :ego [151 119] :face :right)
|
|
(actions/do-dialogue entities :ego "Some would say this is life-giving nectar."
|
|
:ego "... Me?"
|
|
:ego "I'd just as soon say it's nasty public fountain water.")
|
|
(actions/play-animation entities :ego :get-sick))
|
|
:scripts {:flask-2 (actions/get-script entities
|
|
(actions/walk-to entities :ego [151 119] :face :right)
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/remove-item entities :flask-2)
|
|
(actions/give entities :flask-water)
|
|
(actions/talk entities :ego "Filled up with water, just as Gandarf wanted."))}}}
|
|
:layers {:day [(assoc (texture "outside-jail/background.png") :x 0 :y 0 :baseline 0)
|
|
(assoc (texture "outside-jail/fountain.png") :x 0 :y 0 :baseline 114)]
|
|
:night [(assoc (texture "outside-jail/background.png") :x 0 :y 0 :baseline 0)
|
|
(assoc (texture "outside-jail/fountain.png") :x 0 :y 0 :baseline 114)]}
|
|
:entities {:warden {:object nil
|
|
:x 36
|
|
:y 86
|
|
:width 10
|
|
:height 10
|
|
:talk-color (color 0.9 0.3 0.9 1.0)}
|
|
:candle-flame (assoc (animation->texture screen candle-flame)
|
|
:origin-x 8 :origin-y 11
|
|
:x 14 :y 82
|
|
:baseline 1
|
|
:night-profile :none
|
|
:anim candle-flame
|
|
:anim-start 0)
|
|
:candle-aura (assoc (animation->texture screen candle-aura) :x 14 :y 82 :baseline 240
|
|
:additive? true :origin-x 67 :origin-y 67 :scale-x 1 :scale-y 1 :opacity 0.5 :anim candle-aura :anim-start 0 :night-profile :none)
|
|
:fountain-particle (assoc (doto (particle-effect "outside-jail/fountain")
|
|
(particle-effect! :reset)
|
|
(particle-effect! :start))
|
|
:x 172
|
|
:y 140
|
|
:baseline 114)
|
|
:axe (assoc (texture "outside-jail/axe.png") :x 213 :y 63 :baseline 176 :night-profile :sprite)
|
|
:bent-bar-window (assoc (texture "outside-jail/bent-bar-window.png")
|
|
:x 69 :y (- 240 63) :baseline 2)
|
|
:outside-particles (common/make-outside-particles)}
|
|
:fountain-sound {:sound (sound "outside-jail/fountain-2.ogg")
|
|
:id nil}
|
|
|
|
|
|
|
|
|
|
|
|
:guard (rooms/make-entity :guard (assoc (animation->texture screen guard-stand)
|
|
:x 70 :y 55 :baseline 185
|
|
:stand guard-stand
|
|
:talk guard-talk
|
|
:sleep guard-sleep
|
|
:script (actions/get-script entities (search-guard entities))
|
|
:night-profile :sprite))
|
|
:rope (rooms/make-entity :rope (assoc (texture "outside-jail/rope.png")
|
|
:x 14 :y 20 :baseline 1 :night-profile :sprite))
|
|
:spear (rooms/make-entity :spear (assoc (texture "outside-jail/spear.png")
|
|
:night-profile :none
|
|
:x 60 :y 65 :baseline 180
|
|
:script (actions/get-script entities (grab-spear entities))))
|
|
:alarm-clock (rooms/make-entity :alarm-clock (assoc (texture "outside-jail/alarm-clock.png")
|
|
:x 217 :y 83 :baseline 160
|
|
:script (actions/get-script entities
|
|
(actions/walk-to entities :ego [189 65] :face :right)
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/remove-entity entities :alarm-clock)
|
|
(actions/give entities :alarm-clock))))
|
|
|
|
:stash (rooms/make-entity :stash (assoc (animation->texture screen open-stash)
|
|
:x 197 :y 94 :baseline 146
|
|
:open open-stash
|
|
:close close-stash))
|
|
|
|
:collision "outside-jail/collision.png"
|
|
:scale-fn (utils/scaler-fn-with-baseline 40 0.001 1.3)
|
|
:start-pos [145 15]
|
|
|
|
:update-fn (fn [_ entities]
|
|
(when-let [fountain-sound-id (get-in entities [:room :fountain-sound :id])]
|
|
(sound! (get-in entities [:room :fountain-sound :sound]) :set-volume fountain-sound-id (fountain-vol entities)))
|
|
entities)
|
|
|
|
:stop-fn (fn [_ entities]
|
|
(when-let [fountain-sound-id (get-in entities [:room :fountain-sound :id])]
|
|
(sound! (get-in entities [:room :fountain-sound :sound]) :stop fountain-sound-id))
|
|
entities)
|
|
|
|
:apply-state (fn [_ entities]
|
|
(utils/fast-forward-particle (get-in entities [:room :entities :outside-particles]))
|
|
|
|
(as-> entities entities
|
|
(assoc-in entities [:room :fountain-sound :id] (sound! (get-in entities [:room :fountain-sound :sound]) :loop (fountain-vol entities)))
|
|
(if (= :night (get-in entities [:state :time]))
|
|
(make-night entities)
|
|
(update-in entities [:room :entities] dissoc :candle-aura :candle-flame))
|
|
(if (get-in entities [:state :dropped-ball?])
|
|
(update-in entities [:room :entities :guard] #(actions/start-animation % :sleep))
|
|
(update-in entities [:room :entities] dissoc :bent-bar-window )))))))
|