Files
gitea-docker/desktop/src-common/advent/screens/rooms/inside_castle.clj

266 lines
22 KiB
Clojure

(ns advent.screens.rooms.inside-castle
(:require [advent.screens.rooms :as rooms]
[advent.actions :as actions]
[advent.screens.items :as items]
[advent.utils :as utils]
[clojure.zip :as zip]
[clojure.set :as set]
[clojure.string :as str]
[play-clj.core :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(defn play-warlocks-castle [entities]
(let [scenarios [#(actions/do-dialogue entities
:game-player "As you approach the lair of the cave beast, a foul odor fills your nostrils."
:game-player "To your horror, you realize that the stench is from the corpses of less wise wizards."
:game-player "The cave is eerie and dark. What do you do?")
#(actions/do-dialogue entities
:game-player "As you move forward in your quest, you come upon an abandoned library."
:game-player "Still, something doesn't feel right about the place."
:game-player "It's quiet."
:game-player "A little too quiet.")
#(actions/do-dialogue entities
:game-player "The treacherous stair lies before you.")]]
(doseq [scenario (take 2 (shuffle scenarios))]
(scenario))))
(defn nice-trophy-dialogue [entities]
{:run #(actions/respond entities %
:game-player "Thanks. I'm the reigning champ in the annual Town of Remington Junior Smarty Pants Derby."
:game-player "And with my sharp intellect, I'm guessing you want my trophy?")
:choices ["Yes."
{:run #(do (actions/update-state entities (fn [state] (assoc state :current-riddle :wool)))
(actions/respond entities %
:game-player "Well, if you want my trophy, you'll have to earn it."
:game-player "There are a few riddles that even I, the wisest in all of Remington, cannot solve."
:game-player "How about you help me?"
:game-player "Bring me the answer:"
:game-player "White as snow, but not as cold,"
:game-player "Keeps you warm, or so I'm told."
:ego "Okay."))}
"No."
{:run #(actions/respond entities %
:game-player "That's exactly what I'd expect a dummy like you to say.")}]})
(defn walk-to-player [entities]
(actions/walk-to entities :ego [210 73] :face :right))
(defn do-game-player-dialogue [entities]
(walk-to-player entities)
(actions/do-dialogue entities :ego "You there!" :game-player "... Yes?")
(actions/present-choices entities
{:choices ["Do you know anything about the sword in the stone up there?"
{:run #(actions/respond entities %
:game-player "It is said that only he who is worthy in wisdom can pull the sword!"
:game-player "I, of course have such wisdom, but I'm still unable to pull it myself.")
:choices ["How'd you get to be so wise?"
{:run #(actions/respond entities %
:game-player "Ever heard of the annual Town of Remington Junior Smarty Pants Derby?"
:ego "I don't think so..."
:game-player "I'm the three times town champ!"
:game-player "My intellect has only been achieved with years of precise training!"
:ego "..."
:game-player "It would take years of careful honing of your skills to be as wise as I am.")
:choices actions/previous-choices}
"Why don't you pull the sword?"
{:run #(actions/respond entities %
:game-player "You must be mighty in strength to pull the sword."
:game-player "And I spend all my time studying!")
:choices actions/previous-choices}
"Something else."
{:choices actions/something-else}]}
(when (= nil (get-in @entities [:state :current-riddle]))
"Nice trophy.")
(nice-trophy-dialogue entities)
(when (= :wool (get-in @entities [:state :current-riddle]))
"What was that riddle again?")
{:run #(actions/respond entities %
:game-player "White as snow, but not as cold,"
:game-player "Keeps you warm, or so I'm told.")
:choices actions/previous-choices}
(when (= :balloon (get-in @entities [:state :current-riddle]))
"What was that riddle again?")
{:run #(actions/respond entities %
:game-player "Filled with air, light as a feather,"
:game-player "If you want to keep it, best have a tether.")
:choices actions/previous-choices}
(when (= :frog-legs (get-in @entities [:state :current-riddle]))
"What was that riddle again?")
{:run #(actions/respond entities %
:game-player "Hippity-hop, I jump real far,"
:game-player "Now I'm dead, or at least have a scar.")
:choices actions/previous-choices}
"Nevermind."
{:run #(actions/respond entities % :game-player "See you around.")}]}))
(defn pull-sword [entities]
(actions/play-animation entities :ego :reach)
(actions/give entities :sword)
(actions/remove-entity entities :sword)
(actions/talk entities :ego "I got it! I will become the greatest knight Remington has ever known!"))
(defn try-to-pull-sword [entities missing-items obtained-items]
(let [item->proof {:trophy "wisdom" :medal "strength" :kiss "courage"}]
(actions/play-animation entities :ego :reach)
(actions/do-dialogue entities
:ego "I can't pull it out!"
:ego "It looks like there's an enscription here.")
(actions/play-animation entities :ego :squat)
(actions/do-dialogue entities
:ego "The Sword of Blergh with magic sting,"
:ego "shall yield to no earthly king."
:ego "Worthy in wisdom, courage, and might,"
:ego "only then with sword he'll fight.")
(if (= 3 (count missing-items))
(actions/do-dialogue entities :ego "I have to prove myself worthy in wisdom, courage, and might!")
(actions/do-dialogue entities :ego (str "I've proven myself in "
(str/join " and " (map item->proof obtained-items))
", but still have to prove myself in "
(str/join " and " (map item->proof missing-items))
".")))))
(defn make [screen]
(let [game-player-talk-sheet (texture! (texture "inside-castle/game-player-talk.png") :split 40 44)
game-player-talk (animation 0.15 (for [i [0 2 0 2 0 2 0 3 0 2 0 1 0 0 0 0 2 0 2 0 3 0 1 0 1 0 0 1 0 2 0 3 0]]
(aget game-player-talk-sheet 0 i)))
game-player-stand (animation 0.15 (for [i [0 0 0 0 0 0 0 0 0 0 0 1]]
(aget game-player-talk-sheet 0 i)))
trophy (utils/make-anim "inside-castle/trophy.png" [16 16] 0.1 (flatten [(repeat 50 0) 1 2 3 3 3 3 2 1]))]
(rooms/make :music :town-1
:interactions
{:right-door {:box [286 140 306 160]
:cursor :right
:script (actions/get-script entities
(actions/walk-to entities :ego [284 145])
(actions/transition-background entities :outside-castle [82 180])
(actions/walk-to entities :ego [129 148]))}
:up-door {:box [50 150 70 170]
:script (actions/get-script entities
(actions/walk-to entities :ego [65 155])
(actions/transition-background entities :inside-cafeteria [319 55])
(actions/walk-to entities :ego [300 55]))
:cursor :up}
:antique-door {:box [154 90 189 150]
:cursor :up
:script (actions/get-script entities
(actions/walk-to entities :ego [182 90] :face :left)
(actions/play-animation entities :ego :reach)
(actions/transition-background entities :inside-antique [222 15]))}
:sword {:box [0 130 39 165]
:script (actions/get-script entities
(if (actions/has-item? entities :sword)
(actions/talk entities :ego "I already have the Sword of Blergh!")
(do (actions/talk entities :ego "That's the coolest sword I've ever seen!!")
(actions/walk-to entities :ego [37 134] :face :left)
(actions/talk entities :ego "If I pull it out I can become a great knight!")
(let [missing-items (set/difference #{:trophy :medal :kiss} (get-in @entities [:state :obtained-items]))
obtained-items (set/intersection #{:trophy :medal :kiss} (get-in @entities [:state :obtained-items]))]
(if (= #{} missing-items)
(pull-sword entities)
(try-to-pull-sword entities missing-items obtained-items)))))
)}
:sign {:box [125 140 165 155]
:script (actions/get-script entities
(actions/talk entities :ego "Ye Ol' Antique Shoppe."))}
:background-houses {:box [84 145 126 180]
:script (actions/get-script entities
(actions/walk-to entities :ego [79 145] :face :right)
(actions/talk entities :ego "Those are just a bunch of townsfolk houses."))}
:mid-house {:box [217 125 250 180]
:script (actions/get-script entities
(actions/do-dialogue entities
:ego "That's Billy Billigan's house."
:ego "He's probably still angry from when I put his dog in the dryer."))}
:frankie-house {:box [251 140 266 160]
:script (actions/get-script entities
(actions/do-dialogue entities
:ego "That's Frankie Rockfist's house."
:ego "The last time I saw him, he socked me one, right in the kisser."))}
:georgia-house {:box [271 150 286 170]
:script (actions/get-script entities
(actions/do-dialogue entities
:ego "That's Georgia McGorgeous' house."
:ego "One day, when I'm a knight, I'll ask her to be my girlfriend."))}}
:layers [(assoc (texture "inside-castle/background.png") :x 0 :y 0 :baseline 0)
(assoc (texture "inside-castle/pedestal-overlay.png") :x 0 :y 0 :baseline 135)]
:entities {:bird-1 (utils/make-bird screen (as-> [[185 235]
[220 225] [210 230] [250 235]] p
(concat p (reverse p))))
:bird-2 (utils/make-bird screen (as-> [[220 225] [195 235] [210 230] [250 225]] p
(concat p (reverse p))))
:sword (assoc (texture "inside-castle/sword.png")
:x 16
:y 145
:baseline 95)
:trophy (assoc (animation->texture screen trophy)
:x 253 :y 69 :baseline 191
:anim trophy
:anim-start 0
:script (actions/get-script entities
(walk-to-player entities)
(if (= nil (get-in @entities [:state :current-riddle]))
(let [{:keys [run choices]} (nice-trophy-dialogue entities)]
(run "Nice trophy.")
(actions/present-choices entities {:choices choices}))
(actions/do-dialogue entities :ego "Can't you give me your trophy of wisdom?"
:game-player "If you want my trophy, you'll have to help me with my riddles."))))
:game-player (assoc (texture "inside-castle/gameplayer.png") :x 266 :y 49 :baseline 191
:script (actions/get-script entities (do-game-player-dialogue entities))
:scripts {:wool (actions/get-script entities
(walk-to-player entities)
(if (= :wool (get-in @entities [:state :current-riddle]))
(do (actions/update-state entities #(assoc % :current-riddle :balloon))
(actions/remove-item entities :wool)
(actions/do-dialogue entities
:game-player "That's right! Now for your second riddle:"
:game-player "Filled with air, light as a feather,"
:game-player "If you want to keep it, best have a tether."))
(actions/talk entities :ego "He doesn't need it.")))
:balloon (actions/get-script entities
(walk-to-player entities)
(if (= :balloon (get-in @entities [:state :current-riddle]))
(do (actions/update-state entities #(assoc % :current-riddle :frog-legs))
(actions/remove-item entities :balloon)
(actions/do-dialogue entities
:game-player "That's right! Now for your third riddle:"
:game-player "Hippity-hop, I jump really far,"
:game-player "Now I'm dead, or at least a have a scar."))
(actions/talk entities :ego "He doesn't need it.")))
:frog-legs (actions/get-script entities
(walk-to-player entities)
(if (= :frog-legs (get-in @entities [:state :current-riddle]))
(do (actions/update-state entities #(assoc % :current-riddle :done))
(actions/remove-item entities :frog-legs)
(actions/do-dialogue entities
:game-player "Wow! That's right!"
:game-player "I guess I'm not the wisest person in Remington."
:game-player "You have earned my trophy.")
(actions/give entities :trophy)
(actions/remove-entity entities :trophy))
(actions/talk entities :ego "He doesn't need it.")))
:trophy (actions/get-script entities
(walk-to-player entities)
(actions/talk entities :game-player "You can keep the trophy. You've earned it."))}
:anim game-player-stand
:anim-start 0
:stand game-player-stand
:talk game-player-talk)}
:collision "inside-castle/collision.png"
:scale-fn (utils/scaler-fn-from-image "inside-castle/scale.png" 0.25 1.00)
:apply-state (fn [entities]
(as-> entities entities
(if (actions/has-item? entities :trophy)
(update-in entities [:room :entities] #(dissoc % :trophy))
entities)
(if (actions/has-item? entities :sword)
(update-in entities [:room :entities] #(dissoc % :sword))
entities)))
:start-pos [245 90])))