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