263 lines
23 KiB
Clojure
263 lines
23 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 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 "I earned it with my wisdom and sharp intellect."
|
|
:game-player "Oh, I'm guessing you want it? Perhaps to prove your wisdom and pull the Sword of Blergh?"
|
|
:game-player "Perhaps to become a knight and impress a young lady?")
|
|
:choices ["Yes."
|
|
{:run #(actions/respond entities %
|
|
:game-player "My trophy is hard-won. You want pry it from my fingers easily."
|
|
:game-player "But I'm preparing for next year's Junior Smarty Pants Derby, and I need some help."
|
|
:game-player "If you can help me, it will secure my success for next year, and so you can have this trophy."
|
|
:game-player "Deal?")
|
|
:choices ["What is the Junior Smarty Pants Derby?"
|
|
{:run #(actions/respond entities %
|
|
:game-player "The annual Town of Remington Junior Smarty Pants Derby is a contest of wits."
|
|
:game-player "It's sort of like a game of riddles, mixed with a scavenger hunt."
|
|
:game-player "You must find the answer to the riddle to win."
|
|
:game-player "There are a few puzzles that even I, Brian O'Brainy, stumped."
|
|
:game-player "If you can help me, I'll let you have my trophy.")
|
|
:choices actions/previous-choices}
|
|
"Deal."
|
|
{:run #(do (actions/update-state entities (fn [state] (assoc state :current-riddle :wool)))
|
|
(actions/respond entities %
|
|
:game-player "Very well. I am studying for next year's derby, and there are a few puzzles that have me stumped."
|
|
:game-player "If you can bring me the answers to three riddles, I'll give you my trophy."
|
|
:game-player "Here's the first riddle:"
|
|
:game-player "'White as snow, but not as cold,\nKeeps you warm, or so I'm told.'"
|
|
:ego "Okay. So I'll be back soon."))}
|
|
"No thanks."
|
|
{:run #(actions/respond entities % :game-player "Fine by me.")}]}
|
|
"No."
|
|
{:run #(actions/respond entities % :game-player "Fine by me.")}]})
|
|
|
|
(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's the Sword of Blergh. There's a prophecy that says that whoever pulls it will be a great knight!"
|
|
:game-player "'The Sword of Blergh, with magic sting,\nshall yield to no earthly king.'"
|
|
:game-player "'Worthy in wisdom, courage, and might,\nonly then with sword he'll fight.'"
|
|
:game-player "I've often dreamed of pulling the sword myself.")
|
|
:choices ["Why don't you?"
|
|
{:run #(actions/respond entities %
|
|
:game-player "I, of course, have the wisdom required for the task."
|
|
:game-player "But I'm not much of a warrior. I don't have the might required for the task."
|
|
:game-player "The knights of Remington have muscles the size of tree trunks."
|
|
:game-player "I'd never be able to prove my strength.")
|
|
: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,\nKeeps 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,\nIf 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'd jump so high,\nWithout these springs, can't harm a fly.'")
|
|
: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 inscription here.")
|
|
(actions/play-animation entities :ego :squat)
|
|
(actions/do-dialogue entities
|
|
:ego "'The Sword of Blergh with magic sting,\nShall yield to no earthly king.'"
|
|
:ego "Worthy in wisdom, courage, and might,\nOnly 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!"
|
|
:ego "Then I can become a knight and impress Georgia McGorgeous!")
|
|
(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)
|
|
(sound! (sound "door.ogg") :play)
|
|
(actions/play-animation entities :ego :reach)
|
|
(actions/transition-background entities :inside-antique [228 -30])
|
|
(actions/walk-straight-to entities :ego [222 15] :face :left))}
|
|
: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,\nIf you want to keep it, best have a tether.'"
|
|
:ego "Okay. Be back soon."))
|
|
(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'd jump so high,\nWithout these springs, can't harm a fly.'"
|
|
:ego "Okay. Be back soon."))
|
|
(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 "You, sir, have proven yourself worthy of my trophy."
|
|
:game-player "Even I, Brian O'Brainy, am impressed with your wisdom."
|
|
:game-player "Take it, and go in wisdom.")
|
|
(actions/give entities :trophy)
|
|
(actions/remove-entity entities :trophy)
|
|
(actions/talk entities :ego "Thanks!"))
|
|
(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])))
|