refactors and cleanups.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.2 KiB |
@@ -27,7 +27,7 @@
|
|||||||
resized ))
|
resized ))
|
||||||
|
|
||||||
(defn right-click [screen entities]
|
(defn right-click [screen entities]
|
||||||
(let [entities (update-in entities [:cursor] #(assoc % :cursor-index (+next-cursor+ (:cursor-index %)) :hotspot [63 63]))]
|
(let [entities (update-in entities [:cursor] #(assoc % :cursor-index (+next-cursor+ (:cursor-index %)) :hotspot [0 0 ]))]
|
||||||
(input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :cursor-index])) 0 0)
|
(input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :cursor-index])) 0 0)
|
||||||
entities))
|
entities))
|
||||||
|
|
||||||
@@ -48,9 +48,9 @@
|
|||||||
:anim (animation 0.075 (for [i (range 8)]
|
:anim (animation 0.075 (for [i (range 8)]
|
||||||
(texture (aget player-sheet 0 i))))
|
(texture (aget player-sheet 0 i))))
|
||||||
:baseline 95
|
:baseline 95
|
||||||
:origin-x 16
|
:origin-x 0
|
||||||
|
:origin-y 0
|
||||||
:x 150 :y 95 :x-velocity 1
|
:x 150 :y 95 :x-velocity 1
|
||||||
:character-x 158 :character-y 95
|
|
||||||
:id "ego"}]
|
:id "ego"}]
|
||||||
(merge (animation->texture screen (:anim ego)) ego)))
|
(merge (animation->texture screen (:anim ego)) ego)))
|
||||||
|
|
||||||
@@ -60,28 +60,37 @@
|
|||||||
[target-x target-y] (first target-path)
|
[target-x target-y] (first target-path)
|
||||||
target {:x target-x :y target-y}]
|
target {:x target-x :y target-y}]
|
||||||
(if (and target (seq target-path))
|
(if (and target (seq target-path))
|
||||||
(let [delta-x (- (:x target) (:character-x ego))
|
(let [scale-fn (-> entities :background :scale-fn)
|
||||||
delta-y (- (:y target) (:character-y ego))
|
delta-x (- (:x target) (:x ego))
|
||||||
|
delta-y (- (:y target) (:y ego))
|
||||||
mag (Math/sqrt (+ (* delta-x delta-x) (* delta-y delta-y)))
|
mag (Math/sqrt (+ (* delta-x delta-x) (* delta-y delta-y)))
|
||||||
vector-x (* 1.5 (/ delta-x mag))
|
vector-x (* 1.5 (/ delta-x mag))
|
||||||
vector-y (* 1.5 (/ delta-y mag))]
|
vector-y (* 1.5 (/ delta-y mag))]
|
||||||
(if (< mag 1)
|
(if (< mag 1)
|
||||||
(update-in ego [:target-path] rest)
|
(update-in ego [:target-path] rest)
|
||||||
(merge (as-> ego _
|
(do
|
||||||
(update-in _ [:x] #(+ % vector-x))
|
(merge (as-> ego _
|
||||||
(update-in _ [:y] #(+ % vector-y))
|
(update-in _ [:x] #(+ % vector-x))
|
||||||
(assoc-in _ [:character-x] (+ 8 (:x _)))
|
(update-in _ [:y] #(+ % vector-y))
|
||||||
(assoc-in _ [:character-y] (:y _))
|
(assoc-in _ [:baseline] (- 240 (:y _)))
|
||||||
(assoc-in _ [:baseline] (- 240 (:y _)))
|
(assoc-in _ [:anim] (if (< vector-x 0)
|
||||||
(assoc-in _ [:anim] (if (< vector-x 0)
|
(:left _)
|
||||||
(:left _)
|
(:right _)))
|
||||||
(:right _)))
|
(assoc-in _ [:scale-x] (scale-fn (:y _)))
|
||||||
(assoc-in _ [:scale-x] (/ 1 (/ 240 (- 310 (:y _)))))
|
(assoc-in _ [:scale-y] (scale-fn (:y _))))
|
||||||
(assoc-in _ [:scale-y] (/ 1 (/ 240 (- 310 (:y _))))))
|
|
||||||
|
|
||||||
(animation->texture screen (:anim ego)))))
|
(animation->texture screen (:anim ego))))))
|
||||||
|
|
||||||
(merge (dissoc ego :target-path) (texture (animation! (:anim ego) :get-key-frame 0.6))))))
|
(merge (dissoc ego :target-path) (texture (animation! (:anim ego) :get-key-frame 0.6))))))
|
||||||
|
|
||||||
|
(defn scaler-fn-with-baseline [baseline minimum-size & [maximum-size]]
|
||||||
|
(let [maximum-size (or maximum-size 1.0)]
|
||||||
|
(fn [y]
|
||||||
|
(if (< y baseline) maximum-size
|
||||||
|
(let [percent-complete (- 1.0 (/ (- y baseline) (- +screen-height+ baseline)))
|
||||||
|
range (+ (* percent-complete (- maximum-size minimum-size)) minimum-size)]
|
||||||
|
range)))))
|
||||||
|
|
||||||
(defscreen main-screen
|
(defscreen main-screen
|
||||||
:on-show
|
:on-show
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
@@ -98,7 +107,8 @@
|
|||||||
:background (assoc background
|
:background (assoc background
|
||||||
:id "background" :x 0 :y 0
|
:id "background" :x 0 :y 0
|
||||||
:collision (advent.pathfind/map-from-resource "pathfind-test-big.png")
|
:collision (advent.pathfind/map-from-resource "pathfind-test-big.png")
|
||||||
:baseline 0)
|
:baseline 0
|
||||||
|
:scale-fn (scaler-fn-with-baseline 110 0.10 1.10))
|
||||||
:house (assoc house
|
:house (assoc house
|
||||||
:x 0 :y 0
|
:x 0 :y 0
|
||||||
:baseline 122)
|
:baseline 122)
|
||||||
|
|||||||
Reference in New Issue
Block a user