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

257 lines
19 KiB
Clojure

(ns advent.screens.rooms.space
(: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]
[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]))
(defn taunt [screen entities]
(when (and (not (get-in entities [:actions :script-running?]))
(get-in entities [:state :active?])
(not (get-in entities [:state :blergh-dead?])))
((actions/get-script entities (actions/do-dialogue entities :bloodclot-head (rand-nth ["Come on, little man! Try and hit me!"
"What's the matter? Cold feet?"
"Come here and fight me like man!"
"Your precious Georgia McGorgeous would be laughing if she saw you now."
"Pick up your weapon and fight!"]))) entities))
nil)
(defn start-swing-if-necessary [screen e]
(if (and (not= (:anim e) :swing)
(> (:x e) 190))
(actions/start-animation screen e :swing)
e))
(defn start-fade-if-necessary [e screen]
(if (and (nil? (get-in e [:tweens :flash]))
(< (get-in e [:room :entities :ego :y]) 100))
(assoc-in e [:tweens :flash] (utils/tween :flash screen [:white-fade :opacity] 0.0 1.0 0.5 :power 3.0))
e))
(defn bloodclot-disappear [entities]
(actions/run-action entities
(begin [this screen entities]
(particle-effect! (get-in entities [:room :entities :appear]) :reset)
(particle-effect! (get-in entities [:room :entities :appear]) :start)
(sound! (sound "inside-house/disappear.ogg") :play)
(-> entities
(assoc-in [:tweens :bloodclot-head-appear]
(utils/tween :bloodclot-head-appear screen [:room :entities :bloodclot-head :opacity] 1.0 0.0 1.0 :power 4.0))
(assoc-in [:tweens :bloodclot-appear]
(utils/tween :bloodclot-appear screen [:room :entities :bloodclot :opacity] 1.0 0.0 1.0 :power 4.0))))
(continue [this screen entities]
entities)
(done? [this screen entities]
(= 0.0 (get-in entities [:room :entities :bloodclot :opacity])))
(terminate [this screen entities]
entities)
(can-skip? [this screen entities]
false)))
(defn swing-at-blergh [entities]
(let [jump-path (bezier (map #(apply vector-2* %) [[35 45] [110 145] [195 180]]))
swing-path (bezier (map #(apply vector-2* %) [[195 180] [205 45]]))
jump-dist (utils/dist 35 45 205 45)
speed 190.0
jump-duration (/ jump-dist speed)
swing-dist (utils/dist 195 180 205 45)
swing-duration (/ swing-dist (* speed 1.5))]
(actions/run-action entities
(begin [this screen entities]
(sound! (sound "space/jump.ogg") :play)
(-> entities
(assoc-in [:room :entities :cloud] (assoc (texture "space/cloud.png")
:x (- (get-in entities [:room :entities :ego :x]) 10)
:y (get-in entities [:room :entities :ego :y])
:origin-x 7
:origin-y 7
:scale-x 0.5
:scale-y 0.5
:opacity 0.5
:baseline 240))
(assoc-in [:tweens :cloud-up] (utils/tween :cloud-up screen [:room :entities :cloud :y]
(get-in entities [:room :entities :ego :y])
(+ (get-in entities [:room :entities :ego :y]) 20)
1.0))
(assoc-in [:tweens :cloud-fade] (utils/tween :cloud-fade screen [:room :entities :cloud :opacity]
0.5
0.0
1.0))
(assoc-in [:tweens :cloud-grow] (utils/tween :cloud-grow screen [:room :entities :cloud :scale-y]
0.5
2.5
1.0))
(assoc-in [:tweens :cloud-grow-2] (utils/tween :cloud-grow-2 screen [:room :entities :cloud :scale-x]
0.5
2.5
1.0))
(update-in [:room :entities :ego]
#(actions/start-animation screen % :jump))
(assoc-in [:tweens :jump-pos] (utils/tween :jump-pos screen [:room :entities :ego :move-pct] 0.0 1.0 jump-duration :power 2))))
(continue [this screen entities]
(let [v (vector-2 0 0)
a (bezier! jump-path :value-at v (get-in entities [:room :entities :ego :move-pct] 0.0))]
(update-in entities [:room :entities :ego] #(assoc % :x (vector-2! v :x) :y (vector-2! v :y)))))
(done? [this screen entities]
(= (get-in entities [:room :entities :ego :move-pct]) 1.0))
(terminate [this screen entities]
(assoc-in entities [:room :entities :ego :move-pct] 0.0))
(can-skip? [this screen entities]
false))
(actions/run-action entities
(begin [this screen entities]
(sound! (sound "space/swingsword.ogg") :play)
(-> entities
(update-in [:room :entities :ego]
#(actions/start-animation screen % :swing))
(assoc-in [:tweens :swing-pos] (utils/tween :swing-pos screen [:room :entities :ego :move-pct] 0.0 1.0 swing-duration :power 10))))
(continue [this screen entities]
(let [v (vector-2 0 0)
a (bezier! swing-path :value-at v (get-in entities [:room :entities :ego :move-pct] 0.0))]
(-> entities
(start-fade-if-necessary screen)
(update-in [:room :entities :ego] #(assoc % :x (vector-2! v :x) :y (vector-2! v :y))))))
(done? [this screen entities]
(= (get-in entities [:room :entities :ego :move-pct]) 1.0))
(terminate [this screen entities]
(-> entities
(assoc-in [:room :entities :ego :move-pct] 0.0)
(update-in [:room :entities :ego] #(actions/start-animation screen % :pant))))
(can-skip? [this screen entities]
false))
(actions/run-action entities
(begin [this screen entities]
(assoc-in entities [:tweens :flash] (utils/tween :flash screen [:white-fade :opacity] 1.0 0.0 3.0 :power 2.0)))
(continue [this screen entities]
entities)
(done? [this screen entities]
(nil? (get-in entities [:tweens :flash])))
(terminate [this screen entities]
entities)
(can-skip? [this screen entities]
false))))
(defn make [screen]
(let [
blergh-flex (texture "space/blergh-flex.png")
bloodclot-head-talk-anim (utils/make-anim "space/bloodclot-head-talk.png" [82 75] 0.05 [0 0 1 1 2 2 1 1 0 0 1 1 2 2 1 1 0 0 3 4 4 4 3 0 0 1 1 2 2 1 1 0 0 0 0 5 5 5 6 6 6 7 7 7])
bloodclot-head-stand-anim (utils/make-anim "space/bloodclot-head-talk.png" [82 75] 0.05 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 3])
bloodclot-head-shoot-anim (utils/make-anim "space/bloodclot-head-talk.png" [82 75] 0.05 [8 9 8 9 8 9 8 9 8 9 8 9 8 9 8 9 8 9 8 9 10 11 10 11 10 11 10 11 10 11 10 11])
bloodclot-head-keep-shoot-anim (utils/make-anim "space/bloodclot-head-talk.png" [82 75] 0.05 [12 13])
blergh-stand-anim (utils/make-anim "space/bloodclot-stand.png" [106 165] 0.05 [0 0 0])
blergh-swing (utils/make-anim "space/blergh-swing.png" [106 165] 0.1 [0 0 1 2 3 4 ])
blergh-appear (utils/make-anim "space/blergh-appear.png" [106 165] 0.05 (flatten [(range 13) 12 12 12 12 12 12 12 12 12 12 12 12 12 ]))
blergh-grow (utils/make-anim "space/blergh-grow.png" [106 165] 0.10 [0 1 0 1 0 1 0 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 2 2 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 5 6 7 8 9 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11])
bullet (utils/make-anim "space/bullet.png" [24 24] 0.0075 [0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 3 3 3 4 4 5 5 6 5 4 7])
effect (particle-effect "space/appear")]
(rooms/make :music :fight
:interactions
{}
:layers [(assoc (texture "space/background.png") :x 0 :y 0 :baseline 0)]
:timers {:taunt [10.0 8.0 taunt]}
:entities {:appear (assoc effect
:x 240 :y 50
:baseline 200)
:bloodclot-head (assoc (animation->texture screen bloodclot-head-stand-anim)
:x 195 :y 138 :baseline 195
:opacity 0.0
:anim bloodclot-head-stand-anim
:talk bloodclot-head-talk-anim
:keep-shoot bloodclot-head-keep-shoot-anim
:shoot bloodclot-head-shoot-anim
:anim-start 0
:stand bloodclot-head-stand-anim
:talk-color (color 0.95 0.4 0.2 1.0))
:bloodclot (assoc (animation->texture screen blergh-stand-anim)
:x 180 :y 50 :baseline 190
:stand blergh-stand-anim
:opacity 0.0
:appear blergh-appear
:grow blergh-grow
:script (actions/get-script entities
(actions/do-dialogue entities :bloodclot-head "Come on! Try and hit me!"))
:scripts {:sword (actions/get-script entities
(swing-at-blergh entities)
(actions/do-dialogue entities :bloodclot-head "Ha ha ha! Is that the best you can do?"
:bloodclot-head "Take this!")
(sound! (sound "space/shock.ogg") :play)
(actions/play-animation entities :bloodclot-head :shoot :stop? false)
(actions/begin-animation entities :bloodclot-head :keep-shoot)
(actions/play-animation entities :ego :shock :stop? false)
(actions/begin-animation entities :bloodclot-head :stand)
(actions/play-animation entities :ego :burnt :stop? false)
(actions/play-animation entities :ego :passed-out :continue? true)
(actions/do-dialogue entities :bloodclot-head "Oh shucks. I overcooked him."
:bloodclot-head "No matter."
:bloodclot-head "Tomorrow, I will return with my legion of goblins."
:bloodclot-head "And THEN the feast will begin."
:bloodclot-head "Starting with his precious Georgia McGorgeous.")
(bloodclot-disappear entities)
(common/go-to-jail entities)
(actions/do-dialogue entities :ego "Hey!" :ego "What's going on? I was just about to teach Bloodclot a lesson!"))
:magic-slingshot (actions/get-script entities
(actions/do-dialogue entities
:ego "Hey Blergh!"
:ego "Take this!")
(actions/play-animation entities :ego :shoot)
(actions/add-entity entities :bullet (get-in @entities [:room :bullet]))
(actions/walk-straight-to entities :bullet [213 166] :update-baseline? false :speed 5.0)
(actions/add-entity entities :broken-jewel (get-in @entities [:room :broken-jewel]))
(Thread/sleep 500)
(actions/remove-entity entities :bullet)
(actions/update-state entities #(assoc % :broke-jewel? true))
(actions/do-dialogue entities
:bloodclot-head "Argh! My magic lightning helmet!"
:bloodclot-head "No matter. I will destroy you with my bare hands!"))})}
:bullet (assoc (animation->texture screen bullet)
:x 130 :y 85 :baseline 241
:walk bullet)
:broken-jewel (assoc (texture "space/broken-jewel.png")
:x 222 :y 172 :baseline 240)
:collision "space/collision.png"
:scale-fn (constantly 1.5)
:start-pos [35 45]
:apply-state (fn [e]
(as-> e e
(if (get-in e [:state :broke-jewel?])
(assoc-in e [:room :entities :broken-jewel] (get-in e [:room :entities :broken-jewel]))
e)
(if (get-in e [:state :seen-bloodclot?])
(assoc-in e [:room :entities :bloodclot :opacity ] 1.0)
e)
(if (get-in e [:state :seen-bloodclot?])
(assoc-in e [:room :entities :bloodclot-head :opacity ] 1.0)
e)
(assoc-in e [:state :seen-bloodclot?] true))))))