drawing player

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

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

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

Loading…
Cancel
Save