distance.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.6 KiB |
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user