Add more body functions and move entities in step! function

This commit is contained in:
oakes
2014-01-17 21:11:20 -05:00
parent c25477e11d
commit 7dbf3509c9
2 changed files with 36 additions and 2 deletions

View File

@@ -234,7 +234,13 @@
(.step ^World world time-step velocity-iterations position-iterations)))
([screen entities]
(step! screen)
entities))
(map (fn [entity]
(if-let [body (:body entity)]
(assoc entity
:x (g2dp/body-x body)
:y (g2dp/body-y body))
entity))
entities)))
; cameras

View File

@@ -2,7 +2,7 @@
(:require [play-clj.math :as m]
[play-clj.utils :as u])
(:import [com.badlogic.gdx.physics.box2d Body BodyDef ChainShape CircleShape
ContactListener EdgeShape FixtureDef PolygonShape World]))
ContactListener EdgeShape FixtureDef PolygonShape Transform World]))
; world
@@ -54,6 +54,34 @@
(u/calls! ^Body object# ~@options)
object#))
(defn body-x
[entity]
(. (body! entity :get-position) x))
(defn body-y
[entity]
(. (body! entity :get-position) y))
(defn body-angle
[entity]
(.getRotation ^Transform (body! entity :get-transform)))
(defn body-transform!
[entity x y angle]
(body! entity :set-transform x y angle))
(defn body-x!
[entity x]
(body-transform! entity x (body-y entity) (body-angle entity)))
(defn body-y!
[entity y]
(body-transform! entity (body-x entity) y (body-angle entity)))
(defn body-angle!
[entity angle]
(body-transform! entity (body-x entity) (body-y entity) angle))
; fixtures
(defn fixture