diff --git a/src/play_clj/core_graphics.clj b/src/play_clj/core_graphics.clj index 5b5827c..7f33345 100644 --- a/src/play_clj/core_graphics.clj +++ b/src/play_clj/core_graphics.clj @@ -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 diff --git a/src/play_clj/g2d_physics.clj b/src/play_clj/g2d_physics.clj index 204ac09..0524762 100644 --- a/src/play_clj/g2d_physics.clj +++ b/src/play_clj/g2d_physics.clj @@ -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