Allow adding/removing entities

This commit is contained in:
oakes
2013-12-29 15:30:15 -05:00
parent 9088f9906b
commit 8f97c3fa57
2 changed files with 29 additions and 9 deletions

View File

@@ -37,7 +37,16 @@
(swap! screen assoc
:renderer (create-renderer renderer)
:camera (create-camera camera)
:total-time 0)
:total-time 0
:entities []
:add-entity (fn [entity]
(->> entity
(conj (:entities @screen))
(swap! screen assoc :entities)))
:del-entity (fn [entity]
(->> (:entities @screen)
(remove #(= % entity))
(swap! screen assoc :entities))))
(on-show @screen))
(render [delta-time]
(swap! screen assoc :total-time (+ (:total-time @screen) delta-time))
@@ -52,6 +61,14 @@
[name & {:keys [] :as options}]
`(def ~name (defscreen* ~options)))
(defn add-entity!
[{:keys [add-entity]} e]
(add-entity e))
(defn remove-entity!
[{:keys [del-entity]} e]
(del-entity e))
(defn set-screen!
[^Game game ^Screen screen]
(.setScreen game screen))