(ns advent.screens.rooms.inside-cafeteria (:require [advent.screens.rooms :as rooms] [advent.screens.items :as items] [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 make-fight-entity [] (assoc (texture "inside-cafeteria/fight.png") :x 0 :y 0 :baseline 1000)) (defn play-battle [entities anim] (actions/transition-music entities :fight) (actions/pause-camera entities) (actions/add-entity entities :fight (get-in @entities [:room :fight])) (actions/add-entity entities :hands-fight (get-in @entities [:room :hands-fight])) (actions/play-animation entities :hands-fight anim) (actions/transition-music entities nil) (actions/remove-entity entities :hands-fight) (actions/remove-entity entities :fight) (actions/resume-camera entities)) (defn do-warrior-dialogue [entities] (actions/walk-to entities :ego [150 45] :face :left) (actions/talk entities :ego "Hey guys!") (actions/talk entities :warriors "Hark! Good day, young esquire.") (actions/present-choices entities {:choices ["Why dost thou speaketh in this manner?" {:run #(actions/respond entities % :warriors "`Tis a tradition!" :warriors "All knights speaketh in such a manner." :warriors "As my father instructedeth unto me as a mere lad: " :warriors "'Son, thou must speaketh in this manner.'" :warriors "And I asketh unto him:" :warriors "'But father, why musteth I speaketh in this manner?'" :warriors "'Yea, my son, for thou art a knight. And thou musteth speaketh in this manner.'" :warriors "And I toldeth unto him:" :warriors "'Thou art my father, and I am thy son. Therefore I will speaketh in this manner.'" :ego "... I think I've got the idea.") :choices actions/previous-choices} (when (not (actions/has-obtained? entities :medal)) "Can I be a knight like you guys?") {:run #(actions/respond entities % :warriors "We thinketh not, young esquire." :warriors "Thou lacketh the strength and vigor required for such a task." :warriors "To becometh a knight, thou wouldst have to best Captain McHulk in battle." :warriors "And no one durst challenge him!") :choices ["But I'm on a quest to become a knight!" {:run #(actions/respond entities % :warriors "Young esquire, thou art valiant in heart. " :warriors "Departeth henceforth and go hitherto, unto the gym.")} "I challenge Captain McHulk to an arm wrestling match to prove my strength." {:run (fn [msg] (actions/respond entities msg :warriors "Prepare thyself, thy task is not for the faint of heart.") (if (actions/has-item? @entities :flask-1-strength) (do (actions/do-dialogue entities :ego "One sec.") (sound! (sound "ego/potion.ogg") :play (utils/current-sound-volume)) (actions/play-animation entities :ego :grow :stop? false) (play-battle entities :win) (actions/do-dialogue entities :warriors "Congratulations young master. Thou art worthy in might." :warriors "Take thy servant's medal of strength.") (actions/give entities :medal) (actions/glad entities)) (do (play-battle entities :lose) (actions/do-dialogue entities :warriors "You lost, young master. Go hitherto, unto thy gym.") (actions/walk-to entities :ego [160 45]) (actions/do-dialogue entities :ego "Dang! If I only I had some kind of potion to make me strong..."))))} "Something else." {:choices actions/something-else}] } "Goodbye." {:run #(actions/respond entities % :warriors "Fare thee well, and godspeed.")}]})) (defn do-ladder-guard-dialogue [entities] (actions/walk-to entities :ego [170 45] :face :right) (actions/do-dialogue entities :ego "Hello." :ladder-guard "'Ello, young sire.") (actions/present-choices entities {:choices [(when (not (actions/has-obtained? entities :ladder)) "Nice ladder.") {:run #(actions/respond entities % :ladder-guard "Tis nice, indeed!" :ladder-guard "Belongeth to the Duke of Remington, it doth.") :choices ["Can I have it?" {:run #(actions/respond entities % :ladder-guard "No.") :choices ["Please?" {:run #(actions/respond entities % :ladder-guard "No.") :choices ["Pretty please?" {:run #(actions/respond entities % :ladder-guard "No.") :choices ["Pretty pretty please?" {:run #(actions/respond entities % :ladder-guard "No.") :choices ["Pretty pretty pretty please?" {:run #(do (actions/respond entities % :ladder-guard "Well, okay." :ladder-guard "Do not darest telleth a soul, or thou wilst bring my family dishonor!" :ladder-guard "I will shame the name of my father, Luke, and his father, Puke." :ladder-guard "Not to mention, the duke will have my head!") (actions/walk-to entities :ego [211 63] :face :right) (actions/play-animation entities :ego :reach) (actions/remove-entity entities :ladder) (actions/give entities :ladder))} "Nevermind." {:run #(actions/respond entities %)}]} "Nevermind." {:run #(actions/respond entities %)}]} "Nevermind." {:run #(actions/respond entities %)}]} "Nevermind." {:run #(actions/respond entities %)}]} "Something else." {:choices actions/something-else}]} (when (and (actions/has-obtained? entities :ladder)) "About that ladder...") {:run #(if (actions/has-item? entities :ladder?) (actions/respond entities % :ladder-guard "I trusteth it is safe in thy possession?" :ego "Yes, it sure is!" :ego "Can I borrow it a while longer?" :ladder-guard "Yes, but do not durst tell a soul!") (actions/respond entities % :ladder-guard "I trusteth it is safe in thy possession?" :ego "Ahem..." :ego "... Yes, it sure is!" :ladder-guard "I senseth some uncertainty in thine voice." :ego "No uncertainty here!")) :choices actions/previous-choices} "Why aren't you sitting and eating?" {:run #(do (actions/respond entities % :ladder-guard "I'm on duty, young sire.") (when (not (actions/has-obtained? entities :ladder)) (actions/do-dialogue entities :ladder-guard "Dost thou seeth this ladder?" :ladder-guard "Tis my duty to guardeth it." :ladder-guard "Why, if I didst sit and dineth with my friends, a hoodlum wouldst steal it."))) :choices actions/previous-choices} "What's your name?" {:run #(actions/respond entities % :ladder-guard "I am Took, son of Luke, son of Puke.") :choices actions/previous-choices} "Goodbye." {:run #(actions/respond entities % "Goodbye.")}]})) (defn make [screen] (let [#_#_warriors-stand-sheet (texture! (texture "inside-cafeteria/warriors-stand.png") :split 66 126) #_#_warriors-stand (animation 0.2 (for [i [0 0 0 0 0 0 1 1 0 0 1 1 1 0 0 2 2 2 2 3 3 3 0 0 0 2 2 2 ]] (aget warriors-stand-sheet 0 i))) #_#_ladder-guard-sheet (texture! (texture "inside-cafeteria/ladder-guard.png") :split 37 87) #_#_ladder-guard-stand (animation 0.1 [(aget ladder-guard-sheet 0 0)]) ladder-guard-stand (animation 0.1 [(texture "inside-cafeteria/ladder-guard-2.png")]) ladder-guard-talk (animation 0.1 [ (texture "inside-cafeteria/ladder-guard-2.png")]) warriors-stand (utils/make-anim "inside-cafeteria/knights-stand.png" [74 97] 0.6 (take 100 (repeatedly #(rand-int 10)))) #_#_ladder-guard-talk (animation 0.2 (for [i [0 0 0 0 1 0 0 1]] (aget ladder-guard-sheet 0 i))) base-fight (repeat 3 [0 1 0 4 0 1 0 4 0 1 0 4 0 1 0 4 0 1 0 4 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1 0 0 0 4 0 1 2 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 1 1 1 0 0 0 1 1 2 2 2 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 1 0 4 0 1 0 4 0 4 0 4 0 4 0 4 4 4 4 4 4 5 5 5 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0 ]) hands-fight-win (utils/make-anim "inside-cafeteria/hands-fight.png" [104 104] 0.075 (flatten (concat base-fight [1 1 1 1 1 0 1 0 1 2 2 1 1 2 2 1 1 2 2 2 1 1 0 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3]))) hands-fight-lose (utils/make-anim "inside-cafeteria/hands-fight.png" [104 104] 0.075 (flatten (concat base-fight [4 4 4 4 4 4 0 0 0 0 4 4 4 0 0 0 4 4 4 0 0 1 1 0 0 4 4 4 5 5 5 5 4 4 4 5 5 5 5 4 4 4 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6])))] (rooms/make :music :town-1 :interactions {:right-dir {:box [272 45 320 120] :script (actions/get-script entities (actions/walk-to entities :ego [319 50] :skip-type :end) (actions/transition-background entities :inside-castle [65 150]) (actions/walk-to entities :ego [126 80] :skip-type :end)) :cursor :right} } :layers [(assoc (texture "inside-cafeteria/background.png") :x 0 :y 0 :baseline 0) (assoc (texture "inside-cafeteria/doorway.png") :x 306 :y 34 :baseline 202) (assoc (texture "inside-cafeteria/glow.png") :y 0 :baseline 240 :additive? true :opacity 0.3) (assoc (texture "inside-cafeteria/fg.png") :x 10 :y 0 :scale-x 1.1 :scale-y 1.0 :baseline 320 :parallax 1.5) ] :entities { :warriors (actions/start-animation screen (assoc (animation->texture screen warriors-stand) :x 8 :y 19 :baseline 180 :left {:stand (utils/flip warriors-stand) :talk (utils/flip warriors-stand)} :right {:stand warriors-stand :talk warriors-stand} :facing :right :talk-color (color 1.0 0.2 0.3 1.0) :script (actions/get-script entities (do-warrior-dialogue entities)) :scripts (constantly (actions/get-script entities (actions/walk-to entities :ego [150 45] :face :left) (actions/do-dialogue entities :warriors "We are warriors. We coveteth not earthly possessions.")))) :stand) :ladder-guard (actions/start-animation screen (assoc (animation->texture screen ladder-guard-stand) :x 180 :y 70 :baseline 170 :stand ladder-guard-stand :talk ladder-guard-talk :talk-color (color 0.2 0.6 1.0 1.0) :script (actions/get-script entities (do-ladder-guard-dialogue entities)) :scripts #(actions/get-script entities (actions/walk-to entities :ego [170 45] :face :right) (actions/do-dialogue entities :ladder-guard (if (= :ladder %) "Do not durst telleth a soul about that ladder!" "No thank you, young sire.")))) :stand) :ladder (assoc (texture "inside-cafeteria/ladder.png") :x 205 :y 70 :baseline 170 :script (actions/get-script entities (actions/talk entities :ladder-guard "Do not toucheth, young sire.")))} :collision "inside-cafeteria/collision.png" :fight (make-fight-entity) :hands-fight (assoc (animation->texture screen hands-fight-win) :x 122 :y 38 :baseline 1001 :win hands-fight-win :lose hands-fight-lose) :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.3) :apply-state (fn [_ entities] (as-> entities entities (if (actions/has-obtained? entities :ladder) (update-in entities [:room :entities] #(dissoc % :ladder)) entities))) :start-pos [300 55])))