simple scaling.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.8 KiB |
@@ -27,16 +27,17 @@
|
|||||||
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 %))))]
|
(let [entities (update-in entities [:cursor] #(assoc % :cursor-index (+next-cursor+ (:cursor-index %)) :hotspot [63 63]))]
|
||||||
(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))
|
||||||
|
|
||||||
(defn left-click [screen entities]
|
(defn left-click [screen entities]
|
||||||
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
|
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
|
||||||
(assoc-in entities [:ego :target-path] (take-nth 2 (advent.pathfind/visit-all
|
path (vec (take-nth 2 (advent.pathfind/visit-all
|
||||||
(:collision (:background entities))
|
(:collision (:background entities))
|
||||||
[(int (:x (:ego entities))) (int (:y (:ego entities)))]
|
[(int (:x (:ego entities))) (int (:y (:ego entities)))]
|
||||||
[(int x) (int y)])))))
|
[(int x) (int y)])))]
|
||||||
|
(assoc-in entities [:ego :target-path] (when (seq path) (conj path [x y])))))
|
||||||
|
|
||||||
(defn get-ego [screen]
|
(defn get-ego [screen]
|
||||||
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
||||||
@@ -47,7 +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
|
||||||
:x 150 :y 95 :x-velocity 1
|
:origin-x 16
|
||||||
|
: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)))
|
||||||
|
|
||||||
@@ -57,23 +60,28 @@
|
|||||||
[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) (:x ego))
|
(let [delta-x (- (:x target) (:character-x ego))
|
||||||
delta-y (- (:y target) (:y ego))
|
delta-y (- (:y target) (:character-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 (-> ego
|
(merge (as-> ego _
|
||||||
(update-in [:x] #(+ % vector-x))
|
(update-in _ [:x] #(+ % vector-x))
|
||||||
(update-in [:y] #(+ % vector-y))
|
(update-in _ [:y] #(+ % vector-y))
|
||||||
(assoc-in [:baseline] (- 240 (:y ego)))
|
(assoc-in _ [:character-x] (+ 8 (:x _)))
|
||||||
(assoc-in [:anim] (if (< vector-x 0)
|
(assoc-in _ [:character-y] (:y _))
|
||||||
(:left ego)
|
(assoc-in _ [:baseline] (- 240 (:y _)))
|
||||||
(:right ego))))
|
(assoc-in _ [:anim] (if (< vector-x 0)
|
||||||
|
(:left _)
|
||||||
|
(:right _)))
|
||||||
|
(assoc-in _ [:scale-x] (/ 1 (/ 240 (- 310 (:y _)))))
|
||||||
|
(assoc-in _ [:scale-y] (/ 1 (/ 240 (- 310 (:y _))))))
|
||||||
|
|
||||||
(animation->texture screen (:anim ego)))))
|
(animation->texture screen (:anim ego)))))
|
||||||
|
|
||||||
(dissoc ego :target-path))))
|
(merge (dissoc ego :target-path) (texture (animation! (:anim ego) :get-key-frame 0.6))))))
|
||||||
(defscreen main-screen
|
(defscreen main-screen
|
||||||
:on-show
|
:on-show
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
@@ -82,8 +90,11 @@
|
|||||||
_ (input! :set-cursor-image (cursor "cursor.png" 0) 0 0)
|
_ (input! :set-cursor-image (cursor "cursor.png" 0) 0 0)
|
||||||
background (texture "bg5.png")
|
background (texture "bg5.png")
|
||||||
house (texture "house.png")
|
house (texture "house.png")
|
||||||
overdirt (texture "overdirt.png")]
|
overdirt (texture "overdirt.png")
|
||||||
{:cursor {:id "cursor" :cursor-index 0}
|
music (sound "outside-house.mp3")
|
||||||
|
_ (sound! music :loop)]
|
||||||
|
{
|
||||||
|
:cursor {:id "cursor" :cursor-index 0 :hotspot [63 63]}
|
||||||
: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")
|
||||||
@@ -109,9 +120,12 @@
|
|||||||
|
|
||||||
|
|
||||||
:on-touch-down (fn [screen [entities]]
|
:on-touch-down (fn [screen [entities]]
|
||||||
(if (= (button-code :right) (:button screen))
|
(let [screen (-> screen
|
||||||
(right-click screen entities)
|
(update-in [:input-x] #(+ % (first (:hotspot (:cursor entities)))))
|
||||||
(left-click screen entities))))
|
(update-in [:input-y] #(+ % (second (:hotspot (:cursor entities))))))]
|
||||||
|
(if (= (button-code :right) (:button screen))
|
||||||
|
(right-click screen entities)
|
||||||
|
(left-click screen entities)))))
|
||||||
|
|
||||||
(defgame advent
|
(defgame advent
|
||||||
:on-create
|
:on-create
|
||||||
|
|||||||
Reference in New Issue
Block a user