From 6b1eda86c8e037a5e8ebe969cd2b266cf784c51a Mon Sep 17 00:00:00 2001 From: oakes Date: Fri, 17 Jan 2014 17:13:06 -0500 Subject: [PATCH] Start work on body functions --- src/play_clj/g2d_physics.clj | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/play_clj/g2d_physics.clj b/src/play_clj/g2d_physics.clj index 627b70d..84103c2 100644 --- a/src/play_clj/g2d_physics.clj +++ b/src/play_clj/g2d_physics.clj @@ -1,7 +1,9 @@ (ns play-clj.g2d-physics (:require [play-clj.math :as m] [play-clj.utils :as u]) - (:import [com.badlogic.gdx.physics.box2d ContactListener World])) + (:import [com.badlogic.gdx.physics.box2d Body BodyDef ContactListener World])) + +; world (defn box-2d* ([] @@ -21,6 +23,37 @@ [screen k & options] `(u/call! ^World (:world ~screen) ~k ~@options)) +; body + +(defmacro body-type + [k] + `~(symbol (str u/main-package ".physics.box2d.BodyDef$BodyType/" + (u/key->pascal k) "Body"))) + +(defn body-def* + [type-symbol] + (let [bdef (BodyDef.)] + (set! (. bdef type) type-symbol) + bdef)) + +(defmacro body-def + [type-name] + `(body-def* (body-type ~type-name))) + +(defn body* + [screen entity bdef] + (assoc entity :body (box-2d! screen :create-body bdef))) + +(defmacro body + [screen entity type-name & options] + `(let [entity# (body* ~screen ~entity (body-def ~type-name))] + (u/calls! ^Body (:body entity#) ~@options) + entity#)) + +(defmacro body! + [entity k & options] + `(u/call! ^Body (:body ~entity) ~k ~@options)) + (defn contact-listener [{:keys [on-begin-contact on-end-contact on-post-solve on-pre-solve]} execute-fn!] (reify ContactListener