|
|
@ -1,25 +1,19 @@
|
|
|
|
(ns topdown2d.demoscene
|
|
|
|
(ns topdown2d.demoscene
|
|
|
|
(:require
|
|
|
|
(:require
|
|
|
|
[topdown2d.objects :as objects]
|
|
|
|
[topdown2d.collision :as collision]
|
|
|
|
[topdown2d.input :as input]
|
|
|
|
[topdown2d.input :as input]
|
|
|
|
[topdown2d.sprites :as sprites]))
|
|
|
|
[topdown2d.sprites :as sprites]))
|
|
|
|
|
|
|
|
|
|
|
|
(defn init [gamestate scenedata]
|
|
|
|
(defn init [gamestate scenedata]
|
|
|
|
(assoc scenedata
|
|
|
|
(assoc scenedata
|
|
|
|
:data {
|
|
|
|
:data {
|
|
|
|
:bumper {
|
|
|
|
|
|
|
|
:x 100
|
|
|
|
|
|
|
|
:y 80
|
|
|
|
|
|
|
|
:w 50
|
|
|
|
|
|
|
|
:h 50
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
:player {
|
|
|
|
:player {
|
|
|
|
:x 0 :y 0
|
|
|
|
:x (- (/ (get-in gamestate [:dimensions :w]) 2) 32)
|
|
|
|
|
|
|
|
:y (- (/ (get-in gamestate [:dimensions :h]) 2) 32)
|
|
|
|
:w 64 :h 64
|
|
|
|
:w 64 :h 64
|
|
|
|
:pps 150
|
|
|
|
|
|
|
|
:d :?
|
|
|
|
:d :?
|
|
|
|
:sprite {
|
|
|
|
:sprite {
|
|
|
|
:image (.getElementById js/document "player")
|
|
|
|
:image (.getElementById js/document "demo-player")
|
|
|
|
:size 64
|
|
|
|
:size 64
|
|
|
|
:d :s
|
|
|
|
:d :s
|
|
|
|
:rows {
|
|
|
|
:rows {
|
|
|
@ -28,15 +22,26 @@
|
|
|
|
:? 2
|
|
|
|
:? 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
:cycle {
|
|
|
|
:cycle {
|
|
|
|
:count 8
|
|
|
|
|
|
|
|
:from 1
|
|
|
|
|
|
|
|
:pos 0
|
|
|
|
:pos 0
|
|
|
|
|
|
|
|
:from 1 :count 8
|
|
|
|
: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")
|
|
|
|
|
|
|
|
:keep-in {
|
|
|
|
|
|
|
|
:x 0 :y 0
|
|
|
|
|
|
|
|
:w 2239 :h 2235
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
:x 1 :y 1
|
|
|
|
|
|
|
|
:d :?
|
|
|
|
|
|
|
|
:pps 350
|
|
|
|
|
|
|
|
:w (get-in gamestate [:dimensions :w])
|
|
|
|
|
|
|
|
:h (get-in gamestate [:dimensions :h])
|
|
|
|
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
(defn update-player [gamestate player dir]
|
|
|
|
(defn update-player [gamestate player dir]
|
|
|
@ -50,17 +55,30 @@
|
|
|
|
(sprites/proc-cycle gamestate p)
|
|
|
|
(sprites/proc-cycle gamestate p)
|
|
|
|
p))))
|
|
|
|
p))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn update-viewport [gamestate viewport dir]
|
|
|
|
|
|
|
|
(collision/move-inside
|
|
|
|
|
|
|
|
(assoc viewport :d dir)
|
|
|
|
|
|
|
|
(:keep-in viewport)
|
|
|
|
|
|
|
|
(collision/pps->px gamestate viewport)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn update-scene [gamestate scenedata]
|
|
|
|
(defn update-scene [gamestate scenedata]
|
|
|
|
(let [player (get-in scenedata [:data :player])
|
|
|
|
(let [player (get-in scenedata [:data :player])
|
|
|
|
|
|
|
|
viewport (get-in scenedata [:data :viewport])
|
|
|
|
dir (input/dirinput)]
|
|
|
|
dir (input/dirinput)]
|
|
|
|
(assoc-in scenedata
|
|
|
|
(-> scenedata
|
|
|
|
[:data :player]
|
|
|
|
(assoc-in [:data :player]
|
|
|
|
(update-player gamestate player dir))))
|
|
|
|
(update-player gamestate player dir))
|
|
|
|
|
|
|
|
(assoc-in [:data :viewport]
|
|
|
|
|
|
|
|
(update-viewport gamestate viewport dir)))))
|
|
|
|
|
|
|
|
|
|
|
|
(defn draw-scene [gamestate scenedata]
|
|
|
|
(defn draw-scene [gamestate scenedata]
|
|
|
|
(let [{{:keys [bumper player]} :data} scenedata
|
|
|
|
(let [viewport (get-in scenedata [:data :viewport])
|
|
|
|
ctx (:ctx gamestate)]
|
|
|
|
{:keys [x y w h background]} viewport]
|
|
|
|
(let [{:keys [x y w h]} bumper]
|
|
|
|
(.drawImage
|
|
|
|
(.fillRect ctx
|
|
|
|
(:ctx gamestate)
|
|
|
|
x y w h))
|
|
|
|
(:image viewport)
|
|
|
|
(sprites/draw gamestate player)))
|
|
|
|
x y w h
|
|
|
|
|
|
|
|
0 0 w h))
|
|
|
|
|
|
|
|
(sprites/draw
|
|
|
|
|
|
|
|
gamestate
|
|
|
|
|
|
|
|
(get-in scenedata [:data :player])))
|
|
|
|