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 ))
|
||||
|
||||
(defn right-click [screen entities]
|
||||
(let [entities (update-in entities [:cursor] #(assoc % :cursor-index (+next-cursor+ (:cursor-index %))))]
|
||||
(input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :cursor-index])) 0 0 )
|
||||
(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)
|
||||
entities))
|
||||
|
||||
(defn left-click [screen entities]
|
||||
(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
|
||||
(:collision (:background entities))
|
||||
[(int (:x (:ego entities))) (int (:y (:ego entities)))]
|
||||
[(int x) (int y)])))))
|
||||
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
|
||||
path (vec (take-nth 2 (advent.pathfind/visit-all
|
||||
(:collision (:background entities))
|
||||
[(int (:x (:ego entities))) (int (:y (:ego entities)))]
|
||||
[(int x) (int y)])))]
|
||||
(assoc-in entities [:ego :target-path] (when (seq path) (conj path [x y])))))
|
||||
|
||||
(defn get-ego [screen]
|
||||
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
||||
@@ -47,7 +48,9 @@
|
||||
:anim (animation 0.075 (for [i (range 8)]
|
||||
(texture (aget player-sheet 0 i))))
|
||||
: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"}]
|
||||
(merge (animation->texture screen (:anim ego)) ego)))
|
||||
|
||||
@@ -57,23 +60,28 @@
|
||||
[target-x target-y] (first target-path)
|
||||
target {:x target-x :y target-y}]
|
||||
(if (and target (seq target-path))
|
||||
(let [delta-x (- (:x target) (:x ego))
|
||||
delta-y (- (:y target) (:y ego))
|
||||
(let [delta-x (- (:x target) (:character-x ego))
|
||||
delta-y (- (:y target) (:character-y ego))
|
||||
mag (Math/sqrt (+ (* delta-x delta-x) (* delta-y delta-y)))
|
||||
vector-x (* 1.5 (/ delta-x mag))
|
||||
vector-y (* 1.5 (/ delta-y mag))]
|
||||
(if (< mag 1)
|
||||
(update-in ego [:target-path] rest)
|
||||
(merge (-> ego
|
||||
(update-in [:x] #(+ % vector-x))
|
||||
(update-in [:y] #(+ % vector-y))
|
||||
(assoc-in [:baseline] (- 240 (:y ego)))
|
||||
(assoc-in [:anim] (if (< vector-x 0)
|
||||
(:left ego)
|
||||
(:right ego))))
|
||||
(merge (as-> ego _
|
||||
(update-in _ [:x] #(+ % vector-x))
|
||||
(update-in _ [:y] #(+ % vector-y))
|
||||
(assoc-in _ [:character-x] (+ 8 (:x _)))
|
||||
(assoc-in _ [:character-y] (:y _))
|
||||
(assoc-in _ [:baseline] (- 240 (:y _)))
|
||||
(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)))))
|
||||
|
||||
(dissoc ego :target-path))))
|
||||
(merge (dissoc ego :target-path) (texture (animation! (:anim ego) :get-key-frame 0.6))))))
|
||||
(defscreen main-screen
|
||||
:on-show
|
||||
(fn [screen entities]
|
||||
@@ -82,8 +90,11 @@
|
||||
_ (input! :set-cursor-image (cursor "cursor.png" 0) 0 0)
|
||||
background (texture "bg5.png")
|
||||
house (texture "house.png")
|
||||
overdirt (texture "overdirt.png")]
|
||||
{:cursor {:id "cursor" :cursor-index 0}
|
||||
overdirt (texture "overdirt.png")
|
||||
music (sound "outside-house.mp3")
|
||||
_ (sound! music :loop)]
|
||||
{
|
||||
:cursor {:id "cursor" :cursor-index 0 :hotspot [63 63]}
|
||||
:background (assoc background
|
||||
:id "background" :x 0 :y 0
|
||||
:collision (advent.pathfind/map-from-resource "pathfind-test-big.png")
|
||||
@@ -109,9 +120,12 @@
|
||||
|
||||
|
||||
:on-touch-down (fn [screen [entities]]
|
||||
(if (= (button-code :right) (:button screen))
|
||||
(right-click screen entities)
|
||||
(left-click screen entities))))
|
||||
(let [screen (-> screen
|
||||
(update-in [:input-x] #(+ % (first (:hotspot (:cursor 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
|
||||
:on-create
|
||||
|
||||
Reference in New Issue
Block a user