diff --git a/v3/src/physics/impact/Body.js b/v3/src/physics/impact/Body.js index 3915950a8..e74a36198 100644 --- a/v3/src/physics/impact/Body.js +++ b/v3/src/physics/impact/Body.js @@ -39,13 +39,13 @@ var Body = new Class({ this.vel = { x: 0, y: 0 }; this.accel = { x: 0, y: 0 }; this.friction = { x: 0, y: 0 }; - this.maxVel = { x: 100, y: 100 }; + this.maxVel = { x: world.defaults.maxVelocityX, y: world.defaults.maxVelocityY }; this.standing = false; - this.gravityFactor = 1; - this.bounciness = 0; - this.minBounceVelocity = 40; + this.gravityFactor = world.defaults.gravityFactor; + this.bounciness = world.defaults.bounciness; + this.minBounceVelocity = world.defaults.minBounceVelocity; this.accelGround = 0; this.accelAir = 0; @@ -57,7 +57,7 @@ var Body = new Class({ this.debugShowBody = true; this.debugShowVelocity = true; - this.debugBodyColor = world.debugColors.body; + this.debugBodyColor = world.defaults.bodyDebugColor; // min 44 deg, max 136 deg this.slopeStanding = { min: 0.767944870877505, max: 2.3736477827122884 }; @@ -131,7 +131,7 @@ var Body = new Class({ var x = pos.x + this.size.x / 2; var y = pos.y + this.size.y / 2; - graphic.lineStyle(1, this.world.debugColors.velocity, 1); + graphic.lineStyle(1, this.world.defaults.velocityDebugColor, 1); graphic.lineBetween(x, y, x + this.vel.x, y + this.vel.y); } } diff --git a/v3/src/physics/impact/World.js b/v3/src/physics/impact/World.js index cb26451d1..86b4c3660 100644 --- a/v3/src/physics/impact/World.js +++ b/v3/src/physics/impact/World.js @@ -4,6 +4,7 @@ var Body = require('./Body'); var Class = require('../../utils/Class'); var COLLIDES = require('./COLLIDES'); var CollisionMap = require('./CollisionMap'); +var GetFastValue = require('../../utils/object/GetFastValue'); var Set = require('../../structs/Set'); var Solver = require('./Solver'); var TYPE = require('./TYPE'); @@ -12,46 +13,47 @@ var World = new Class({ initialize: - function World (scene, gravity, cellSize, showDebug) + function World (scene, config) { - if (gravity === undefined) { gravity = 0; } - if (cellSize === undefined) { cellSize = 64; } - if (showDebug === undefined) { showDebug = false; } - this.scene = scene; this.events = scene.sys.events; this.bodies = new Set(); - this.gravity = gravity; + this.gravity = GetFastValue(config, 'gravity', 0); // Spatial hash cell dimensions - this.cellSize = cellSize; + this.cellSize = GetFastValue(config, 'cellSize', 64); this.collisionMap = new CollisionMap(); - this.delta = 0; - - this.timeScale = 1; + this.timeScale = GetFastValue(config, 'timeScale', 1); // Impacts maximum time step is 20 fps. - this.maxStep = 0.05; + this.maxStep = GetFastValue(config, 'maxStep', 0.05); this.enabled = true; - this.drawDebug = false; + this.drawDebug = GetFastValue(config, 'debug', false); this.debugGraphic; - this.debugColors = { - body: 0xff00ff, - velocity: 0x00ff00 + this.defaults = { + bodyDebugColor: GetFastValue(config, 'debugBodyColor', 0xff00ff), + velocityDebugColor: GetFastValue(config, 'debugVelocityColor', 0x00ff00), + maxVelocityX: GetFastValue(config, 'maxVelocityX', 100), + maxVelocityY: GetFastValue(config, 'maxVelocityY', 100), + minBounceVelocity: GetFastValue(config, 'minBounceVelocity', 40), + gravityFactor: GetFastValue(config, 'gravityFactor', 1), + bounciness: GetFastValue(config, 'bounciness', 0) }; + this.delta = 0; + this._lastId = 0; - if (showDebug) + if (this.drawDebug) { this.createDebugGraphic(); } diff --git a/v3/src/plugins/PhysicsManager.js b/v3/src/plugins/PhysicsManager.js index cb18f390b..dd5c075f5 100644 --- a/v3/src/plugins/PhysicsManager.js +++ b/v3/src/plugins/PhysicsManager.js @@ -29,7 +29,7 @@ var PhysicsManager = new Class({ if (config.system === 'impact') { - this.world = new Physics.Impact.World(this.scene, config.gravity, config.cellSize, config.debug); + this.world = new Physics.Impact.World(this.scene, config); this.add = new Physics.Impact.Factory(this.world); } },