Files
gitea-docker/desktop/src-common/advent/screens/rooms/inside_antique.clj
2014-12-14 12:04:51 -08:00

213 lines
18 KiB
Clojure

(ns advent.screens.rooms.inside-antique
(: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 do-antique-dialogue [entities]
(actions/do-dialogue entities
:shopkeep "Welcome to my antique shop!"
:shopkeep "Can I help you?")
(actions/present-choices entities
{:choices ["What do you have for sale here?"
{:run #(actions/respond entities %
:shopkeep "For sale?"
:shopkeep "This is a very UNIQUE antique shop."
:shopkeep "Nothing's for sale, sonny."
:shopkeep "It's more like a museum."
:shopkeep "You can take look around at some of my items, but nothing is for sale.")
:choices ["How do you make money then?"
{:run #(actions/respond entities %
:shopkeep "Mostly insurance claims."
:shopkeep "When you run such an impressive shop as I do, items sometimes just go missing.")
:choices actions/previous-choices}
"Is there anything here you will sell?"
{:run #(actions/respond entities %
:shopkeep "No."
:shopkeep "But I do have some free magical fire mints that Gandarf brewed up."
:shopkeep "Careful! They're spicy.")
:choices actions/previous-choices}
"So in order to continue on my quest, I'll need to solve some puzzle here?"
{:run #(actions/respond entities %
:shopkeep "I have no idea what you're talking about, sonny.")
:choices actions/previous-choices}
"Something else."
{:choices actions/something-else}]}
(when (and (get-in @entities [:state :wants-toy])
(not (get-in @entities [:state :allowed-to-keep-teddy?])))
"Listen, I really need that teddy bear you have.")
{:run #(actions/respond entities %
:shopkeep "Why?"
:shopkeep "It belonged to my long lost son."
:shopkeep "Why should I give it to you?")
:choices ["I just need it ok?"
{:run #(actions/respond entities %
:shopkeep "I'm sorry, it's not for sale.")
:choices actions/something-else}
"Your long lost son said I could have it."
{:run #(do (actions/respond entities %
:shopkeep "REALLY? You've met him?"
:ego "... erm. Yes!"
:shopkeep "If you really met him, you'll have to prove it."
:shopkeep "What is my son's name?"))
:choices ["... Bud?"
{:run #(actions/respond entities % :shopkeep "No. *sigh* That's not it.")}
"... Steve?"
{:run #(actions/respond entities % :shopkeep "No. *sigh* That's not it.")}
"... Bob?"
{:run #(actions/respond entities % :shopkeep "No. *sigh* That's not it.")}
(when ((get-in @entities [:state :clues]) :name)
"Herb.")
{:run #(do (actions/respond entities %
:shopkeep "Yes, that's it!"
:shopkeep "You must have really met my son!"
:shopkeep "Of course you can keep the teddy bear.")
(actions/update-state entities (fn [s] (assoc s :allowed-to-keep-teddy? true))))}]}]}
"How's life in the antique shop biz?"
{:run #(actions/respond entities %
:shopkeep "Pretty lonely."
:shopkeep "My long lost son used to help me run this shop, but he's been gone for five years now."
:shopkeep "I've been couped up in here by myself ever since."
:shopkeep "Now all I have is this grandfather clock to keep me company.")
:choices actions/previous-choices}
"Nevermind." {:run #(actions/respond entities % :shopkeep "Feel free to look around.")}]}))
(defn has-to-return-teddy? [entities]
(and (actions/has-item? entities :teddy)
(not (get-in @entities [:state :allowed-to-keep-teddy?]))))
(defn make [screen]
(let [shopkeep-sheet (texture! (texture "inside-antique/shopkeep-talk.png") :split 18 21)
shopkeep-stand (animation 0.1 (for [i (flatten [(repeat 30 0) 1 (repeat 50 0) 1 0 1 0 1])]
(aget shopkeep-sheet 0 i)))
shopkeep-talk (animation 0.15 (for [i [0 2 0 2 0 3 1 0]]
(aget shopkeep-sheet 0 i)))
portrait (rooms/make-entity :portrait (assoc (texture "inside-antique/portrait.png")
:x 109
:y 120
:baseline 120
:script (actions/get-script entities
(actions/walk-to entities :ego [136 80] :face :left)
(actions/play-animation entities :ego :reach)
(actions/talk entities :ego "It's a portrait. There's something on the back but I can't read it.")
(actions/remove-entity entities :portrait)
(actions/give entities :portrait))))
beard (utils/make-anim "inside-antique/beard.png" [12 32] 0.5 [0 1 0 2])
teddy (assoc (texture "inside-antique/teddy.png")
:x 250
:y 80
:baseline 160
:script (actions/get-script entities
(actions/walk-to entities :ego [220 35] :face :right)
(actions/play-animation entities :ego :reach)
(actions/give entities :teddy)
(actions/remove-entity entities :teddy)
(when (not (get-in @entities [:state :allowed-to-keep-teddy?]))
(actions/do-dialogue entities
:ego "Aww, a cute teddy bear!"
:shopkeep "Don't get any fast ideas."
:shopkeep "That teddy bear does not leave my store."))))]
(rooms/make :music :inside-antique
:interactions
{:down {:box [60 0 290 25]
:cursor :down
:script (actions/get-script entities
(when (or (actions/has-item? entities :portrait)
(has-to-return-teddy? entities))
(actions/walk-to entities :ego [222 3])
(actions/talk entities :shopkeep "Excuse me sonny. Please return my belongings before you leave.")
(when (actions/has-item? entities :portrait)
(actions/walk-to entities :ego [136 80] :face :left)
(actions/play-animation entities :ego :reach)
(actions/add-entity entities :portrait portrait)
(actions/remove-item entities :portrait))
(when (has-to-return-teddy? entities)
(actions/walk-to entities :ego [220 35] :face :right)
(actions/play-animation entities :ego :reach)
(actions/add-entity entities :teddy teddy)
(actions/remove-item entities :teddy)))
(actions/walk-to entities :ego [222 3])
(actions/transition-background entities :inside-castle [182 90]))}
:window {:box [212 130 256 180]
:script (actions/get-script entities
(actions/talk entities :ego "It's a nice, big window."))
:scripts {:portrait (actions/get-script entities
(actions/walk-to entities :ego [151 60] :face :right)
(actions/play-animation entities :ego :hold-up-to-window)
(actions/talk entities :ego "The portrait says 'Herb' on the back.")
(actions/update-state entities (fn [state] (update-in state [:clues] #(conj % :name)) )))}}
:grandfather-clock {:box [50 137 90 185]
:script (actions/get-script entities
(actions/do-dialogue entities :ego "Cool grandfather clock!"
:shopkeep "It's quite the exquisit piece, isn't it?"))}
:shelf {:box [0 40 48 210]
:script (actions/get-script entities
(actions/walk-to entities :ego [55 35])
(actions/talk entities :ego "All of these trinkets seem too bulky to fit in my pack."))}
:flowers {:box [171 125 181 155]
:script (actions/get-script entities
(actions/talk entities :ego "I've never been a fan of flowers."))}
:lian {:box [272 100 313 160]
:script (actions/get-script entities
(actions/walk-to entities :ego [220 35] :face :right)
(actions/do-dialogue entities
:ego "It's a tapestry of Rupert the Lion!"
:ego "He's the town of Remington's mascot."))}
}
:layers [(assoc (texture "inside-antique/background.png") :x 0 :y 0 :baseline 0)]
:entities {:shopkeep (actions/start-animation screen (assoc (animation->texture screen shopkeep-stand) :x 137 :y 128 :baseline 112
:stand shopkeep-stand
:talk shopkeep-talk
:script (actions/get-script entities (do-antique-dialogue entities))
:scripts {:teddy (actions/get-script entities
(if (get-in @entities [:state :allowed-to-keep-teddy?])
(actions/talk entities :shopkeep "Please give the teddy bear to Herb when you see him.")
(actions/talk entities :shopkeep "That belonged to my long lost son.")))}
)
:stand)
:portrait portrait
:beard (assoc (animation->texture screen beard)
:anim beard
:anim-start 0
:x 65
:y 109
:baseline 120)
:bowl (assoc (texture "inside-antique/bowl.png")
:x 155
:y 125
:baseline 125
:script (actions/get-script entities
(if (= 3 (get-in @entities [:state :mints-eaten]))
(do (actions/walk-to entities :ego [145 80] :face :right)
(actions/do-dialogue entities
:ego "She's all out."
:ego "Maybe Gandarf can brew her up another batch."))
(do (actions/walk-to entities :ego [145 80] :face :right)
(actions/talk entities :ego "I'll just try one of these mints.")
(actions/play-animation entities :ego :reach)
(actions/update-state entities (fn [s] (assoc s :mints-eaten (inc (s :mints-eaten)))))
(actions/play-animation entities :ego [:fire (get-in @entities [:state :mints-eaten])])
(actions/talk entities :ego "WOWZA! Those are hot.")
(when (= 3 (get-in @entities [:state :mints-eaten]))
(actions/talk entities :shopkeep "You brat! You ate the last mint.")
(actions/talk entities :shopkeep "Since you ate the last one, you have to go tell Gandarf to bring me some more."))))))
:teddy teddy}
:collision "inside-antique/collision.png"
:apply-state (fn [entities]
(as-> entities entities
(if (or (actions/has-item? entities :teddy)
(actions/has-obtained? entities :balloon))
(update-in entities [:room :entities] #(dissoc % :teddy))
entities)))
:scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.50)
:start-pos [222 3])))