Added Gravity component and new ImpactBody helper class

This commit is contained in:
Richard Davey 2017-08-16 00:30:12 +01:00
parent fe2f82c229
commit e64981c51d
9 changed files with 100 additions and 4 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '3cc5e4b0-820c-11e7-8573-1960fd3f13b3'
build: 'c897f920-8210-11e7-91c0-5f772e8c4462'
};
module.exports = CHECKSUM;

View file

@ -1,6 +1,7 @@
// Phaser.Physics.Impact.Body
var Class = require('../../utils/Class');
var Components = require('./Components');
var COLLIDES = require('./COLLIDES');
var GetVelocity = require('./GetVelocity');
var TYPE = require('./TYPE');
@ -114,6 +115,32 @@ var Body = new Class({
return this;
},
toJSON: function ()
{
var output = {
name: this.name,
size: { x: this.size.x, y: this.size.y },
pos: { x: this.pos.x, y: this.pos.y },
vel: { x: this.vel.x, y: this.vel.y },
accel: { x: this.accel.x, y: this.accel.y },
friction: { x: this.friction.x, y: this.friction.y },
maxVel: { x: this.maxVel.x, y: this.maxVel.y },
gravityFactor: this.gravityFactor,
bounciness: this.bounciness,
minBounceVelocity: this.minBounceVelocity,
type: this.type,
checkAgainst: this.checkAgainst,
collides: this.collides
};
return output;
},
fromJSON: function (config)
{
// TODO
},
check: function (other)
{
// Overridden by user code

View file

@ -1,4 +1,5 @@
var Class = require('../../utils/Class');
var ImpactBody = require('./ImpactBody');
var ImpactImage = require('./ImpactImage');
var ImpactSprite = require('./ImpactSprite');
@ -13,9 +14,9 @@ var Factory = new Class({
this.sys = world.scene.sys;
},
body: function (x, y, sizeX, sizeY)
body: function (x, y, width, height)
{
return this.world.create(x, y, sizeX, sizeY);
return new ImpactBody(this.world, x, y, width, height);
},
image: function (x, y, key, frame)

View file

@ -0,0 +1,32 @@
var Class = require('../../utils/Class');
var Components = require('./Components');
var ImpactBody = new Class({
Mixins: [
Components.Acceleration,
Components.BodyType,
Components.Bounce,
Components.CheckAgainst,
Components.Collides,
Components.Gravity,
Components.Velocity
],
initialize:
function ImpactBody (world, x, y, width, height)
{
this.body = world.create(x, y, width, height);
// Local references to the Body properties
this.vel = this.body.vel;
this.accel = this.body.accel;
this.friction = this.body.friction;
this.maxVel = this.body.maxVel;
}
});
module.exports = ImpactBody;

View file

@ -13,6 +13,7 @@ var ImpactImage = new Class({
Components.Bounce,
Components.CheckAgainst,
Components.Collides,
Components.Gravity,
Components.Velocity
],

View file

@ -13,6 +13,7 @@ var ImpactSprite = new Class({
Components.Bounce,
Components.CheckAgainst,
Components.Collides,
Components.Gravity,
Components.Velocity
],

View file

@ -7,7 +7,14 @@ var Bounce = {
return this;
},
bounciness: {
setMinBounceVelocity: function (value)
{
this.body.minBounceVelocity = value;
return this;
},
bounce: {
get: function ()
{

View file

@ -0,0 +1,26 @@
var Gravity = {
setGravity: function (value)
{
this.body.gravityFactor = value;
return this;
},
gravity: {
get: function ()
{
return this.body.gravityFactor;
},
set: function (value)
{
this.body.gravityFactor = value;
}
}
};
module.exports = Gravity;

View file

@ -7,6 +7,7 @@ module.exports = {
Bounce: require('./Bounce'),
CheckAgainst: require('./CheckAgainst'),
Collides: require('./Collides'),
Gravity: require('./Gravity'),
Velocity: require('./Velocity')
};