cool lamb.
This commit is contained in:
@@ -227,12 +227,34 @@
|
|||||||
add-wizard-if-necessary
|
add-wizard-if-necessary
|
||||||
add-note-if-necessary))
|
add-note-if-necessary))
|
||||||
|
|
||||||
|
(defn move-toward [screen entities {:keys [x y] :as e} target-x]
|
||||||
|
(let [delta-x (- target-x x)
|
||||||
|
speed (* 1.0
|
||||||
|
(/ (:delta-time screen)
|
||||||
|
(/ 1.0 60.0)))
|
||||||
|
speed (if (< delta-x 0) (- speed) speed)
|
||||||
|
moved-x (if (< (Math/abs delta-x) speed)
|
||||||
|
target-x
|
||||||
|
(* speed (/ delta-x delta-x) ))]
|
||||||
|
(if (< (Math/abs delta-x) speed)
|
||||||
|
(actions/start-animation screen
|
||||||
|
(dissoc e :target-x)
|
||||||
|
:stand)
|
||||||
|
|
||||||
|
(actions/start-animation screen
|
||||||
|
(assoc (actions/jump-to screen entities e [(+ moved-x x) y] false)
|
||||||
|
:facing (cond (< delta-x 0) :left
|
||||||
|
(> delta-x 0) :right
|
||||||
|
:else (:facing e)))
|
||||||
|
:walk))))
|
||||||
|
|
||||||
(defn jump-around [screen entities]
|
(defn jump-around [screen entities]
|
||||||
(when (and (not (get-in entities [:actions :script-running?]))
|
(if-let [target-x (get-in entities [:room :entities :lamb :target-x])]
|
||||||
(get-in entities [:state :active?]))
|
(update-in entities [:room :entities :lamb]
|
||||||
(let [x (rand-nth [30 10 60 70])]
|
#(move-toward screen entities % target-x))
|
||||||
((actions/get-script entities (actions/walk-straight-to entities :lamb [x 130]) :update-baseline? false) entities)))
|
(if (= 1 (rand-int 50))
|
||||||
nil)
|
(assoc-in entities [:room :entities :lamb :target-x] (rand-nth [30 10 60 70]))
|
||||||
|
entities)))
|
||||||
|
|
||||||
(defn make [screen]
|
(defn make [screen]
|
||||||
(let [sheep-stand-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
|
(let [sheep-stand-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
|
||||||
@@ -246,10 +268,10 @@
|
|||||||
cauldron (utils/make-anim "outsidehouse/cauldron.png" [50 38] 0.15 (range 4))
|
cauldron (utils/make-anim "outsidehouse/cauldron.png" [50 38] 0.15 (range 4))
|
||||||
scaler (utils/scaler-fn-with-baseline 110 0.10 1.00)
|
scaler (utils/scaler-fn-with-baseline 110 0.10 1.00)
|
||||||
lamb-stand (aget lamb-walk-sheet 0 0)
|
lamb-stand (aget lamb-walk-sheet 0 0)
|
||||||
lamb-walk (animation 0.05 (for [i (range 4)]
|
lamb-walk (animation 0.075 (for [i (range 4)]
|
||||||
(aget lamb-walk-sheet 0 i)))]
|
(aget lamb-walk-sheet 0 i)))]
|
||||||
(rooms/make :music {:day :town-2 :night :night}
|
(rooms/make :music {:day :town-2 :night :night}
|
||||||
:timers {:jump-around [1.0 2.0 jump-around]}
|
:update-fn jump-around
|
||||||
:interactions
|
:interactions
|
||||||
{:door {:box [258 100 281 160]
|
{:door {:box [258 100 281 160]
|
||||||
:script
|
:script
|
||||||
@@ -350,14 +372,19 @@
|
|||||||
:scaled true)
|
:scaled true)
|
||||||
sheep-stand)
|
sheep-stand)
|
||||||
:lamb (assoc (texture "outsidehouse/lamb.png")
|
:lamb (assoc (texture "outsidehouse/lamb.png")
|
||||||
:x 10 :y 130 :baseline 90
|
:x 10 :y 163 :baseline 77
|
||||||
:right {:stand (animation 0.1 [lamb-stand])
|
:right {:stand (animation 0.1 [lamb-stand])
|
||||||
:walk lamb-walk}
|
:walk lamb-walk}
|
||||||
|
|
||||||
:left {:stand (utils/flip (animation 0.1 [lamb-stand]))
|
:left {:stand (utils/flip (animation 0.1 [lamb-stand]))
|
||||||
:walk (utils/flip lamb-walk)}
|
:walk (utils/flip lamb-walk)}
|
||||||
:scale-x (scaler [10 150])
|
:scale-x (scaler [10 163])
|
||||||
:scale-y (scaler [10 150]))
|
:scale-y (scaler [10 163])
|
||||||
|
:script (actions/get-script entities
|
||||||
|
(actions/talk entities :ego "Aww, it's a newborn lamb!"))
|
||||||
|
:scripts {:carrot (actions/get-script entities (actions/talk entities :ego "I think it's still nursing."))
|
||||||
|
:grass (actions/get-script entities (actions/talk entities :ego "I think it's still nursing."))}
|
||||||
|
)
|
||||||
:butterfly (assoc (animation->texture screen butterfly-stand)
|
:butterfly (assoc (animation->texture screen butterfly-stand)
|
||||||
:x 161
|
:x 161
|
||||||
:y 218
|
:y 218
|
||||||
@@ -392,7 +419,8 @@
|
|||||||
:apply-state (fn [entities]
|
:apply-state (fn [entities]
|
||||||
(as-> entities entities
|
(as-> entities entities
|
||||||
(if (get-in entities [:state :coaxed-sheep?])
|
(if (get-in entities [:state :coaxed-sheep?])
|
||||||
(update-in entities [:room :entities :sheep] #(assoc % :x 90 :y 138 :baseline 40))
|
(let [scale ((get-in entities [:room :scale-fn]) [90 138])]
|
||||||
|
(update-in entities [:room :entities :sheep] #(assoc % :x 90 :y 138 :baseline 40 :scale-x scale :scale-y scale)))
|
||||||
entities)
|
entities)
|
||||||
(if (= :night (get-in entities [:state :time]))
|
(if (= :night (get-in entities [:state :time]))
|
||||||
(make-night entities)
|
(make-night entities)
|
||||||
|
|||||||
@@ -423,6 +423,11 @@
|
|||||||
(sound! (or (snd e)
|
(sound! (or (snd e)
|
||||||
(snd (:sounds entities))) :play vol 1.0 pan))))))
|
(snd (:sounds entities))) :play vol 1.0 pan))))))
|
||||||
|
|
||||||
|
(defn update-from-room [screen entities]
|
||||||
|
(if-let [update-fn (get-in entities [:room :update-fn])]
|
||||||
|
(update-fn screen entities)
|
||||||
|
entities))
|
||||||
|
|
||||||
|
|
||||||
(defscreen scene
|
(defscreen scene
|
||||||
:on-timer
|
:on-timer
|
||||||
@@ -514,6 +519,7 @@
|
|||||||
entities (utils/apply-tweens screen entities (:tweens entities))
|
entities (utils/apply-tweens screen entities (:tweens entities))
|
||||||
entities (update-cursor screen entities)
|
entities (update-cursor screen entities)
|
||||||
entities (update-from-script screen entities)
|
entities (update-from-script screen entities)
|
||||||
|
entities (update-from-room screen entities)
|
||||||
entities (update-from-hotspots screen entities)
|
entities (update-from-hotspots screen entities)
|
||||||
entities (assoc-in entities [:room :entities :ego :last-frame] (get-in entities [:room :entities :ego :object]))
|
entities (assoc-in entities [:room :entities :ego :last-frame] (get-in entities [:room :entities :ego :object]))
|
||||||
entities (update-in entities [:room :entities] (fn [entities]
|
entities (update-in entities [:room :entities] (fn [entities]
|
||||||
@@ -545,6 +551,8 @@
|
|||||||
layers (get-layers entities)
|
layers (get-layers entities)
|
||||||
|
|
||||||
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]
|
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]
|
||||||
|
(when (nil? (:zoom (:cam entities)))
|
||||||
|
(println entities))
|
||||||
(set! (. camera zoom) (:zoom (:cam entities)))
|
(set! (. camera zoom) (:zoom (:cam entities)))
|
||||||
(set! (.. camera position x) (:x (:cam entities) 160.0))
|
(set! (.. camera position x) (:x (:cam entities) 160.0))
|
||||||
(set! (.. camera position y) (:y (:cam entities) 120.0))
|
(set! (.. camera position y) (:y (:cam entities) 120.0))
|
||||||
|
|||||||
Reference in New Issue
Block a user