Files
gitea-docker/desktop/src-common/advent/screens/rooms/outside_jail.clj
2014-12-28 15:17:38 -08:00

129 lines
9.3 KiB
Clojure

(ns advent.screens.rooms.outside-jail
(:require [advent.screens.rooms :as rooms]
[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 make-night [entities]
(-> entities
(assoc-in [:room :entities :guard] (get-in entities [:room :guard]))
add-spear-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 "Looks like it's pretty mangled from his spill.")
(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 make [screen]
(let [fountain (utils/make-anim "outside-jail/fountain.png" [42 50] 0.2 (range 3))
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))]
(rooms/make :music :town-2
:interactions {:down-dir {:box [30 0 227 20]
:script (actions/get-script entities
(actions/walk-to entities :ego [159 5])
(actions/walk-straight-to entities :ego [159 -20])
(actions/transition-background entities :inside-castle [79 145]
)
(actions/walk-to entities :ego [159 74]))
: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."
))}}
:layers {:day [(assoc (texture "outside-jail/background.png") :x 0 :y 0 :baseline 0)]
:night [(assoc (texture "outside-jail/background-dark.png") :x 0 :y 0 :baseline 0)]}
:entities {:fountain (assoc (animation->texture screen fountain)
:x 150 :y 126 :baseline 114
:anim fountain
:anim-start 0
:script (actions/get-script entities
(actions/walk-to entities :ego [151 119] :face :right)
(actions/play-animation entities :ego :reach)
(actions/do-dialogue entities :ego "Ahh, life-giving water."
:ego "I feel strength."
:ego "And renewal!"))
: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 with water, just as Gandarf wanted."))})
:warden {:object nil
:x 36
:y 86
:width 10
:height 10
:talk-color (color 0.9 0.3 0.9 1.0)}}
: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))))
:spear (rooms/make-entity :spear (assoc (texture "outside-jail/spear.png")
:x 60 :y 65 :baseline 180
:script (actions/get-script entities (grab-spear entities))))
:collision "outside-jail/collision.png"
:scale-fn (utils/scaler-fn-with-baseline 40 0.001 1.3)
:start-pos [145 15]
:apply-state (fn [entities]
(as-> entities entities
(if (= :night (get-in entities [:state :time]))
(make-night entities)
entities)
(if (get-in entities [:state :dropped-ball?])
(update-in entities [:room :entities :guard] #(actions/start-animation % :sleep))
entities))))))