diff --git a/src/cljs/topdown2d/core.cljs b/src/cljs/topdown2d/core.cljs index c3e55f7..aa06b81 100644 --- a/src/cljs/topdown2d/core.cljs +++ b/src/cljs/topdown2d/core.cljs @@ -19,8 +19,8 @@ ;; difference between prev and now in seconds :elapsed 0} ;; width and height of the canvas - :dimensions {:w 1200 - :h 500} + :dimensions {:w 1280 + :h 800} :input {:dir :?} ;; currently active scene :scene :demo @@ -150,6 +150,13 @@ (defn init-scenes "initiates the scene data maps using their respective init functions" [] + (aset (:ctx gamestate) + "imageSmoothingEnabled" + false) + (aset (:canvas gamestate) + "width" (get-in gamestate [:dimensions :w])) + (aset (:canvas gamestate) + "height" (get-in gamestate [:dimensions :h])) (update gamestate :scenes #(reduce diff --git a/src/cljs/topdown2d/demoscene.cljs b/src/cljs/topdown2d/demoscene.cljs index 3765c2a..c845475 100644 --- a/src/cljs/topdown2d/demoscene.cljs +++ b/src/cljs/topdown2d/demoscene.cljs @@ -14,8 +14,9 @@ (.then #(reset! map-def (js->clj %)))) (merge scenestate - {:tileset {:images {:pokelike (by-id "demoscene-tileset")} - :def nil} + {:map-def {:images {:pokelike (by-id "demoscene-tileset")} + :def nil + :zoom 5} :player {:x (- (/ (get-in gamestate [:dimensions :w]) 2) 32) :y (- (/ (get-in gamestate [:dimensions :h]) 2) 32) :d :s @@ -48,28 +49,31 @@ (:keep-in viewport) (collision/pps->px gamestate viewport))) -(defn map-tileset-size [tileset] +(defn map-tilesets [zoom tileset] (-> tileset + (assoc :target-width (* zoom (:tilewidth tileset))) + (assoc :target-height (* zoom (:tileheight tileset))) (assoc :tiles-x (:columns tileset)) (assoc :tiles-y (/ (:tilecount tileset) (:columns tileset))))) (defn map-layer-tiles [map-def] (let [ftileset (first (:tilesets map-def))] - (-> map-def - (update :layers - #(map (partial tileset/layer->dest ftileset) %))))) + (update map-def :layers + #(map (partial tileset/layer->dest ftileset) + %)))) (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)) - (assoc-in - scenestate - [:tileset :def] - (-> @map-def - (walk/keywordize-keys) - (update :tilesets #(map map-tileset-size %)) - map-layer-tiles)) + (let [zoom (get-in scenestate [:map-def :zoom])] + (assoc-in + scenestate + [:map-def :def] + (-> @map-def + (walk/keywordize-keys) + (update :tilesets #(map (partial map-tilesets zoom) %)) + map-layer-tiles))) scenestate)) (defn update-scene [gamestate scenestate] @@ -84,8 +88,8 @@ (defn draw-scene [gamestate scenestate] (let [viewport (:viewport scenestate) {:keys [x y w h background]} viewport] - (when (get-in scenestate [:tileset :def]) - (tileset/draw-viewport (:tileset scenestate) + (when (get-in scenestate [:map-def :def]) + (tileset/draw-viewport (:map-def scenestate) (:ctx gamestate) viewport)) #_(.drawImage diff --git a/src/cljs/topdown2d/tileset.cljs b/src/cljs/topdown2d/tileset.cljs index e0341c2..2a65b5c 100644 --- a/src/cljs/topdown2d/tileset.cljs +++ b/src/cljs/topdown2d/tileset.cljs @@ -44,24 +44,25 @@ (fn [ix tile] (let [{:keys [width height]} layer [dxc dyc] (ix->coords ix width height) - {:keys [tilewidth tileheight]} tileset] + {:keys [target-width target-height]} tileset] {:tile tile - :x (* dxc tilewidth) - :y (* dyc tileheight) - :w tilewidth - :h tileheight})) + :x (* dxc target-width) + :y (* dyc target-height) + :w target-width + :h target-height})) (:data layer))) (defn draw-tile [ctx tileset image tileid dest] (let [{:keys [tileheight tilewidth - tiles-x tiles-y]} tileset + tiles-x tiles-y + target-width target-height]} tileset [x y] (ix->coords tileid tiles-x tiles-y) sx (* x tilewidth) sy (* y tileheight)] (.drawImage ctx image sx sy tilewidth tileheight (:x dest) (:y dest) - tilewidth tileheight))) + target-width target-height))) (defn draw-viewport [map-def ctx viewport] (let [{:keys [images def]} map-def