(ns advent.screens.rooms.inside-house (:require [advent.screens.items :as items] [advent.screens.rooms :as rooms] [advent.screens.rooms.common :as common] [advent.screens.safe :as safe] [advent.actions :as actions] [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 open-safe [entities] (screen! safe/safe-screen :show-screen :success (actions/get-script entities (if (actions/has-item? entities :recipe) (do (actions/play-animation entities :ego :squat) (actions/talk entities :ego "I already took everything interesting from there.")) (do (actions/talk entities :ego "Yes! That worked.") (actions/talk entities :ego "Let's see here...") (actions/play-animation entities :ego :squat) (actions/talk entities :ego "No, that's a recipe to turn someone into a professional dancer...") (actions/play-animation entities :ego :squat) (actions/talk entities :ego "Here's a recipe to make everything taste like cotton candy. I'll just put that back.") (actions/play-animation entities :ego :squat) (actions/give entities :recipe) (actions/talk entities :ego "Aha! Here it is! I found a recipe for a strength potion!") (actions/talk entities :ego "Looks like there's something else in here too...") (actions/play-animation entities :ego :squat) (actions/give entities :mandrake) (actions/talk entities :ego "Weird. It's some kind of root.")))) :failure (actions/get-script entities (actions/talk entities :ego "I don't think that worked..."))) (actions/update-state entities #(assoc % :active? false))) (defn do-wizard-dialogue [entities] (actions/do-dialogue entities :wizard "What can I do for you boy?") (actions/present-choices entities {:choices ["Can you teach me the ways of magic?" {:run #(actions/respond entities % :wizard "The ways of magic?" :wizard "Magic ability is innate, it cannot be learned." :ego "How did you learn then?" :wizard "I didn't." :wizard "When I was a toddler, I sneezed, and blew up my parents house." :wizard "I've been casting magic spells ever since.") :choices actions/previous-choices} "What's with the safe?" {:run #(actions/respond entities % :wizard "That's my MagiSafe 5000." :wizard "It's used to keep whipper-snappers like you out of my precious belongings." :wizard "It's a magical safe only opened when the correct musical password is entered." :ego "What's the password?" :wizard "That's for me to know, and you not to find out.") :choices actions/previous-choices} (when (not (actions/has-obtained-all-of? entities [:trophy :medal :kiss])) "About that prophecy...") {:run #(actions/respond entities % :wizard "To become a knight you will need to be worthy in courage, wisdom, and might." :wizard "Only then can you become worthy to pull the Sword of Blergh.") :choices [(when (not (actions/has-obtained? entities :trophy)) "How can I prove that I'm worthy in wisdom?") {:run #(actions/respond entities % :wizard "Every year we have the annual Town of Remington Junior Smarty Pants Derby." :wizard "The whole town gets together to vote on who is the wisest in town, by a game of riddles." :wizard "Last year's winner was a young man named Brian O'Brainy, in town." :wizard "Maybe you can ask him.") :choices actions/previous-choices} (when (not (actions/has-obtained? entities :medal)) "Can you make some kind of potion to make me strong?") {:run #(do (actions/respond entities % :wizard "Of course I could." :wizard "I keep all sorts of potion recipes in my MagiSafe 5000.") (actions/talk entities :wizard "I can turn a weakling into an olympic lifter." :anim :talk-angry :stop? false) (actions/talk entities :wizard "A flea into a lion!" :anim :talk-angry :stop? false) (actions/talk entities :wizard "A klutz into a ballet dancer!" :anim :talk-angry :stop? true) (actions/do-dialogue entities :wizard "But that would be cheating wouldn't it?" :wizard "You need to concoct your own way to become strong.")) :choices actions/previous-choices} (when (not (actions/has-obtained? entities :kiss)) "Aren't I already courageous enough?") {:run #(actions/respond entities % :wizard "When was the last time you rescued a damsel in distress?" :ego "Erm..." :wizard "Fought a firebreathing dragon?" :ego "Umm..." :wizard "Saved an old lady from a burning building?" :wizard "Stave off zombies from the eternal graveyard?" :wizard "Rescued a stranded cat?" :ego "I haven't done any of those things!" :wizard "Seems to me you have to go do some heroic deeds!") :choices actions/previous-choices} "But what about that last part?" {:run #(actions/respond entities % :ego "You know, 'One final test remains, behold!'" :ego "What final test, Gandarf?" :wizard "Nobody knows, boy." :wizard "Some say you must fight the ghost of its prior owner." :wizard "Some say you'll be struck by lightning." :wizard "Others say you'll go through an inter-dimensional portal to a land filled with snake men." :wizard "Whatever it is, it won't be easy for you!") :choices actions/previous-choices} "Something else." {:choices actions/something-else}]} (when (actions/has-obtained-all-of? entities [:trophy :medal :kiss]) "About that prophecy...") {:run #(actions/respond entities % :wizard "It looks to me as if you are ready to pull the sword, boy!") :choices actions/previous-choices} (when (= 3 (get-in @entities [:state :mints-eaten])) "Someone ate all of the antique shopkeeper's fire mints.") {:run #(do (actions/respond entities % :wizard "Already?" :wizard "Ok, I'll deliver some more myself. Don't touch anything while I'm gone.") (actions/update-state entities (fn [s] (assoc s :mints-eaten 0 :wizard-left? true))) (sound! (sound "inside-house/disappear.ogg") :play (utils/current-sound-volume)) (actions/play-animation entities :wizard :disappear :stop? false) (actions/remove-entity entities :wizard))} "Nevermind." {:run #(actions/do-dialogue entities :ego %)}]})) (defn make [screen] (let [safelock-sheet (texture! (texture "inside-house/safe-lock.png") :split 9 2) safe-lock (animation 0.1 (for [i (flatten [(repeat 20 0) 1 2 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 (range 3 20) 20 20 20 20 21 21 21 21 21 20 20 21 21 21 21 21 20 20 20 ])] (aget safelock-sheet 0 i))) candle (utils/make-anim (texture "inside-house/candle.png") [34 32] 0.2 [1 0 1 2]) candle-aura (utils/make-anim (texture "inside-house/candle-aura.png") [27 27] 0.2 [0 1 2 3 2 1] ) experiment-left (utils/flip (utils/make-anim (texture "wizard/experiment.png" ) [45 55] 0.075 [0 0 0 0 0 0 0 0 0 0 1 1 2 2 2 2 3 3 3 4 4 5 5 6 6 6 6 6 6 7 8 9 9 10 10 11 11 12 12 12 12 12 12 12 12 12 12 12 13 13 14 14 14 14 14 15 15 16 16 17 17 18 18 18 18 19 20 21 21 21 21 21 21 22 23 22 23 22 23 22 23 23 23 23 23 23 23 23 24 24 24 24 24 24 24 24 24 25 26 27 37 38 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 29 29 29 28 28 28 28 29 29 28 28 28 28 28 28 28 28 30 30 30 30 31 32 33 31 31 31 31 31 31 31 31 34 35 36 36 36 36 36 36 36 36 36] ))] (rooms/make :music :inside-fangald :interactions {:down-dir {:box [151 0 320 40] :script (actions/get-script entities (actions/update-state entities #(assoc % :wizard-left? false)) (actions/walk-to entities :ego [237 1] :stop? false :skip-type :end) (actions/walk-straight-to entities :ego [245 -60]) (actions/transition-background entities :outside-house [257 90] :face :left)) :cursor :down} :safe {:box [34 70 70 115] :script (actions/get-script entities (actions/walk-to entities :ego [59 65]) (if (get-in @entities [:room :entities :wizard]) (actions/talk entities :wizard "Don't touch my MagiSafe!!") (open-safe entities)))} :knight {:box [71 70 102 190] :script (actions/get-script entities (actions/talk entities :ego "Maybe when I am an older knight, Gandarf will give me his armor!"))} :shelves {:box [215 100 320 220] :script (actions/get-script entities (actions/talk entities :ego "His shelves are full of books and strange ingredients."))} :window {:box [119 120 203 190] :script (actions/get-script entities (actions/talk entities :ego "It's a really big window!"))}} :layers [(assoc (texture "inside-house/background.png") :x 0 :y 0 :baseline 0) (assoc (texture "inside-house/desk.png") :x 0 :y 0 :baseline 200) (assoc (texture "inside-house/sillhoute.png") :x 0 :y 0 :baseline 240 :parallax 2.0) (assoc (texture "inside-house/glow.png") :x 0 :y 0 :baseline 199 :additive? true)] :entities { :wizard (common/make-wizard screen {:x 228 :y 60 :baseline 160 :scale-x 1.75 :scale-y 1.75 :origin-x 0 :origin-y 0 :script (actions/get-script entities (do-wizard-dialogue entities)) :scripts #(condp = % :kiss (actions/get-script entities (actions/do-dialogue entities :wizard "Good job boy! You saved a damsel in distress." :wizard "You have proven yourself worthy in courage.")) :medal (actions/get-script entities (actions/do-dialogue entities :wizard "So you beat Captain McHulk at arm wrestling? " :wizard "You must have been working out!")) :trophy (actions/get-script entities (actions/do-dialogue entities :wizard "My, my, you have proven your worth in wisdom!" :wizard "One day you'll be as wise as me!")) :recipe (actions/get-script entities (actions/do-dialogue entities :ego "I probably shouldn't show him that I have his stolen posessions.")) :frog-legs (actions/get-script entities (actions/do-dialogue entities :ego "I probably shouldn't show him that I have his stolen posessions.")) :mandrake (actions/get-script entities (actions/do-dialogue entities :ego "I probably shouldn't show him that I have his stolen posessions.")) :flask-1 (actions/get-script entities (actions/do-dialogue entities :wizard "You can keep the flask.")) (actions/get-script entities (actions/do-dialogue entities :wizard "No thank you.")))}) :safe-lock (actions/start-animation screen (assoc (animation->texture screen safe-lock) :x 51 :y 95 :baseline 145 :stand safe-lock) :stand) :candle (assoc (animation->texture screen candle) :x 157 :y 92 :baseline 200 :anim candle :anim-start 0 :script (actions/get-script entities (actions/do-dialogue entities :ego "It's just a candle."))) :candle-aura (assoc (animation->texture screen candle-aura) :x 172 :y 97 :baseline 239 :additive? true :origin-x 13 :opacity 0.5 :anim candle-aura :anim-start 0) :candle-smoke (doto (assoc (particle-effect "inside-house/candle") :x 172 :y 112 :baseline 200) (particle-effect! :set-position 172 112)) :magic-frog-particle (doto (assoc (particle-effect "inside-house/magic-frog") :x 230 :y 0 :baseline 241) (particle-effect! :set-position 237 0)) :flask (assoc (texture "inside-house/flask.png") :x 265 :y 80 :baseline 240 :script (actions/get-script entities (actions/remove-entity entities :flask) (actions/give entities :flask-1) (when (get-in @entities [:room :entities :wizard]) (actions/do-dialogue entities :ego "Hey you think I could have this flask?" :wizard "Sure.")))) :frog-legs (assoc (texture "inside-house/frog-legs.png") :x 180 :y 77 :baseline 240 :script (actions/get-script entities (if (get-in @entities [:room :entities :wizard]) (actions/do-dialogue entities :wizard "Hey, I need those frog legs for one of my spells!") (do (actions/give entities :frog-legs) (actions/remove-entity entities :frog-legs) (actions/do-dialogue entities :ego "Eww. Frog legs.")))))} :experiment (rooms/make-entity :experiment (assoc (animation->texture screen experiment-left) :x 228 :y 60 :scale-x 1.75 :scale-y 1.75 :origin-x 13 :origin-y 0 :experiment experiment-left :baseline 225)) :collision "inside-house/collision.png" :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.75) :apply-state (fn [_ entities] (utils/fast-forward-particle (get-in entities [:room :entities :candle-smoke])) (as-> entities entities (if (actions/has-obtained? entities :flask-1) (update-in entities [:room :entities] #(dissoc % :flask)) entities) (if (actions/has-obtained? entities :frog-legs) (update-in entities [:room :entities] #(dissoc % :frog-legs)) entities) (if (get-in entities [:state :wizard-left?]) (update-in entities [:room :entities] #(dissoc % :wizard)) entities))) :start-pos [237 0])))