mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
38 lines
No EOL
923 B
JavaScript
Executable file
38 lines
No EOL
923 B
JavaScript
Executable file
define([
|
|
"Lib/Vendor/Box2D",
|
|
"Lib/Utilities/Exception"
|
|
],
|
|
|
|
function (Box2D, Exception) {
|
|
|
|
function GameObject(physicsEngine, uid) {
|
|
this.uid = uid;
|
|
|
|
var def = this.getBodyDef();
|
|
def.userData = this;
|
|
this.body = physicsEngine.getWorld().CreateBody(def);
|
|
}
|
|
|
|
GameObject.prototype.getBodyDef = function() {
|
|
throw new Exception('Abstract method GameObject.getBodyDef not overwritten');
|
|
};
|
|
|
|
GameObject.prototype.destroy = function() {
|
|
if(this.body instanceof Box2D.Dynamics.b2Body) {
|
|
this.body.GetWorld().DestroyBody(this.body);
|
|
} else {
|
|
throw new Exception("can not destroy body");
|
|
}
|
|
};
|
|
|
|
GameObject.prototype.getBody = function() {
|
|
return this.body;
|
|
};
|
|
|
|
GameObject.prototype.getPosition = function() {
|
|
return this.body.GetPosition().Copy();
|
|
};
|
|
|
|
return GameObject;
|
|
|
|
}); |