disable useless smoothing, zoom

master
Josha von Gizycki 6 years ago
parent 635c391e54
commit 56a69fcc34

@ -19,8 +19,8 @@
;; difference between prev and now in seconds ;; difference between prev and now in seconds
:elapsed 0} :elapsed 0}
;; width and height of the canvas ;; width and height of the canvas
:dimensions {:w 1200 :dimensions {:w 1280
:h 500} :h 800}
:input {:dir :?} :input {:dir :?}
;; currently active scene ;; currently active scene
:scene :demo :scene :demo
@ -150,6 +150,13 @@
(defn init-scenes (defn init-scenes
"initiates the scene data maps using their respective init functions" "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 (update gamestate
:scenes :scenes
#(reduce #(reduce

@ -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))
(assoc-in (let [zoom (get-in scenestate [:map-def :zoom])]
scenestate (assoc-in
[:tileset :def] scenestate
(-> @map-def [:map-def :def]
(walk/keywordize-keys) (-> @map-def
(update :tilesets #(map map-tileset-size %)) (walk/keywordize-keys)
map-layer-tiles)) (update :tilesets #(map (partial map-tilesets zoom) %))
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

@ -44,24 +44,25 @@
(fn [ix tile] (fn [ix tile]
(let [{:keys [width height]} layer (let [{:keys [width height]} layer
[dxc dyc] (ix->coords ix width height) [dxc dyc] (ix->coords ix width height)
{:keys [tilewidth tileheight]} tileset] {:keys [target-width target-height]} tileset]
{:tile tile {:tile tile
:x (* dxc tilewidth) :x (* dxc target-width)
:y (* dyc tileheight) :y (* dyc target-height)
:w tilewidth :w target-width
:h tileheight})) :h target-height}))
(:data layer))) (:data layer)))
(defn draw-tile [ctx tileset image tileid dest] (defn draw-tile [ctx tileset image tileid dest]
(let [{:keys [tileheight tilewidth (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) [x y] (ix->coords tileid tiles-x tiles-y)
sx (* x tilewidth) sx (* x tilewidth)
sy (* y tileheight)] sy (* y tileheight)]
(.drawImage ctx image (.drawImage ctx image
sx sy tilewidth tileheight sx sy tilewidth tileheight
(:x dest) (:y dest) (:x dest) (:y dest)
tilewidth tileheight))) target-width target-height)))
(defn draw-viewport [map-def ctx viewport] (defn draw-viewport [map-def ctx viewport]
(let [{:keys [images def]} map-def (let [{:keys [images def]} map-def

Loading…
Cancel
Save