parent
b2baae0b9b
commit
91b35cba12
@ -1,7 +0,0 @@
|
||||
var CLOSURE_UNCOMPILED_DEFINES = null;
|
||||
if(typeof goog == "undefined") document.write('<script src="js/out/goog/base.js"></script>');
|
||||
document.write('<script src="js/out/cljs_deps.js"></script>');
|
||||
document.write('<script>if (typeof goog == "undefined") console.warn("ClojureScript could not load :main, did you forget to specify :asset-path?");</script>');
|
||||
|
||||
document.write("<script>if (typeof goog != \"undefined\") { goog.require(\"figwheel.connect.build_default\"); }</script>");
|
||||
document.write('<script>goog.require("topdown2d.core");</script>');
|
@ -1,7 +1,45 @@
|
||||
(ns topdown2d.demoscene)
|
||||
(ns topdown2d.demoscene
|
||||
(:require
|
||||
[topdown2d.objects :as objects]
|
||||
[topdown2d.input :as input]))
|
||||
|
||||
(defn init [gamestate scenedata]
|
||||
(assoc scenedata
|
||||
:data
|
||||
{
|
||||
:bumper
|
||||
{
|
||||
:x 50
|
||||
:y 50
|
||||
:w 10
|
||||
:h 10
|
||||
:v 0
|
||||
}
|
||||
:box
|
||||
{
|
||||
:x 5
|
||||
:y 5
|
||||
:w 10
|
||||
:h 10
|
||||
:v 5
|
||||
:d :?
|
||||
}
|
||||
}))
|
||||
|
||||
(defn update [gamestate scenedata]
|
||||
(.debug js/console "a")
|
||||
scenedata)
|
||||
(let [box (get-in scenedata [:data :box])
|
||||
dir (input/dirinput)
|
||||
box (assoc box :d dir)]
|
||||
(update-in scenedata
|
||||
[:data :box]
|
||||
#(objects/move box))))
|
||||
|
||||
(defn draw [gamestate scenedata])
|
||||
(defn draw [gamestate scenedata]
|
||||
(let [{{:keys [bumper box]} :data} scenedata
|
||||
ctx (:2d gamestate)]
|
||||
(let [{:keys [x y w h]} bumper]
|
||||
(.fillRect ctx
|
||||
x y w h))
|
||||
(let [{:keys [x y w h]} box]
|
||||
(.strokeRect ctx
|
||||
x y w h))))
|
||||
|
@ -0,0 +1,27 @@
|
||||
(ns topdown2d.input)
|
||||
|
||||
(def keysdown (atom {}))
|
||||
|
||||
(defn keydown? [code]
|
||||
(get @keysdown (name code) false))
|
||||
|
||||
(.addEventListener js/document
|
||||
"keydown"
|
||||
(fn [event]
|
||||
(swap! keysdown #(assoc % (.-code event) true))
|
||||
false))
|
||||
|
||||
(.addEventListener js/document
|
||||
"keyup"
|
||||
(fn [event]
|
||||
(swap! keysdown
|
||||
#(assoc % (.-code event) false))
|
||||
false))
|
||||
|
||||
(defn dirinput []
|
||||
(cond
|
||||
(keydown? :ArrowLeft) :w
|
||||
(keydown? :ArrowRight) :e
|
||||
(keydown? :ArrowUp) :n
|
||||
(keydown? :ArrowDown) :s
|
||||
:else :?))
|
@ -0,0 +1,18 @@
|
||||
(ns topdown2d.objects)
|
||||
|
||||
(defn move [obj]
|
||||
(let [{:keys [x y v d]} obj]
|
||||
(cond
|
||||
(= d :w)
|
||||
(assoc obj
|
||||
:x (- x v))
|
||||
(= d :e)
|
||||
(assoc obj
|
||||
:x (+ x v))
|
||||
(= d :n)
|
||||
(assoc obj
|
||||
:y (- y v))
|
||||
(= d :s)
|
||||
(assoc obj
|
||||
:y (+ y v))
|
||||
:else obj)))
|
Loading…
Reference in new issue