mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 13:43:26 +00:00
Starting merge of Matter JS.
This commit is contained in:
parent
d20b7abba6
commit
fb83d6dab5
7 changed files with 277 additions and 10 deletions
|
@ -3,13 +3,6 @@
|
|||
module.exports = {
|
||||
Arcade: require('./arcade'),
|
||||
Impact: require('./impact'),
|
||||
PolyDecomp: require('./poly-decomp/')
|
||||
// MatterJS: require('./matter-js'),
|
||||
PolyDecomp: require('./poly-decomp')
|
||||
};
|
||||
|
||||
/*
|
||||
module.exports = {
|
||||
Impact: require('./impact'),
|
||||
PolyDecomp: require('./poly-decomp/'),
|
||||
MatterJS: require('./matter-js/module/main')
|
||||
};
|
||||
*/
|
||||
|
|
24
v3/src/physics/matter-js/Body.js
Normal file
24
v3/src/physics/matter-js/Body.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Phaser.Physics.Matter.Body
|
||||
|
||||
var Class = require('../../utils/Class');
|
||||
// var CONST = require('./const');
|
||||
// var PhysicsEvent = require('./events');
|
||||
var Rectangle = require('../../geom/rectangle/Rectangle');
|
||||
// var RectangleContains = require('../../geom/rectangle/Contains');
|
||||
var Vector2 = require('../../math/Vector2');
|
||||
|
||||
var Body = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function Body (world, gameObject)
|
||||
{
|
||||
this.world = world;
|
||||
|
||||
this.gameObject = gameObject;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = Body;
|
103
v3/src/physics/matter-js/Factory.js
Normal file
103
v3/src/physics/matter-js/Factory.js
Normal file
|
@ -0,0 +1,103 @@
|
|||
// var MatterImage = require('./MatterImage');
|
||||
// var MatterSprite = require('./MatterSprite');
|
||||
var Class = require('../../utils/Class');
|
||||
// var CONST = require('./const');
|
||||
// var PhysicsGroup = require('./PhysicsGroup');
|
||||
// var StaticPhysicsGroup = require('./StaticPhysicsGroup');
|
||||
|
||||
// When registering a factory function 'this' refers to the GameObjectFactory context.
|
||||
//
|
||||
// There are several properties available to use:
|
||||
//
|
||||
// this.scene - a reference to the Scene that owns the GameObjectFactory
|
||||
// this.displayList - a reference to the Display List the Scene owns
|
||||
// this.updateList - a reference to the Update List the Scene owns
|
||||
|
||||
var Factory = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function Factory (world)
|
||||
{
|
||||
this.world = world;
|
||||
|
||||
this.scene = world.scene;
|
||||
|
||||
this.sys = world.scene.sys;
|
||||
|
||||
// this.displayList = this.sys.
|
||||
// this.displayList = sys.displayList;
|
||||
// this.updateList = sys.updateList;
|
||||
},
|
||||
|
||||
/*
|
||||
collider: function (object1, object2, collideCallback, processCallback, callbackContext)
|
||||
{
|
||||
return this.world.addCollider(object1, object2, collideCallback, processCallback, callbackContext);
|
||||
},
|
||||
|
||||
overlap: function (object1, object2, collideCallback, processCallback, callbackContext)
|
||||
{
|
||||
return this.world.addOverlap(object1, object2, collideCallback, processCallback, callbackContext);
|
||||
},
|
||||
|
||||
staticImage: function (x, y, key, frame)
|
||||
{
|
||||
var image = new ArcadeImage(this.scene, x, y, key, frame);
|
||||
|
||||
this.sys.displayList.add(image);
|
||||
|
||||
this.world.enableBody(image, CONST.STATIC_BODY);
|
||||
|
||||
return image;
|
||||
},
|
||||
|
||||
image: function (x, y, key, frame)
|
||||
{
|
||||
var image = new ArcadeImage(this.scene, x, y, key, frame);
|
||||
|
||||
this.sys.displayList.add(image);
|
||||
|
||||
this.world.enableBody(image, CONST.DYNAMIC_BODY);
|
||||
|
||||
return image;
|
||||
},
|
||||
|
||||
staticSprite: function (x, y, key, frame)
|
||||
{
|
||||
var sprite = new ArcadeSprite(this.scene, x, y, key, frame);
|
||||
|
||||
this.sys.displayList.add(sprite);
|
||||
this.sys.updateList.add(sprite);
|
||||
|
||||
this.world.enableBody(sprite, CONST.STATIC_BODY);
|
||||
|
||||
return sprite;
|
||||
},
|
||||
|
||||
sprite: function (x, y, key, frame)
|
||||
{
|
||||
var sprite = new ArcadeSprite(this.scene, x, y, key, frame);
|
||||
|
||||
this.sys.displayList.add(sprite);
|
||||
this.sys.updateList.add(sprite);
|
||||
|
||||
this.world.enableBody(sprite, CONST.DYNAMIC_BODY);
|
||||
|
||||
return sprite;
|
||||
},
|
||||
|
||||
staticGroup: function (children, config)
|
||||
{
|
||||
return this.sys.updateList.add(new StaticPhysicsGroup(this.world, this.world.scene, children, config));
|
||||
},
|
||||
|
||||
group: function (children, config)
|
||||
{
|
||||
return this.sys.updateList.add(new PhysicsGroup(this.world, this.world.scene, children, config));
|
||||
}
|
||||
*/
|
||||
|
||||
});
|
||||
|
||||
module.exports = Factory;
|
20
v3/src/physics/matter-js/Matter.js
Normal file
20
v3/src/physics/matter-js/Matter.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var Factory = require('./Factory');
|
||||
var World = require('./World');
|
||||
|
||||
var Matter = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function Matter (physicsManager, config)
|
||||
{
|
||||
this.config = config;
|
||||
|
||||
physicsManager.world = new World(physicsManager.scene, config);
|
||||
|
||||
physicsManager.add = new Factory(physicsManager.world);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = Matter;
|
59
v3/src/physics/matter-js/World.js
Normal file
59
v3/src/physics/matter-js/World.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Phaser.Physics.Arcade.World
|
||||
|
||||
var Body = require('./Body');
|
||||
var Class = require('../../utils/Class');
|
||||
// var CONST = require('./const');
|
||||
var GetValue = require('../../utils/object/GetValue');
|
||||
// var Rectangle = require('../../geom/rectangle/Rectangle');
|
||||
// var RTree = require('../../structs/RTree');
|
||||
var Set = require('../../structs/Set');
|
||||
// var ProcessQueue = require('../../structs/ProcessQueue');
|
||||
// var StaticBody = require('./StaticBody');
|
||||
var Vector2 = require('../../math/Vector2');
|
||||
|
||||
var World = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function World (scene, config)
|
||||
{
|
||||
var defaults = {
|
||||
fps: 60,
|
||||
correction: 1,
|
||||
deltaSampleSize: 60,
|
||||
counterTimestamp: 0,
|
||||
frameCounter: 0,
|
||||
deltaHistory: [],
|
||||
timePrev: null,
|
||||
timeScalePrev: 1,
|
||||
frameRequestId: null,
|
||||
isFixed: false,
|
||||
enabled: true
|
||||
};
|
||||
|
||||
this.scene = scene;
|
||||
|
||||
this.events = scene.sys.events;
|
||||
|
||||
// this.engine = Phaser.Physics.MatterJS.Engine;
|
||||
// this.world = Phaser.Physics.MatterJS.World;
|
||||
},
|
||||
|
||||
update: function (time, delta)
|
||||
{
|
||||
// this.engine.update(this.engine, delta, correction);
|
||||
},
|
||||
|
||||
shutdown: function ()
|
||||
{
|
||||
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = World;
|
|
@ -18,7 +18,7 @@ var Common = require('../core/Common');
|
|||
var Body = require('../body/Body');
|
||||
var Bounds = require('../geometry/Bounds');
|
||||
var Vector = require('../geometry/Vector');
|
||||
var decomp = require('poly-decomp');
|
||||
var decomp = require('../../poly-decomp');
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
68
v3/src/physics/matter-js/index.js
Normal file
68
v3/src/physics/matter-js/index.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
// Phaser.Physics.Matter
|
||||
|
||||
// World updated to run off the Phaser main loop.
|
||||
// Body extended to support additional setter functions.
|
||||
|
||||
module.exports = {
|
||||
|
||||
Body: require('./Body'),
|
||||
Factory: require('./Factory'),
|
||||
// Group: require('./PhysicsGroup'),
|
||||
// Image: require('./MatterImage'),
|
||||
// Sprite: require('./MatterSprite'),
|
||||
World: require('./World')
|
||||
|
||||
};
|
||||
|
||||
// Export globally for testing
|
||||
var Matter = module.exports = require('./core/Matter');
|
||||
|
||||
Matter.Body = require('./body/Body');
|
||||
Matter.Composite = require('./body/Composite');
|
||||
Matter.World = require('./body/World');
|
||||
|
||||
Matter.Contact = require('./collision/Contact');
|
||||
Matter.Detector = require('./collision/Detector');
|
||||
Matter.Grid = require('./collision/Grid');
|
||||
Matter.Pairs = require('./collision/Pairs');
|
||||
Matter.Pair = require('./collision/Pair');
|
||||
Matter.Query = require('./collision/Query');
|
||||
Matter.Resolver = require('./collision/Resolver');
|
||||
Matter.SAT = require('./collision/SAT');
|
||||
|
||||
Matter.Constraint = require('./constraint/Constraint');
|
||||
Matter.MouseConstraint = require('./constraint/MouseConstraint');
|
||||
|
||||
Matter.Common = require('./core/Common');
|
||||
Matter.Engine = require('./core/Engine');
|
||||
Matter.Events = require('./core/Events');
|
||||
Matter.Mouse = require('./core/Mouse');
|
||||
// Matter.Runner = require('./core/Runner');
|
||||
Matter.Sleeping = require('./core/Sleeping');
|
||||
Matter.Plugin = require('./core/Plugin');
|
||||
|
||||
// @if DEBUG
|
||||
// Matter.Metrics = require('./core/Metrics');
|
||||
// @endif
|
||||
|
||||
Matter.Bodies = require('./factory/Bodies');
|
||||
Matter.Composites = require('./factory/Composites');
|
||||
|
||||
Matter.Axes = require('./geometry/Axes');
|
||||
Matter.Bounds = require('./geometry/Bounds');
|
||||
Matter.Svg = require('./geometry/Svg');
|
||||
Matter.Vector = require('./geometry/Vector');
|
||||
Matter.Vertices = require('./geometry/Vertices');
|
||||
|
||||
// Matter.Render = require('./render/Render');
|
||||
// Matter.RenderPixi = require('./render/RenderPixi');
|
||||
|
||||
// aliases
|
||||
|
||||
Matter.World.add = Matter.Composite.add;
|
||||
Matter.World.remove = Matter.Composite.remove;
|
||||
Matter.World.addComposite = Matter.Composite.addComposite;
|
||||
Matter.World.addBody = Matter.Composite.addBody;
|
||||
Matter.World.addConstraint = Matter.Composite.addConstraint;
|
||||
Matter.World.clear = Matter.Composite.clear;
|
||||
Matter.Engine.run = Matter.Runner.run;
|
Loading…
Reference in a new issue