cool lamb.

This commit is contained in:
2015-02-23 06:49:47 -08:00
parent 61e0b88b9f
commit 19b7df1f1f
2 changed files with 47 additions and 11 deletions

View File

@@ -227,12 +227,34 @@
add-wizard-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]
(when (and (not (get-in entities [:actions :script-running?]))
(get-in entities [:state :active?]))
(let [x (rand-nth [30 10 60 70])]
((actions/get-script entities (actions/walk-straight-to entities :lamb [x 130]) :update-baseline? false) entities)))
nil)
(if-let [target-x (get-in entities [:room :entities :lamb :target-x])]
(update-in entities [:room :entities :lamb]
#(move-toward screen entities % target-x))
(if (= 1 (rand-int 50))
(assoc-in entities [:room :entities :lamb :target-x] (rand-nth [30 10 60 70]))
entities)))
(defn make [screen]
(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))
scaler (utils/scaler-fn-with-baseline 110 0.10 1.00)
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)))]
(rooms/make :music {:day :town-2 :night :night}
:timers {:jump-around [1.0 2.0 jump-around]}
:update-fn jump-around
:interactions
{:door {:box [258 100 281 160]
:script
@@ -350,14 +372,19 @@
:scaled true)
sheep-stand)
: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])
:walk lamb-walk}
:left {:stand (utils/flip (animation 0.1 [lamb-stand]))
:walk (utils/flip lamb-walk)}
:scale-x (scaler [10 150])
:scale-y (scaler [10 150]))
:scale-x (scaler [10 163])
: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)
:x 161
:y 218
@@ -392,7 +419,8 @@
:apply-state (fn [entities]
(as-> entities entities
(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)
(if (= :night (get-in entities [:state :time]))
(make-night entities)

View File

@@ -423,6 +423,11 @@
(sound! (or (snd e)
(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
:on-timer
@@ -514,6 +519,7 @@
entities (utils/apply-tweens screen entities (:tweens entities))
entities (update-cursor screen entities)
entities (update-from-script screen entities)
entities (update-from-room 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 (update-in entities [:room :entities] (fn [entities]
@@ -545,6 +551,8 @@
layers (get-layers 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 position x) (:x (:cam entities) 160.0))
(set! (.. camera position y) (:y (:cam entities) 120.0))