From 2b7b663e72a84a3932e17f96c046745b5cb851f3 Mon Sep 17 00:00:00 2001 From: Remington Covert Date: Mon, 6 Oct 2014 20:43:33 -0700 Subject: [PATCH] distance. --- desktop/resources/cursor.png | Bin 2604 -> 2642 bytes desktop/src-common/advent/actions.clj | 14 ++++----- .../advent/screens/rooms/outside_house.clj | 28 ++++++++++++++---- desktop/src-common/advent/screens/scene.clj | 2 +- desktop/src-common/advent/utils.clj | 6 ++++ 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/desktop/resources/cursor.png b/desktop/resources/cursor.png index 8ded96a282fd812b3123df94e8af707856c99400..9e0ef7d3014a787d7e0654f31ed54fe7173dde0f 100644 GIT binary patch delta 1554 zcmV+t2JQK*6w(y1R0MzNNkljI5$-+JLB_C=m@}E!zDf z;uFPR5?wb^5Tru=5h#HQB8VUqv#tg~DF&a2f3}qxktl@5idKX?*orO&3M!T0<43Od zoA$dsJGpc3+}%93WCre@GiS~@GxzNM&YU|}sSVO@80iUc@pgaBKINYJ2yCPXe76>Hy`{rr$Lt6v^57Fv|XRHzcYVnu;c12?5e$!^G?1c@K1cbsJd_8tbP2j zcOlU}pU(%4Mk7%tTFfdj?X004+h4-AC2Y8@3&NK5_V7&6W~H7j`tx+(iA0`&lV~j;mUI zU7MCl&nWPqXs8BoF(GJS!p}Fe|0wg4yFYkT1PLzmP)~pH!eu(H;D-Z%s1+c>&b-pr zD#r<6DRbqeZL8~doy+T;-4Tcq0B)n*Bv5+t5giRC0d&ZNlGjR>AME}BKHF{E&QrL| zmZcIP;IaFYU#R`nRFMEQ=7l-y^?FN50Cu?OgS-}`{1CvjG1rB@&4phau0yVoKErisaaz>?eL1)E1@K=PHp)t+(o^7( z1jutNj+)O*xm?!e3X%Z%I6E&}p9nN1fZ3TDeGUNX`U-&4{hfE;9MnGBuU;5_HM)zJ z_B|KzNCFrm@MSW9(#Sw>Ab0(pZ~qvAd?0^H0%oai_M?eHhTw-R3;3ZwK0XeT*v7`j zR2+C91F!}M2UU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!P~$?3&HSt9rcdaqTleyP@9yLoq; zkU){O;hFx!Po@<<06IPiA=nW0&yO3KB!G$mq(K9`%EO<0mYxKZhaZT*T{^%I5|BGTY(n6d{%IA!+`-j<-SK(9XxT64ab*%fSpdQx&;6(@%ETx$ zKYiSLK|gB^q0*nRlJV4oK$QL$zB_5m3HslzEGrNJ+8vJ^IFaDr{|=Lr#I~y$=qLeX zt(?T*l0cSU+Bn|zW4x2V=X_%TQx<4w8*1B)(XM}JT_JrI355Kp2ML^+9%t9K59~hJ z)!&+(I0~s5h+j%-dN$`Ec6#^D(@KBWHt}!yM^)VU-7Lj^%s|XQ%)nL7z&~V?jzF{- R&D8(^002ovPDHLkV1mt&_}l;h diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 527d116b..80b35bad 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -9,6 +9,7 @@ [advent.pathfind] [advent.actions :as actions] [advent.screens.dialogue :as dialogue] + [advent.utils :as utils] [clojure.core.async :refer [put! ! >!! chan go thread take! alts!!]]) (:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter] [com.badlogic.gdx.graphics.g2d TextureRegion] @@ -53,11 +54,6 @@ (update-in entities [:room :entities target-id] #(start-animation screen % :stand))) -(defn dist [x1 y1 x2 y2] - (let [dx (- x1 x2) - dy (- y1 y2)] - (Math/sqrt (+ (* dx dx) (* dy dy))))) - (defmacro run-action [entities & forms] `(let [c# (chan)] (do @@ -79,7 +75,7 @@ (let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id])] (let [delta-x (- final-x from-x) delta-y (- final-y from-y) - distance (dist from-x from-y final-x final-y) + distance (utils/dist from-x from-y final-x final-y) speed (* (or scale-x 1.0) 1.5) moved-x (if (= 0.0 distance) 0 @@ -102,7 +98,7 @@ (done? [this screen entities] (let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:room :entities target-id])] - (< (dist final-x final-y from-x from-y) 1))) + (< (utils/dist final-x final-y from-x from-y) 1))) (terminate [this screen entities] (stop screen entities target-id)) @@ -131,7 +127,7 @@ [[target-x target-y] remainder] @targets-left] (let [delta-x (- target-x from-x) delta-y (- target-y from-y) - distance (dist from-x from-y target-x target-y) + distance (utils/dist from-x from-y target-x target-y) speed (* (or scale-x 1.0) 1.5) moved-x (if (= 0.0 distance) 0 @@ -155,7 +151,7 @@ (done? [this screen entities] (let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:room :entities target-id])] - (< (dist final-x final-y from-x from-y) 1))) + (< (utils/dist final-x final-y from-x from-y) 1))) (terminate [this screen entities] (stop screen entities target-id)) diff --git a/desktop/src-common/advent/screens/rooms/outside_house.clj b/desktop/src-common/advent/screens/rooms/outside_house.clj index 81657eef..79e813a0 100644 --- a/desktop/src-common/advent/screens/rooms/outside_house.clj +++ b/desktop/src-common/advent/screens/rooms/outside_house.clj @@ -8,6 +8,16 @@ [play-clj.utils :refer :all] [play-clj.g2d :refer :all])) +(def ego-sheep-loc + [132 140]) + +(defn dist-to-sheep [entities] + (apply utils/dist (get-in entities [:room :entities :sheep :x]) (get-in entities [:room :entities :sheep :y]) + ego-sheep-loc)) + +(defn is-sheep-close? [entities] + (< (dist-to-sheep entities) 45)) + (defn wizard-dialogue [entities] (actions/do-dialogue entities :ego "Hello there Mr. Fangald!" :wizard "Oh no, not you again!") (actions/present-choices entities @@ -152,19 +162,27 @@ :box [38 160 71 181] :script (actions/get-script entities + + (if ((get-in @entities [:state :inventory]) :wool) (actions/talk entities :ego "The sheep has given me enough wool.") - (do (actions/give entities :wool) - (actions/talk entities :ego "I guess her wool is shedding.")))) + (if (is-sheep-close? @entities) + (do (actions/walk-to entities :ego ego-sheep-loc) + (actions/give entities :wool) + (actions/talk entities :ego "I guess her wool is shedding.")) + (actions/talk entities :ego "She's too far away for me to pet her.")))) :scripts {:wool (actions/get-script entities (actions/talk entities :ego "She doesn't need it back.")) :carrot (actions/get-script entities - (actions/walk-to entities :ego [132 140]) + (actions/walk-to entities :ego ego-sheep-loc) (actions/talk entities :ego "Come on girl, get the carrot!") (actions/walk-straight-to entities :sheep [95 150])) :flask (actions/get-script entities - (actions/give entities :flask-with-contents) - (actions/talk entities :ego "Sheeps milk."))} + (if (is-sheep-close? @entities) + (do (actions/walk-to entities :ego ego-sheep-loc) + (actions/give entities :flask-with-contents) + (actions/talk entities :ego "Sheeps milk.")) + (actions/talk entities :ego "She's too far away.")))} :left {:walk (utils/flip sheep-walk) :stand (utils/flip sheep-stand)} :right {:walk sheep-walk diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index e21aa86c..5c9c8a5e 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -133,7 +133,7 @@ (update! screen :renderer (stage) :camera (orthographic)) (let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0) music (sound "town-music.mp3") - _ (sound! music :loop 0.80) + ;; _ (sound! music :loop 0.80) rooms {:inside-house (rooms.inside-house/make screen) :outside-house (rooms.outside-house/make screen) :behind-house (rooms.behind-house/make screen) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index bac04070..f4d5c165 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -44,6 +44,12 @@ range (+ (* percent-complete (- maximum-size minimum-size)) minimum-size)] range))))) +(defn dist [x1 y1 x2 y2] + (let [dx (- x1 x2) + dy (- y1 y2)] + (Math/sqrt (+ (* dx dx) (* dy dy))))) + + (defn flip [anim] (animation (animation! anim :get-frame-duration) (for [src-frame (animation! anim :get-key-frames)