clean client code
This commit is contained in:
parent
f3619ba891
commit
21a30ad212
18 changed files with 294 additions and 268 deletions
|
@ -1,27 +1,22 @@
|
|||
function Physics() {
|
||||
var b2Vec2 = Box2D.Common.Math.b2Vec2;
|
||||
var b2World = Box2D.Dynamics.b2World;
|
||||
var b2Body = Box2D.Dynamics.b2Body;
|
||||
var b2BodyDef = Box2D.Dynamics.b2BodyDef;
|
||||
var b2Fixture = Box2D.Dynamics.b2Fixture;
|
||||
var b2FixtureDef = Box2D.Dynamics.b2FixtureDef;
|
||||
var b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
|
||||
class Physics {
|
||||
constructor() {
|
||||
|
||||
this.world = new b2World(new b2Vec2(0, 0));
|
||||
this.toRemove = [];
|
||||
this.world = new b2World(new b2Vec2(0, 0));
|
||||
this.toRemove = [];
|
||||
|
||||
var b2DebugDraw = Box2D.Dynamics.b2DebugDraw;
|
||||
var debugDraw = new b2DebugDraw();
|
||||
debugDraw.SetSprite(document.getElementById("starbugs_canvas").getContext("2d"));
|
||||
debugDraw.SetDrawScale(SCALE);
|
||||
debugDraw.SetFillAlpha(0.3);
|
||||
debugDraw.SetLineThickness(1.0);
|
||||
debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);
|
||||
this.world.SetDebugDraw(debugDraw);
|
||||
var b2DebugDraw = Box2D.Dynamics.b2DebugDraw;
|
||||
var debugDraw = new b2DebugDraw();
|
||||
debugDraw.SetSprite(document.getElementById("starbugs_canvas").getContext("2d"));
|
||||
debugDraw.SetDrawScale(SCALE);
|
||||
debugDraw.SetFillAlpha(0.3);
|
||||
debugDraw.SetLineThickness(1.0);
|
||||
debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);
|
||||
this.world.SetDebugDraw(debugDraw);
|
||||
}
|
||||
|
||||
this.createBody = function(body) {
|
||||
var s = SCALE;
|
||||
var bodyDef = new b2BodyDef();
|
||||
createBody(body) {
|
||||
let s = SCALE;
|
||||
let bodyDef = new b2BodyDef();
|
||||
bodyDef.userData = body;
|
||||
bodyDef.position = new b2Vec2(body.x || 0, body.y || 0);
|
||||
bodyDef.fixedRotation = false;
|
||||
|
@ -54,7 +49,7 @@ function Physics() {
|
|||
|
||||
body.com = b2body.GetLocalCenter();
|
||||
if (body.bodyType == 'ship') {
|
||||
console.log(body.getPos());
|
||||
//console.log(body.getPos());
|
||||
//console.log(b2body.GetLocalCenter());
|
||||
//console.log(body);
|
||||
//console.log(b2body.GetMass());
|
||||
|
@ -62,11 +57,11 @@ function Physics() {
|
|||
}
|
||||
}
|
||||
|
||||
this.removeBody = function(body) {
|
||||
removeBody(body) {
|
||||
this.toRemove.push(body.b2body);
|
||||
}
|
||||
|
||||
this.step = function() {
|
||||
step() {
|
||||
this.world.Step(1, 5, 1 / 60);
|
||||
this.world.ClearForces();
|
||||
//this.world.DrawDebugData();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue