|
|
|
@ -13,47 +13,47 @@
|
|
|
|
|
(.then #(.json %))
|
|
|
|
|
(.then #(reset! map-def (js->clj %))))
|
|
|
|
|
(merge
|
|
|
|
|
scenestate
|
|
|
|
|
{:map-def {:images {:pokelike (by-id "demoscene-tileset")}
|
|
|
|
|
:def nil
|
|
|
|
|
:zoom 3}
|
|
|
|
|
:player {:x (/ (get-in gamestate [:dimensions :w]) 2)
|
|
|
|
|
:y (/ (get-in gamestate [:dimensions :h]) 2)
|
|
|
|
|
:w 0 :h 0
|
|
|
|
|
:d :s
|
|
|
|
|
:animation {:ids {:s 778 :n 778
|
|
|
|
|
:e 819 :w 819}
|
|
|
|
|
:last-cycle 0
|
|
|
|
|
:curr-id 778
|
|
|
|
|
: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])
|
|
|
|
|
:h (get-in gamestate [:dimensions :h])
|
|
|
|
|
:d :?
|
|
|
|
|
;; pixels per second
|
|
|
|
|
:pps 150}}))
|
|
|
|
|
scenestate
|
|
|
|
|
{:map-def {:images {:pokelike (by-id "demoscene-tileset")}
|
|
|
|
|
:def nil
|
|
|
|
|
:zoom 3}
|
|
|
|
|
:player {:x (/ (get-in gamestate [:dimensions :w]) 2)
|
|
|
|
|
:y (/ (get-in gamestate [:dimensions :h]) 2)
|
|
|
|
|
:w 0 :h 0
|
|
|
|
|
:d :s
|
|
|
|
|
:animation {:ids {:s 778 :n 778
|
|
|
|
|
:e 819 :w 819}
|
|
|
|
|
:last-cycle 0
|
|
|
|
|
:curr-id 778
|
|
|
|
|
: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])
|
|
|
|
|
:h (get-in gamestate [:dimensions :h])
|
|
|
|
|
:d :?
|
|
|
|
|
;; pixels per second
|
|
|
|
|
:pps 150}}))
|
|
|
|
|
|
|
|
|
|
(defn update-player [gamestate player dir]
|
|
|
|
|
(let [old-dir (:d player)
|
|
|
|
|
new-dir (if (= :? dir) old-dir dir)]
|
|
|
|
|
(as-> player p
|
|
|
|
|
(assoc p :d new-dir)
|
|
|
|
|
(if (= :? dir)
|
|
|
|
|
(sprites/reset player)
|
|
|
|
|
(sprites/proc gamestate p)))))
|
|
|
|
|
(assoc p :d new-dir)
|
|
|
|
|
(if (= :? dir)
|
|
|
|
|
(sprites/reset player)
|
|
|
|
|
(sprites/proc gamestate p)))))
|
|
|
|
|
|
|
|
|
|
(defn update-viewport [gamestate viewport dir]
|
|
|
|
|
(collision/move-inside
|
|
|
|
|
(assoc viewport :d dir)
|
|
|
|
|
(:keep-in viewport)
|
|
|
|
|
(collision/pps->px gamestate viewport)))
|
|
|
|
|
(assoc viewport :d dir)
|
|
|
|
|
(:keep-in viewport)
|
|
|
|
|
(collision/pps->px gamestate viewport)))
|
|
|
|
|
|
|
|
|
|
(defn init-viewport [scenestate]
|
|
|
|
|
(let [{loaded-def :def
|
|
|
|
@ -90,10 +90,7 @@
|
|
|
|
|
(if (and (not (-> scenestate :map-def :def))
|
|
|
|
|
(some? @map-def))
|
|
|
|
|
(let [loaded-def (walk/keywordize-keys @map-def)
|
|
|
|
|
zoom (get-in scenestate [:map-def :zoom])
|
|
|
|
|
viewport (:viewport scenestate)
|
|
|
|
|
{mw :width mh :height
|
|
|
|
|
tw :tilewidth th :tileheight} loaded-def]
|
|
|
|
|
zoom (get-in scenestate [:map-def :zoom])]
|
|
|
|
|
(-> scenestate
|
|
|
|
|
(assoc-in [:map-def :def] loaded-def)
|
|
|
|
|
(update-in [:map-def :def]
|
|
|
|
@ -108,12 +105,11 @@
|
|
|
|
|
viewport (:viewport new-scenestate)
|
|
|
|
|
dir (-> gamestate :input :dir)]
|
|
|
|
|
(assoc new-scenestate
|
|
|
|
|
:player (update-player gamestate player dir)
|
|
|
|
|
:viewport (update-viewport gamestate viewport dir))))
|
|
|
|
|
:player (update-player gamestate player dir)
|
|
|
|
|
:viewport (update-viewport gamestate viewport dir))))
|
|
|
|
|
|
|
|
|
|
(defn draw-scene [gamestate scenestate]
|
|
|
|
|
(let [viewport (:viewport scenestate)
|
|
|
|
|
{:keys [x y w h background]} viewport
|
|
|
|
|
ctx (:ctx gamestate)]
|
|
|
|
|
(when (-> scenestate :map-def :def)
|
|
|
|
|
(tileset/draw-viewport (:map-def scenestate)
|
|
|
|
|