drawing player

master
Josha von Gizycki 6 years ago
parent 62c49be8d4
commit 2539099cb8

@ -25,10 +25,13 @@
:e 819 :w 819} :e 819 :w 819}
:last-cycle 0 :last-cycle 0
:curr-id 778 :curr-id 778
:tileset :pokelike}} :tileset :pokelike
:tileset-def nil
:image (by-id "demoscene-tileset")}}
:viewport {:keep-in {:x 0 :y 0 :viewport {:keep-in {:x 0 :y 0
:w 0 :h 0} :w 0 :h 0}
:tileset :pokelike :tileset :pokelike
:image (by-id "demoscene-tileset")
:tileset-def nil :tileset-def nil
:x 6 :y 9 :x 6 :y 9
:w (get-in gamestate [:dimensions :w]) :w (get-in gamestate [:dimensions :w])
@ -54,7 +57,7 @@
(defn init-viewport [scenestate] (defn init-viewport [scenestate]
(let [{loaded-def :def (let [{loaded-def :def
zoom :zoom} (get-in scenestate [:map-def]) zoom :zoom} (:map-def scenestate)
viewport (:viewport scenestate) viewport (:viewport scenestate)
{mw :width mh :height {mw :width mh :height
tw :tilewidth th :tileheight} loaded-def] tw :tilewidth th :tileheight} loaded-def]
@ -67,6 +70,20 @@
(tileset/map-def->tileset loaded-def (tileset/map-def->tileset loaded-def
(:tileset viewport)))))) (:tileset viewport))))))
(defn init-player [scenestate]
(let [{tw :tilewidth th :tileheight :as map-def}
(get-in scenestate [:map-def :def])
zoom (-> scenestate :map-def :zoom)]
(-> scenestate
(assoc-in [:player :w] (- tw 2))
(assoc-in [:player :h] (- th 2))
(update-in [:player :x] - (* zoom (/ tw 2)))
(update-in [:player :y] - (* zoom (/ th 2)))
(assoc-in [:player :animation :tileset-def]
(tileset/map-def->tileset map-def
(get-in scenestate
[:player :animation :tileset]))))))
(defn init-map-def [scenestate] (defn init-map-def [scenestate]
(if (and (not (get-in scenestate [:map-def :def])) (if (and (not (get-in scenestate [:map-def :def]))
(some? @map-def)) (some? @map-def))
@ -79,10 +96,7 @@
(assoc-in [:map-def :def] loaded-def) (assoc-in [:map-def :def] loaded-def)
(update-in [:map-def :def] (update-in [:map-def :def]
(partial tileset/prepare-map-def zoom)) (partial tileset/prepare-map-def zoom))
(assoc-in [:player :w] (- tw 2)) init-player
(assoc-in [:player :h] (- th 2))
(update-in [:player :w] - (/ tw 2))
(update-in [:player :h] - (/ th 2))
init-viewport)) init-viewport))
scenestate)) scenestate))
@ -97,16 +111,16 @@
(defn draw-scene [gamestate scenestate] (defn draw-scene [gamestate scenestate]
(let [viewport (:viewport scenestate) (let [viewport (:viewport scenestate)
{:keys [x y w h background]} viewport] {:keys [x y w h background]} viewport
ctx (:ctx gamestate)]
(when (get-in scenestate [:map-def :def]) (when (get-in scenestate [:map-def :def])
(tileset/draw-viewport (:map-def scenestate) (tileset/draw-viewport (:map-def scenestate)
(:ctx gamestate) ctx
viewport)) viewport)
#_(.drawImage (let [{:keys [tileset-def curr-id image]}
(:ctx gamestate) (get-in scenestate [:player :animation])]
(:image viewport) (tileset/draw-tile ctx
x y w h tileset-def
0 0 w h)) image
#_ (sprites/draw curr-id
(:ctx gamestate) (:player scenestate))))))
(:player scenestate)))

@ -82,11 +82,11 @@
map-layers)) map-layers))
(defn draw-viewport [map-def ctx viewport] (defn draw-viewport [map-def ctx viewport]
(let [{:keys [images def]} map-def (let [def (:def map-def)
{:keys [tileheight tilewidth {:keys [tileheight tilewidth
height width layers]} def height width layers]} def
tileset-id (:tileset viewport) tileset-id (:tileset viewport)
image (tileset-id images) image (:image viewport)
tileset (:tileset-def viewport)] tileset (:tileset-def viewport)]
(doseq [layer layers] (doseq [layer layers]
(doseq [dest layer (doseq [dest layer

Loading…
Cancel
Save