Files
gitea-docker/desktop/src-common/advent/screens/rooms/held.clj
2018-02-10 22:22:57 -08:00

180 lines
11 KiB
Clojure

(ns advent.screens.rooms.held
(:require [advent.screens.rooms :as rooms]
[advent.screens.rooms.common :as common]
[advent.actions :as actions]
[advent.screens.items :as items]
[advent.utils :as utils]
[advent.tween :as tween]
[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.math :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn bloodclot-choices [entities]
(actions/present-choices entities {:choices ["I'm just a kid! You wouldn't eat a kid, would you?"
{:run #(actions/respond entities %
:bloodclot-head "But I love eating young, tender children!"
:bloodclot-head "My mother would sing while making children stew."
:bloodclot-head "\"Eat the humans while they're young,\nEat the liver, spleen, and lung!\""
:bloodclot-head "Just singing that makes my mouth water.")
:choices actions/previous-choices}
"I'm covered in poison!"
{:run #(actions/respond entities %
:bloodclot-head "Actually, us goblins quite enjoy poison."
:bloodclot-head "It's like a good hotsauce."
:bloodclot-head "A good poison makes the meal pack a punch.")
:choices actions/previous-choices}
"I've got something in my pocket you might be interested in."
{:run #(do (actions/respond entities %
:bloodclot-head "Oh yeah, like what?")
(actions/update-entities entities (fn [e] (assoc-in e [:room :bloodclot-timer] 0))))}]}))
(defn add-second [screen entities]
(when (and (not (get-in entities [:fg-actions :script-running?]))
(get-in entities [:state :active?]))
(if (> (get-in entities [:room :bloodclot-timer] 0) 7)
(do
((actions/get-script entities (actions/talk entities :bloodclot-head "Time is up, runt.")
(bloodclot-choices entities)) entities)
nil)
(update-in entities [:room :bloodclot-timer] (fnil inc 0)))))
(defn bloodclot-talk-script [entities]
(actions/talk entities :ego "Let me down, Bloodclot!" :anim :suspended-talk)
(actions/do-dialogue entities :bloodclot-head "You've been a nuisance since I first met you!"
:bloodclot-head "Why shouldn't I gobble you up?")
(bloodclot-choices entities))
(defn fail-item [who msg]
(actions/get-script entities
(actions/talk entities who msg)))
(defn explode [entities]
(let [start-time (atom nil)]
(actions/run-action entities
(begin [this screen entities]
(reset! start-time (:total-time screen))
(-> entities
(update-in [:room :entities :bloodclot] #(actions/start-animation screen % :grow))
(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]
(let [move-speed (* 0.17
(/ (:delta-time screen)
(/ 1.0 60.0)))
entities (update-in entities [:room :entities :ego :x] #(max 80 (- % move-speed)))]
entities))
(done? [this screen entities]
(> (- (:total-time screen) @start-time) 8.0))
(terminate [this screen entities]
(update-in entities [:room :entities :ego ] #(actions/start-animation screen % :crawl-stand)))
(skip-type [this screen entities]
:none))))
(defn give-potion [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)
(assoc-in [:room :entities :ego :previous-frame-index] -1)
(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!"
)
(actions/transition-music entities :tongue-fight)
(explode entities)
(Thread/sleep 2000)
(actions/talk entities :bloodclot "Now..."
:stop? false
:anim :big)
(actions/talk entities :bloodclot "Where were we?"
:stop? false
:anim :big)
(actions/tween entities
:arm-y
(fn [screen entities]
(tween/tween :arm-y screen [:room :entities :arm :y] 240 70 3.0 :ease tween/ease-linear)))
(actions/transition-background entities :tongue-fight [141 240])
(actions/walk-straight-to entities :ego [141 110] :anim :tongue-idle :speed 4.0))
(defn make [screen atlas global-atlas]
(let [bloodclot-talk (utils/make-anim-seq atlas "bloodclot-head" [114 82] 0.1 [0 1 2 1 0 3 3 0 1 2 1 0 3 4 5 6 5 3 3 1 2 1 3 3 3 3 3 0 0 0 7 8 7])
bloodclot-stand (utils/make-anim-seq atlas "bloodclot-head" [114 82] 0.1 (flatten [(repeat 15 0) 7 8 7]))]
(rooms/make :name "Held"
:interactions {:bloodclot {:box [182 42 270 196]
:label "Bloodclot"
:cursor :talk
:script (actions/get-script entities
(bloodclot-talk-script entities))
:scripts #(condp = %
:magic-slingshot (fail-item :ego "I only had one bullet!")
:spear (fail-item :ego "I'm not strong enough to reach it!")
:sword (fail-item :ego "I'm not strong enough to reach it!")
:crowbar (fail-item :ego "I'm not strong enough to reach it!")
:medal (fail-item :bloodclot-head "Where is your might now, runt?")
:trophy (fail-item :bloodclot-head "Seems like your wisdom has failed you today.")
:kiss (fail-item :bloodclot-head "Your bravery won't save you from my belly!")
:note-1 (fail-item :bloodclot-head "I'm afraid Gandarf will be of no use to you now.")
:note-2 (fail-item :bloodclot-head "I'm afraid Gandarf will be of no use to you now.")
:flask-1-strength (actions/get-script entities (give-potion entities))
(actions/get-script entities
(actions/talk entities :bloodclot-head "Don't make me laugh, kid!")))
}}
:timers {:taunt [5.0 1.0 add-second]}
:layers [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "hand") :x 0 :y 0 :baseline 240)]
:entities {:bloodclot-head (assoc (animation->texture screen bloodclot-stand)
:x 211 :y 115 :baseline 240
:origin-x 57 :origin-y 0
:talk-color (color 0.95 0.4 0.2 1.0)
:stand bloodclot-stand
:talk bloodclot-talk
:anim bloodclot-stand
:anim-start 0)}
:collision "held/collision.png"
:scale-fn (constantly 1.5)
:start-pos [113 120]
:apply-state (fn [screen e]
(-> e
(assoc-in [:cam :paused? ] true)
(update-in [:tweens] dissoc :cam-x :cam-y)
(update-in [:room :entities :ego] #(actions/start-animation screen % :suspended))
(assoc-in [:room :entities :ego :stand-override] :suspended)
(assoc-in [:room :entities :ego :talk-override] :suspended-talk)
(assoc-in [:room :entities :ego :get-script] (fn [cursor [x y]]
(actions/get-script entities
(if (= :flask-1-strength (:value cursor))
(give-potion entities)
(actions/talk entities :ego "I can't reach it!"))))))))))