Files
gitea-docker/desktop/src-common/advent/screens/rooms/common.clj
Bryce Covert 9019166c7e updates
2016-01-07 20:21:04 -08:00

585 lines
38 KiB
Clojure

(ns advent.screens.rooms.common
(:require [clojure.core.async :refer [chan]]
[advent.screens.rooms :as rooms]
[advent.actions :as actions]
[advent.screens.items :as items]
[advent.steam :as steam]
[advent.utils :as utils]
[advent.pathfind]
[advent.tween :as tween]
[clojure.zip :as zip]
[play-clj.core :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.math :refer :all]
[play-clj.g2d :refer :all])
(:import [com.badlogic.gdx.graphics Color]))
(defn go-to-jail [entities & [time]]
(actions/update-state entities #(assoc % :chest-contents (concat (remove #{:key :ladder} (:inventory %)) (:chest-contents %))))
(actions/update-state entities #(assoc % :inventory []))
(actions/update-state entities #(assoc % :opened-bars? false))
(actions/transition-background entities :inside-jail [130 85] :between (fn [s e]
(-> e
(assoc-in [:state :time] :night)
(update-in [:room :entities :ego] #(actions/start-animation s % :crawl-stand))))
:time time)
(actions/play-animation entities :ego :standup))
(defn make-wizard [screen wizard-spec]
(let [wizard-sheet (texture! (utils/get-texture "wizard/talk.png") :split 20 46)
wizard-stand (animation 0.2 (for [i (flatten [(repeat 10 0) 1])]
(aget wizard-sheet 0 i)))
wizard-talk-angry (utils/make-anim "wizard/talk-angry.png" [20 50] 0.2 [0 2 0 2 1 2 0 3 0 2 0 1 0 2])
wizard-magic-hands (utils/make-anim "wizard/magic-hands.png" [20 50] 0.2 (range 2))
wizard-disappear (utils/make-anim "wizard/disappear.png" [20 46] 0.075 (range 19))
disappear-left (utils/flip wizard-disappear)
wizard-talk (animation 0.2 (for [i [0 2 0 2 1 2 0 3 0 2 0 1 0 2]]
(aget wizard-sheet 0 i)))
wizard-talk-left (utils/flip wizard-talk)
wizard-stand-left (utils/flip wizard-stand)
wizard-talk-angry-left (utils/flip wizard-talk-angry)]
(actions/start-animation screen (merge (assoc (animation->texture screen wizard-stand)
:left {:talk wizard-talk-left
:stand wizard-stand-left
:disappear disappear-left
:magic-hands (utils/flip wizard-magic-hands)
:talk-angry wizard-talk-angry-left
}
:right {:talk wizard-talk
:stand wizard-stand
:disappear wizard-disappear
:talk-angry wizard-talk-angry
:magic-hands wizard-magic-hands}
:anim-sound-frames {wizard-stand {11 [:blink 0.15 0.7]}
wizard-talk {11 [:blink 0.15 0.7]
4 [:blink 0.15 0.7]}
wizard-talk-angry {11 [:blink 0.15 0.7]
4 [:blink 0.15 0.7]}
wizard-stand-left {11 [:blink 0.15 0.7]}
wizard-talk-left {11 [:blink 0.15 0.7]
4 [:blink 0.15 0.7]}
wizard-talk-angry-left {11 [:blink 0.15 0.7]
4 [:blink 0.15 0.7]}
wizard-disappear {1 [:disappear 0.7]}
disappear-left {1 [:disappear 0.7]}
}
:night-profile :sprite
:origin-x 0
:origin-y 0
:talk-color (color 0.95 0.3 1.0 1.0)
:facing :left) wizard-spec)
:stand)))
(defn read-note-1 [entities]
(actions/do-dialogue entities
:ego "It's a note from Gandarf! It says:"
:ego "\"Tick, a number of us have been kidnapped by Bloodclot!"
:ego "His minions have us locked up in his fortress of doom."
:ego "It's actually pretty comfortable, despite the name."
:ego "You must cast the spell to restore magic to the Slinger's Shot yourself."
:ego "You do still have The Slinger's Shot, don't you?"
:ego "I will do my best to help you along the way."
:ego "You will need to add to your flask: the ashes of magic and the sound of buzzing."
:ego "Then stir with the gift of flight."
:ego "Then pour the contents in the cauldron."
:ego "I will give you more instructions when I can."
:ego "And please hurry, because we're being forced into a karaoke competition."
:ego "I'm about at my wits' end."
:ego "P.S., Guard that slingshot with your life!"
:ego "P.P.S., You can look for my secret stash of helpful stuff behind a nearby r...\""
:ego "It just cuts off there."))
(defn read-note-2 [entities]
(actions/do-dialogue entities
:ego "It's a Bingo card."
:ego "Look's like there's a note on the back."
:ego "\"Tick, the situation is dire. I don't have much time. Please hurry."
:ego "We've been forced into playing bingo for the last 3 hours."
:ego "You are almost done with the spell to restore magic to The Slinger's Shot."
:ego "You haven't lost it, right?"
:ego "You need to add the root of all evil to the cauldron."
:ego "Also, you'll need to add a split second."
:ego "Then, dip the Slinger's Shot in to complete the spell."
:ego "Don't forget about my secret stash of helpful stuff."
:ego "P.S., It looks like Georgia McGorgeous has been captured, too."
:ego "She's rooting for you, Tick!\""))
(def frankie-color (Color/valueOf "B081ECFF"))
(defn listen-to-frankie [entities]
(let [respond (fn [msg]
(actions/talk entities :ego msg :animate? false :stop? false :color frankie-color)
(Thread/sleep 200))
talk (fn [msg]
(actions/talk entities :ego msg :animate? false :stop? false)
(Thread/sleep 200))]
(talk "Hello?")
(respond "What the?! A walkie-talkie?")
(respond "Who's there?")
(actions/present-choices entities
{:choices ["It's me, Tick!"
{:run #(do
(talk %)
(respond "Dipstick! Leave us in peace!"))}
"It's me, Bubba!"
(if (get-in @entities [:state :bubba-gone?])
{:run #(do
(talk %)
(respond "Bubba!?")
(respond "What happened to your voice?"))
:choices ["(Higher pitch) I think I'm getting a cold."
{:run (fn [m]
(talk "I think I'm getting a cold.")
(respond "Wait a second...")
(respond "You're not Bubba!")
(respond "Bubba has a deep voice!")
(respond "Impostor!")
(respond "Leave us alone."))}
"(Same pitch) I think I'm getting a cold."
{:run (fn [m]
(talk "I think I'm getting a cold.")
(respond "Wait a second...")
(respond "I recognize that voice!")
(respond "I don't know what you're trying to pull, Dipstick.")
(respond "Leave us alone."))}
"(Lower pitch) I think I'm getting a cold."
{:run (fn [m]
(talk "I think I'm getting a cold.")
(respond "Sorry to hear that, Bubba.")
(respond "Whaddaya want?"))
:choices ["Where is our tree fort again?"
{:run (fn [m]
(talk m)
(respond "We don't have a tree fort, Bubba!")
(respond "You must be going crazy.")
(respond "Wait a second...")
(respond "You're not Bubba!")
(respond "I don't know who you are, mister, but quit fooling around!"))}
"Where is the secret stash again?"
{:run (fn [m]
(talk m)
(respond "Bubba, we've talked about this.")
(respond "Our club charter, Chapter 17, Section 23 clearly states...")
(respond "... that we are not to discuss stash locations unless in person!"))
:choices ["Can't you make an exception?"
{:run (fn [m]
(talk m)
(respond "No! Just come back to the gate and I'll tell you in person."))
:choices actions/previous-choices}
"But what about Chapter 24, section 9?"
{:run (fn [m]
(talk m)
(respond "Let's see, Chapter 24...")
(respond "Ahh, yes, here it is.")
(respond "\"There is to be no robbery of the elderly...\"")
(respond "Bubba, Chapter 24 doesn't say anything about our stash!"))
:choices actions/previous-choices}
"But what about Chapter 19A, section 3?"
{:run (fn [m]
(talk m)
(respond "Let's see, Chapter 19A...")
(respond "Ahh yes, here it is.")
(respond "\"If visual confirmation cannot be made...")
(respond "The \"The super cool secret club\" member can validate his allegiance... ")
(respond "By giving a nice compliment to the gang leader.\"")
(respond "... Well?"))
:choices ["Umm, you've got a killer smile."
{:run (fn [m]
(talk m)
(respond "Thanks! I agree.")
(respond "The stash is by the jail.")
(respond "You just have to pull the secret lever.")
(actions/update-state entities #(assoc % :knows-about-stash? true)))}
"Err, your biceps are two in a million."
{:run (fn [m]
(talk m)
(respond "Thanks! I agree.")
(respond "The stash is by the jail.")
(respond "You just have to pull the secret lever.")
(actions/update-state entities #(assoc % :knows-about-stash? true)))}
"Ahh, Your charisma really holds the gang together."
{:run (fn [m]
(talk m)
(respond "Thanks! I agree.")
(respond "The stash is by the jail.")
(respond "You just have to pull the secret lever.")
(actions/update-state entities #(assoc % :knows-about-stash? true)))}]}
"But what about Chapter 47, section 12?"
{:run (fn [m]
(talk m)
(respond "Let's see, Chapter 47...")
(respond "Wait, there is no chapter 47.")
(talk "... righto. I must have been mistaken."))
:choices actions/previous-choices}]}
"Maybe we should give Tick his stuff back."
{:run (fn [m]
(talk m)
(respond "Are you crazy!?")
(respond "We hit the jackpot, and you want to return it?!")
(respond "Wait a second...")
(respond "You're not Bubba!")
(respond "I don't know who you are, mister, but quit fooling around!"))}]}]
}
{:run #(do (talk %)
(respond "Bubba's standing right next to me!")
(respond "You're an imposter!")
(respond "Leave us alone."))})
"It's me, Frankie!"
{:run #(do
(talk %)
(respond "Frankie?")
(respond "But, I'm Frankie!")
(respond "Imposter!")
(respond "Leave us alone!"))}]}))
)
(defn walk-to-frankie [entities]
(actions/walk-to entities :ego [268 61] :face :left))
(defn present-frankie-choices [entities]
(actions/present-choices entities {:choices ["Please, Frankie. Give me my stuff back!"
{:run #(do (actions/respond entities %
:frankie "Not a chance, Dipstick."
:frankie "Burglars like us gotta eat too, you know."
:ego "But it's a matter of life and death!"
:ego "Plus, Georgia's counting on me!")
(actions/georgia-say entities "I'm counting on you, Tick!")
(actions/do-dialogue entities
:frankie "Georgia's going steady with me now, Dipstick."
:frankie "No day-dreaming about my girlfriend!")
(actions/play-animation entities :frankie :laugh)
(actions/do-dialogue entities :frankie "You'd be better off if you just packed your bags and left town."
:frankie "Ain't that right, boys?")
(actions/play-animation entities :frankie :glance))
:choices actions/previous-choices}
"You guys are nothing but a bunch of crooks!"
{:run #(do (actions/respond entities %
:frankie "Oh please."
:frankie "Like you're so different."
:frankie "Am I right, boys?")
(actions/play-animation entities :frankie :glance)
(actions/do-dialogue entities
:frankie "We steal gold, diamonds, and relic slingshots."
:frankie "And you steal teddy bears.")
(actions/play-animation entities :frankie :laugh))
:choices actions/previous-choices}
"Where is your secret stash?"
{:run #(do (actions/respond entities % :frankie "Like I'd ever tell you, Dipstick.")
(actions/play-animation entities :frankie :laugh)
(actions/do-dialogue entities :frankie "That's only for people in the 'Super secret cool club'!"))
:choices actions/previous-choices}
(when-not (get-in @entities [:state :bubba-gone?])
"I found your secret stash!")
{:run #(do (actions/respond entities %
:frankie "What?!"
:frankie "Impossible!")
(actions/play-animation entities :frankie :laugh)
(actions/update-state entities (fn [s] (assoc s :bubba-gone? true)))
(actions/do-dialogue entities :frankie "Bubba, go check to make sure our stuff is safe."
:goon-2 "You got it, boss.")
(actions/walk-straight-to entities :goon-2 [0 100]))}
"Nevermind."
{:run #(actions/respond entities % :frankie "Come back when you've got some good valuables.")}]}))
(defn make-frankie [screen]
(let [stand (utils/make-anim "castle-gate/frankie.png" [24 35] 0.19 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1])
talk (utils/make-anim "castle-gate/frankie.png" [24 35] 0.2 [2 0 2 0 2 0 2 0 0 1 0])
walk (utils/make-anim-seq "castle-gate/frankie-walk" [24 35] 0.2 (range 8))
laugh (utils/make-anim "castle-gate/frankie.png" [24 35] 0.1 [1 3 4 3 4 3 4 3 4 3 4 3 4 1 0])
glance (utils/make-anim "castle-gate/frankie.png" [24 35] 0.25 [0 6 0 6 5 5 5 6 7 7 7 6 ])
reach (utils/make-anim "castle-gate/frankie.png" [24 35] 0.2 [0 8 9 9 9 9 8])
flex (utils/make-anim "castle-gate/frankie.png" [24 35] 0.2 [0 10 11 12 12 12 12 11 10])]
(assoc (animation->texture screen stand)
:x 235 :y 90 :baseline 150
:origin-x 12
:origin-y 0
:anim stand
:anim-start 0
:night-profile :sprite
:scale-x 1.4
:scale-y 1.4
:talk-color frankie-color
:talk talk
:flex flex
:stand stand
:laugh laugh
:glance glance
:reach reach
:right {:walk walk}
:left {:walk (utils/flip walk)}
:script (actions/get-script entities
(walk-to-frankie entities)
(actions/talk entities :ego "Listen, Frankie...")
(present-frankie-choices entities))
:scripts {:walkie-talkies (actions/get-script entities
(actions/do-dialogue entities :frankie "Tin cans? What do I need walkie talkies for?"))
:default (actions/get-script entities
(actions/do-dialogue entities :frankie "What? Wanting to give up more of your goodies?"))})))
(defn explode [entities]
(actions/run-action entities
(begin [this screen entities]
(-> entities
(update-in [:room :entities :bloodclot] #(actions/start-animation screen % :explode))
(update-in [:room :entities] dissoc :broken-jewel)
(update-in [:room :entities] dissoc :bloodclot-head)
(assoc-in [:room :entities :ego :facing] :right)
(update-in [:room :entities :ego] #(actions/start-animation screen % :crawl))))
(continue [this screen entities]
(if (= 185 (get-in entities [:room :entities :bloodclot :current-frame-index]))
(particle-effect! (get-in entities [:room :entities :grow-explode]) :start))
(let [move-speed (* 0.17
(/ (:delta-time screen)
(/ 1.0 60.0)))
entities (update-in entities [:room :entities :ego :x] #(max 80 (- % move-speed)))]
(if (= 80 (get-in entities [:room :entities :ego :x]))
(update-in entities [:room :entities :ego] #(actions/start-animation screen % :crawl-hide))
entities )))
(done? [this screen entities]
(= (get-in entities [:room :entities :bloodclot :current-frame-index]) 191))
(terminate [this screen entities]
(-> entities
(update-in [:room :entities] dissoc :bloodclot)
(assoc-in [:tweens :flash] (tween/tween :flash screen [:white-fade :opacity] 0.0 1.0 0.2 :ease tween/ease-in-cubic))))
(skip-type [this screen entities]
:none))
(actions/run-action entities
(begin [this screen entities]
entities)
(continue [this screen entities]
entities)
(done? [this screen entities]
(not (get-in entities [:tweens :flash])))
(terminate [this screen entities]
entities)
(skip-type [this screen entities]
:none))
(actions/run-action entities
(begin [this screen entities]
(assoc-in entities [:tweens :flash] (tween/tween :flash screen [:white-fade :opacity] 1.0 0.0 4.0 :ease tween/ease-in-cubic)))
(continue [this screen entities]
entities)
(done? [this screen entities]
(not (get-in entities [:tweens :flash])))
(terminate [this screen entities]
(update-in entities [:room :entities :ego] dissoc :stand-override))
(skip-type [this screen entities]
:none)))
(defn disappear [entities]
(actions/run-action entities
(begin [this screen entities]
(-> entities
(assoc-in [:tweens :disappear-ego]
(tween/tween :disappear-ego screen [:room :entities :ego :opacity] 1.0 0.0 0.5 :ease tween/ease-in-out-quintic))))
(continue [this screen entities]
entities)
(done? [this screen entities]
(= 0.0 (get-in entities [:room :entities :ego :opacity])))
(terminate [this screen entities]
entities)
(skip-type [this screen entities]
:none)))
(defn georgia-appear [entities]
(actions/run-action entities
(begin [this screen entities]
(-> entities
(assoc-in [:room :entities :georgia] (get-in entities [:room :georgia]))
(assoc-in [:tweens :appear-georgia]
(tween/tween :appear-georgia screen [:room :entities :georgia :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quintic))))
(continue [this screen entities]
entities)
(done? [this screen entities]
(= 1.0 (get-in entities [:room :entities :georgia :opacity])))
(terminate [this screen entities]
entities)
(skip-type [this screen entities]
:none)))
(defn fade-out [entities]
(actions/run-action entities
(begin [this screen entities]
(-> entities
(assoc-in [:tweens :fade-out]
(tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 7.0 :ease tween/ease-in-out-quintic))))
(continue [this screen entities]
entities)
(done? [this screen entities]
(= 1.0 (get-in entities [:fade :opacity])))
(terminate [this screen entities]
entities)
(skip-type [this screen entities]
:none)))
(defn do-win [entities]
(actions/do-dialogue entities
:ego "Hey, Bloodclot!"
:ego "I have this potion which will make me as strong as you!"
:bloodclot-head "What?!"
:bloodclot-head "Give it here!")
(actions/transition-background entities :space [200 45] :between (fn [s e]
(-> e
(assoc-in [:room :entities :ego :stand-override] :crawl-stand)
(update-in [:room :entities :ego] #(actions/start-animation s % :crawl-stand)))
))
(actions/do-dialogue entities
:bloodclot-head "Yes!"
:bloodclot-head "Ultimate power is mine!"
:bloodclot-head "If I drink this entire bottle, I'll be as powerful as a god!")
(explode entities)
(actions/play-animation entities :ego :standup)
(Thread/sleep 1000)
(actions/update-entities entities (fn [e]
(update-in e [:room :entities :ego] dissoc :stand-override :talk-override )))
(actions/do-dialogue entities
:ego "Hey!"
:ego "I won!")
(steam/set-achievement "BLOODCLOT")
(actions/glad entities)
(actions/walk-straight-to entities :ego [340 55])
(actions/run-action entities
(begin [this screen entities]
(assoc-in entities [:tweens :later] (tween/tween :later screen [:room :entities :later :opacity] 0.0 1.0 4.0 :ease tween/ease-in-cubic)))
(continue [this screen entities]
entities)
(done? [this screen entities]
(not (get-in entities [:tweens :later])))
(terminate [this screen entities]
entities)
(skip-type [this screen entities]
:none))
(Thread/sleep 2000)
(actions/do-stop entities :ego :face :left)
(actions/transition-background entities :ending [165 49] :time 4.0)
(actions/resume-camera entities)
(actions/do-dialogue entities
:duke "Ladies and gentlemen."
:duke "As the Duke of Remington, I'm pleased to inform you..."
:duke "The goblin by the name of Bloodclot has been destroyed!"
:duke "Our town is saved."
:duke "Thanks to this young boy, Tick."
:duke "It is my rightful duty as Duke of Remington to knight you."
:duke "You've proven yourself worthy."
:duke "Your sword, please.")
(actions/walk-straight-to entities :ego [150 49])
(actions/play-animation entities :ego :reach-start :stop? false)
(actions/play-animation entities :duke :reach :stop? false)
(actions/play-animation entities :ego :reach-stop :stop? false)
(actions/talk entities :duke "Kneel." :anim :reach-talk :stop? false)
(actions/play-animation entities :ego :start-squat-2 :stop? false)
(Thread/sleep 1000)
(actions/play-animation entities :duke :knight :stop? false)
(actions/update-entity entities :duke (fn [d] (assoc d :baseline (- 240 48))))
(actions/play-animation entities :duke :knight :stop? false)
(actions/talk entities :duke "In honor of your bravery..." :anim :reach-talk :stop? false)
(actions/talk entities :duke "I declare you Sir Tick of Remington." :anim :reach-talk)
(actions/play-animation entities :ego :end-squat :stop? true)
(Thread/sleep 500)
(actions/glad entities)
(Thread/sleep 200)
(actions/do-dialogue entities :ego "Wait...")
(Thread/sleep 400)
(actions/do-stop entities :ego :face :right)
(Thread/sleep 400)
(actions/do-stop entities :ego :face :left)
(Thread/sleep 400)
(actions/do-stop entities :ego :face :right)
(Thread/sleep 400)
(actions/do-stop entities :ego :face :left)
(Thread/sleep 400)
(actions/do-dialogue entities :ego "Where's Gandarf?")
(actions/do-dialogue entities :ego "And Georgia McGorgeous?")
(actions/walk-straight-to entities :gandarf-cloud [215 100] :update-baseline? false)
(actions/do-stop entities :ego :face :right)
(actions/do-dialogue entities :ego "Gandarf?"
:gandarf "Yes, it is I!"
:gandarf "As soon as you defeated Bloodclot, all of his minions disappeared!"
:gandarf "And I brought someone with me!")
(Thread/sleep 1000)
(actions/talk entities :gandarf "Beautius appearium!!" :anim :talk-angry)
(actions/play-sound entities "ending-castle/georgia-appear.ogg" 0.5 false)
(particle-effect! (get-in @entities [:room :entities :magic-frog-particle]) :reset)
(particle-effect! (get-in @entities [:room :entities :magic-frog-particle]) :start)
(georgia-appear entities)
(actions/do-stop entities :ego :face :left)
(Thread/sleep 3000)
(actions/do-dialogue entities
:georgia "Hey, I'm home!"
:gandarf "Young Tick here saved you from Bloodclot's minions."
:ego "Aww, it was nothing.")
(actions/play-animation entities :ego :shy)
(actions/do-dialogue entities :georgia "Really?" :georgia "My hero!")
(Thread/sleep 500)
(actions/do-dialogue entities :frankie "Wait a hot second!")
(Thread/sleep 500)
(actions/walk-straight-to entities :frankie [95 23])
(actions/do-dialogue entities
:frankie "Come along, Georgia."
:frankie "No sense in thanking Dipstick.")
(actions/play-animation entities :frankie :laugh)
(actions/play-animation entities :georgia :kick)
(actions/walk-straight-to entities :georgia [131 40] :speed 0.8)
(actions/play-animation entities :frankie :fall :stop? false)
(actions/do-dialogue entities :georgia "Let's go, Sir Hunk.")
(actions/play-animation entities :georgia :hand-hold :stop? false)
(actions/play-animation entities :ego :hand-hold :stop? false)
(Thread/sleep 500)
(fade-out entities)
(on-gl (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.credits/credits))))
(defn win []
(actions/get-script entities (do-win entities)))
(defn make-outside-particles []
(doto (assoc (particle-effect "particles/outside-particles") :x 160 :y 120
:baseline 238)
(particle-effect! :set-position 160 120)))
(defn one-liner [msg]
(actions/get-script entities (actions/do-dialogue entities :ego msg)))