|
|
@ -4,11 +4,11 @@
|
|
|
|
[topdown2d.input :as input]
|
|
|
|
[topdown2d.input :as input]
|
|
|
|
[topdown2d.sprites :as sprites]))
|
|
|
|
[topdown2d.sprites :as sprites]))
|
|
|
|
|
|
|
|
|
|
|
|
(defn init [gamestate scenedata]
|
|
|
|
(defn init [gamestate scenestate]
|
|
|
|
(assoc
|
|
|
|
(assoc
|
|
|
|
scenedata
|
|
|
|
scenestate
|
|
|
|
:data
|
|
|
|
:player
|
|
|
|
{:player {:x (- (/ (get-in gamestate [:dimensions :w]) 2) 32)
|
|
|
|
{:x (- (/ (get-in gamestate [:dimensions :w]) 2) 32)
|
|
|
|
:y (- (/ (get-in gamestate [:dimensions :h]) 2) 32)
|
|
|
|
:y (- (/ (get-in gamestate [:dimensions :h]) 2) 32)
|
|
|
|
:w 64 :h 64
|
|
|
|
:w 64 :h 64
|
|
|
|
:d :s
|
|
|
|
:d :s
|
|
|
@ -24,15 +24,16 @@
|
|
|
|
:last-cycle 0
|
|
|
|
:last-cycle 0
|
|
|
|
;; seconds per cycle
|
|
|
|
;; seconds per cycle
|
|
|
|
:spc 0.08}}}
|
|
|
|
:spc 0.08}}}
|
|
|
|
:viewport {:image (.getElementById js/document "demo-background")
|
|
|
|
:viewport
|
|
|
|
|
|
|
|
{:image (.getElementById js/document "demo-background")
|
|
|
|
:keep-in {:x 0 :y 0
|
|
|
|
:keep-in {:x 0 :y 0
|
|
|
|
:w 2239 :h 2235}
|
|
|
|
:w 2239 :h 2235}
|
|
|
|
:x 1 :y 1
|
|
|
|
:x 1 :y 1
|
|
|
|
:d :?
|
|
|
|
:d :?
|
|
|
|
|
|
|
|
;; pixels per second
|
|
|
|
:pps 350
|
|
|
|
:pps 350
|
|
|
|
:w (get-in gamestate [:dimensions :w])
|
|
|
|
:w (get-in gamestate [:dimensions :w])
|
|
|
|
:h (get-in gamestate [:dimensions :h])
|
|
|
|
:h (get-in gamestate [:dimensions :h])}))
|
|
|
|
}}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn update-player [gamestate player dir]
|
|
|
|
(defn update-player [gamestate player dir]
|
|
|
|
(let [old-dir (:d player)
|
|
|
|
(let [old-dir (:d player)
|
|
|
@ -49,18 +50,16 @@
|
|
|
|
(:keep-in viewport)
|
|
|
|
(:keep-in viewport)
|
|
|
|
(collision/pps->px gamestate viewport)))
|
|
|
|
(collision/pps->px gamestate viewport)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn update-scene [gamestate scenedata]
|
|
|
|
(defn update-scene [gamestate scenestate]
|
|
|
|
(let [player (get-in scenedata [:data :player])
|
|
|
|
(let [player (:player scenestate)
|
|
|
|
viewport (get-in scenedata [:data :viewport])
|
|
|
|
viewport (:viewport scenestate)
|
|
|
|
dir (get-in gamestate [:input :dir])]
|
|
|
|
dir (get-in gamestate [:input :dir])]
|
|
|
|
(-> scenedata
|
|
|
|
(assoc scenedata
|
|
|
|
(assoc-in [:data :player]
|
|
|
|
:player (update-player gamestate player dir)
|
|
|
|
(update-player gamestate player dir))
|
|
|
|
:viewport (update-viewport gamestate viewport dir))))
|
|
|
|
(assoc-in [:data :viewport]
|
|
|
|
|
|
|
|
(update-viewport gamestate viewport dir)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn draw-scene [gamestate scenedata]
|
|
|
|
(defn draw-scene [gamestate scenestate]
|
|
|
|
(let [viewport (get-in scenedata [:data :viewport])
|
|
|
|
(let [viewport (:viewport scenestate)
|
|
|
|
{:keys [x y w h background]} viewport]
|
|
|
|
{:keys [x y w h background]} viewport]
|
|
|
|
(.drawImage
|
|
|
|
(.drawImage
|
|
|
|
(:ctx gamestate)
|
|
|
|
(:ctx gamestate)
|
|
|
@ -69,4 +68,4 @@
|
|
|
|
0 0 w h))
|
|
|
|
0 0 w h))
|
|
|
|
(sprites/draw
|
|
|
|
(sprites/draw
|
|
|
|
(:ctx gamestate)
|
|
|
|
(:ctx gamestate)
|
|
|
|
(get-in scenedata [:data :player])))
|
|
|
|
(:player scenestate)))
|
|
|
|