323 lines
19 KiB
Clojure
323 lines
19 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.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]))
|
|
|
|
(defn go-to-jail [entities]
|
|
|
|
(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)))))
|
|
(actions/play-animation entities :ego :standup))
|
|
|
|
(defn make-wizard [screen wizard-spec]
|
|
(let [wizard-sheet (texture! (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))
|
|
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)))]
|
|
(actions/start-animation screen (merge (assoc (animation->texture screen wizard-stand)
|
|
:left {:talk (utils/flip wizard-talk)
|
|
:stand (utils/flip wizard-stand)
|
|
:disappear (utils/flip wizard-disappear)
|
|
|
|
:magic-hands (utils/flip wizard-magic-hands)
|
|
:talk-angry (utils/flip wizard-talk-angry)
|
|
}
|
|
:right {:talk wizard-talk
|
|
:stand wizard-stand
|
|
:disappear wizard-disappear
|
|
:talk-angry wizard-talk-angry
|
|
:magic-hands wizard-magic-hands
|
|
}
|
|
: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, I have been kidnapped by Bloodclot.'"
|
|
:ego "'He's got me 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 still do 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.'"))
|
|
|
|
|
|
(defn listen-1 [entities]
|
|
(actions/talk entities :ego "Did you see the look on Tick's face when we took his stuff?" :animate? false :stop? false)
|
|
(actions/talk entities :ego "It looked like he was about to pee his pants." :animate? false :stop? false)
|
|
(actions/talk entities :ego "Am I right boys?" :animate? false :stop? false))
|
|
|
|
(defn listen-2 [entities]
|
|
(actions/talk entities :ego "Hey Bubba, did you put our spoils in our secret stash yet?" :animate? false :stop? false)
|
|
(actions/talk entities :ego "You don't remember where it's at?" :animate? false :stop? false)
|
|
(actions/talk entities :ego "It's right outside the jail." :animate? false :stop? false)
|
|
(actions/talk entities :ego "You just have to pull the secret lever." :animate? false :stop? false)
|
|
(actions/update-state entities #(assoc % :knows-about-stash? true :stop? false)))
|
|
|
|
(defn listen-3 [entities]
|
|
(actions/talk entities :ego "We're going to be rich after we fence this stuff we've stolen." :animate? false :stop? false)
|
|
(actions/talk entities :ego "Am I right boys?" :animate? false :stop? false))
|
|
|
|
(defn listen-to-frankie [entities]
|
|
((rand-nth [listen-1 listen-2 listen-3]) entities))
|
|
|
|
|
|
(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 :bloodclot-head)
|
|
(assoc-in [:room :entities :ego :facing] :right)
|
|
(update-in [:room :entities :ego] #(actions/start-animation screen % :crawl))))
|
|
|
|
(continue [this screen entities]
|
|
(if (= 170 (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]) 176))
|
|
|
|
(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 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 win []
|
|
|
|
(actions/get-script 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)
|
|
(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/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 Georgia McGorgeous?")
|
|
(actions/walk-straight-to entities :gandarf-cloud [215 100] :update-baseline? false)
|
|
(actions/do-dialogue entities :gandarf "Quickly, boy!")
|
|
(actions/do-stop entities :ego :face :right)
|
|
(actions/do-dialogue entities :ego "Gandarf?"
|
|
:gandarf "Yes, it is I!"
|
|
:ego "How did you escape?"
|
|
:gandarf "No time for that!"
|
|
:gandarf "Georgia McGorgeous has been captured!"
|
|
:ego "Captured?! By who?"
|
|
:gandarf "Bloodclot's second-in-command, Swinebreath."
|
|
:gandarf "I'm afraid that I can't save her."
|
|
:gandarf "This is a job for a knight."
|
|
:gandarf "If you are willing, Tick..."
|
|
:duke "That's 'Sir Tick'..."
|
|
:gandarf "Quite right, quite right."
|
|
:gandarf "If you are willing, Sir Tick..."
|
|
:gandarf "I can transport you to the land where her prision lies."
|
|
:gandarf "But it is far out of my sight, and I know not what you'll find."
|
|
:gandarf "Well? What say you?"
|
|
:ego "I'll do it! "
|
|
:gandarf "Very good."
|
|
:gandarf "Prepare yourself.")
|
|
(Thread/sleep 300)
|
|
(actions/talk entities :gandarf "Beamium Up!!!" :anim :talk-angry)
|
|
(particle-effect! (get-in @entities [:room :entities :magic-frog-particle]) :reset)
|
|
(particle-effect! (get-in @entities [:room :entities :magic-frog-particle]) :start)
|
|
(disappear entities)
|
|
(Thread/sleep 2000)
|
|
(fade-out entities)
|
|
(on-gl (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.credits/credits)))
|
|
))
|
|
|
|
|
|
(defn make-outside-particles []
|
|
(doto (assoc (particle-effect "outside-particles") :x 160 :y 120
|
|
:baseline 238)
|
|
(particle-effect! :set-position 160 120)))
|