|
|
@ -14,8 +14,9 @@
|
|
|
|
(.then #(reset! map-def (js->clj %))))
|
|
|
|
(.then #(reset! map-def (js->clj %))))
|
|
|
|
(merge
|
|
|
|
(merge
|
|
|
|
scenestate
|
|
|
|
scenestate
|
|
|
|
{:tileset {:images {:pokelike (by-id "demoscene-tileset")}
|
|
|
|
{:map-def {:images {:pokelike (by-id "demoscene-tileset")}
|
|
|
|
:def nil}
|
|
|
|
:def nil
|
|
|
|
|
|
|
|
:zoom 5}
|
|
|
|
:player {:x (- (/ (get-in gamestate [:dimensions :w]) 2) 32)
|
|
|
|
:player {:x (- (/ (get-in gamestate [:dimensions :w]) 2) 32)
|
|
|
|
:y (- (/ (get-in gamestate [:dimensions :h]) 2) 32)
|
|
|
|
:y (- (/ (get-in gamestate [:dimensions :h]) 2) 32)
|
|
|
|
:d :s
|
|
|
|
:d :s
|
|
|
@ -48,28 +49,31 @@
|
|
|
|
(:keep-in viewport)
|
|
|
|
(:keep-in viewport)
|
|
|
|
(collision/pps->px gamestate viewport)))
|
|
|
|
(collision/pps->px gamestate viewport)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn map-tileset-size [tileset]
|
|
|
|
(defn map-tilesets [zoom tileset]
|
|
|
|
(-> tileset
|
|
|
|
(-> tileset
|
|
|
|
|
|
|
|
(assoc :target-width (* zoom (:tilewidth tileset)))
|
|
|
|
|
|
|
|
(assoc :target-height (* zoom (:tileheight tileset)))
|
|
|
|
(assoc :tiles-x (:columns tileset))
|
|
|
|
(assoc :tiles-x (:columns tileset))
|
|
|
|
(assoc :tiles-y (/ (:tilecount tileset)
|
|
|
|
(assoc :tiles-y (/ (:tilecount tileset)
|
|
|
|
(:columns tileset)))))
|
|
|
|
(:columns tileset)))))
|
|
|
|
|
|
|
|
|
|
|
|
(defn map-layer-tiles [map-def]
|
|
|
|
(defn map-layer-tiles [map-def]
|
|
|
|
(let [ftileset (first (:tilesets map-def))]
|
|
|
|
(let [ftileset (first (:tilesets map-def))]
|
|
|
|
(-> map-def
|
|
|
|
(update map-def :layers
|
|
|
|
(update :layers
|
|
|
|
#(map (partial tileset/layer->dest ftileset)
|
|
|
|
#(map (partial tileset/layer->dest ftileset) %)))))
|
|
|
|
%))))
|
|
|
|
|
|
|
|
|
|
|
|
(defn init-map-def [scenestate]
|
|
|
|
(defn init-map-def [scenestate]
|
|
|
|
(if (and (not (get-in scenestate [:tileset :def]))
|
|
|
|
(if (and (not (get-in scenestate [:map-def :def]))
|
|
|
|
(some? @map-def))
|
|
|
|
(some? @map-def))
|
|
|
|
|
|
|
|
(let [zoom (get-in scenestate [:map-def :zoom])]
|
|
|
|
(assoc-in
|
|
|
|
(assoc-in
|
|
|
|
scenestate
|
|
|
|
scenestate
|
|
|
|
[:tileset :def]
|
|
|
|
[:map-def :def]
|
|
|
|
(-> @map-def
|
|
|
|
(-> @map-def
|
|
|
|
(walk/keywordize-keys)
|
|
|
|
(walk/keywordize-keys)
|
|
|
|
(update :tilesets #(map map-tileset-size %))
|
|
|
|
(update :tilesets #(map (partial map-tilesets zoom) %))
|
|
|
|
map-layer-tiles))
|
|
|
|
map-layer-tiles)))
|
|
|
|
scenestate))
|
|
|
|
scenestate))
|
|
|
|
|
|
|
|
|
|
|
|
(defn update-scene [gamestate scenestate]
|
|
|
|
(defn update-scene [gamestate scenestate]
|
|
|
@ -84,8 +88,8 @@
|
|
|
|
(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]
|
|
|
|
(when (get-in scenestate [:tileset :def])
|
|
|
|
(when (get-in scenestate [:map-def :def])
|
|
|
|
(tileset/draw-viewport (:tileset scenestate)
|
|
|
|
(tileset/draw-viewport (:map-def scenestate)
|
|
|
|
(:ctx gamestate)
|
|
|
|
(:ctx gamestate)
|
|
|
|
viewport))
|
|
|
|
viewport))
|
|
|
|
#_(.drawImage
|
|
|
|
#_(.drawImage
|
|
|
|