Skip to content

Commit

Permalink
New split physics system is implemented. Still tidying-up, but Arcade…
Browse files Browse the repository at this point in the history
…Physics, P2 and Ninja Physics are in and configured. Lots more examples required, and tilemap collision mostly broken in Arcade at the moment. Time to implement in Ninja.
  • Loading branch information
photonstorm committed Mar 6, 2014
1 parent 2bab4fd commit 3e93f24
Show file tree
Hide file tree
Showing 63 changed files with 3,160 additions and 1,663 deletions.
28 changes: 20 additions & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,26 @@ module.exports = function (grunt) {
'src/utils/Debug.js',
'src/utils/Color.js',

'src/physics/World.js',
'src/physics/PointProxy.js',
'src/physics/InversePointProxy.js',
'src/physics/Body.js',
'src/physics/Spring.js',
'src/physics/Material.js',
'src/physics/ContactMaterial.js',
'src/physics/CollisionGroup.js',
'/src/physics/Physics.js',

'/src/physics/arcade/World.js',
'/src/physics/arcade/Body.js',
'/src/physics/arcade/QuadTree.js',

'/src/physics/ninja/World.js',
'/src/physics/ninja/Body.js',
'/src/physics/ninja/AABB.js',
'/src/physics/ninja/Tile.js',
'/src/physics/ninja/Circle.js',

'/src/physics/p2/World.js',
'/src/physics/p2/PointProxy.js',
'/src/physics/p2/InversePointProxy.js',
'/src/physics/p2/Body.js',
'/src/physics/p2/Spring.js',
'/src/physics/p2/Material.js',
'/src/physics/p2/ContactMaterial.js',
'/src/physics/p2/CollisionGroup.js',

'src/particles/Particles.js',
'src/particles/arcade/ArcadeParticles.js',
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ By Richard Davey, [Photon Storm](http://www.photonstorm.com)
* Join the [Forum](http://www.html5gamedevs.com/forum/14-phaser/)
* Try out 220+ [Phaser Examples](http://examples.phaser.io)
* Read the [documentation online](http://docs.phaser.io)
* Join our [#phaserio IRC channel](http://www.html5gamedevs.com/topic/4470-official-phaserio-irc-channel-phaserio-on-freenode/) on freenode

[Subscribe to our new Phaser Newsletter](https://confirmsubscription.com/h/r/369DE48E3E86AF1E). We'll email you when new versions are released as well as send you our regular Phaser game making magazine.

Expand Down
6 changes: 6 additions & 0 deletions build/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
<script src="$path/src/physics/arcade/Body.js"></script>
<script src="$path/src/physics/arcade/QuadTree.js"></script>
<script src="$path/src/physics/ninja/World.js"></script>
<script src="$path/src/physics/ninja/Body.js"></script>
<script src="$path/src/physics/ninja/AABB.js"></script>
<script src="$path/src/physics/ninja/Tile.js"></script>
<script src="$path/src/physics/ninja/Circle.js"></script>
<script src="$path/src/physics/p2/World.js"></script>
<script src="$path/src/physics/p2/PointProxy.js"></script>
<script src="$path/src/physics/p2/InversePointProxy.js"></script>
Expand Down
Binary file added examples/assets/physics/ninja-tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions examples/wip/ninja1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

// var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });

function preload() {

game.load.spritesheet('ninja-tiles', 'assets/physics/ninja-tiles.png', 128, 128, 34);
game.load.image('a', 'assets/sprites/firstaid.png');

}

var sprite1;
var cursors;

var tile1;
var tile2;

var t;
var running = false;

function create() {

game.stage.smoothed = true;

// Activate the Ninja physics system
game.physics.startSystem(Phaser.Physics.NINJA);

// game.physics.ninja.gravity = 0.1;

sprite1 = game.add.sprite(500, 200, 'a');

// Enable the physics body for the Ninja physics system
// By default it will create an AABB body for the sprite
game.physics.ninja.enableAABB(sprite1);

// But you can change it to either a Tile or a Circle
tile1 = game.add.sprite(0, 550, 'ninja-tiles', 14);
tile1.width = 100;
tile1.height = 100;

game.physics.ninja.enableTile(tile1, 14);

// sprite1.body.aabb.friction = 0;

// tile1 = new Phaser.Physics.Ninja.Tile(game.physics.ninja, 100, 500, 100, 100, Phaser.Physics.Ninja.Tile.SLOPE_45DEGpn);
// tile1 = new Phaser.Physics.Ninja.Tile(game.physics.ninja, 100, 500, 100, 100, 15);
// tile2 = new Phaser.Physics.Ninja.Tile(game.physics.ninja, 300, 500, 100, 100, 7);

cursors = game.input.keyboard.createCursorKeys();

}

function collisionHandler() {
game.stage.backgroundColor = 0xff0000;
}

function update() {

game.physics.ninja.collide(sprite1, tile1, collisionHandler, null, this);

tile1.body.moveRight(1);

/*
if (cursors.up.isDown && !running)
{
running = true;
t = Date.now();
}
sprite1.body.setZeroVelocity();
if (running)
{
sprite1.body.moveRight(100);
if (sprite1.body.x >= 200)
{
var ms = Date.now() - t;
console.log('100px in ', ms);
running = false;
sprite1.body.setZeroVelocity();
}
}
*/

// sprite1.body.setZeroVelocity();

if (cursors.left.isDown)
{
sprite1.body.moveLeft(20);
}
else if (cursors.right.isDown)
{
sprite1.body.moveRight(20);
}

if (cursors.up.isDown)
{
sprite1.body.moveUp(20);
}
else if (cursors.down.isDown)
{
sprite1.body.moveUp(20);
}

}

function render() {

game.debug.text(sprite1.body.shape.velocity.x, 32, 32);
game.debug.text(sprite1.body.shape.velocity.y, 32, 64);
game.debug.text(game.math.radToDeg(sprite1.body.angle), 32, 96);

// tile1.render(game.context, 'ninja-tiles');
// tile2.render(game.context, 'ninja-tiles');

// game.debug.geom(sprite1.body, 'rgba(0,255,0,0.4)', true, 1);

// game.debug.geom(tile1, 'rgba(0,255,0,0.4)', true, 1);
// game.debug.geom(tile1, 'rgba(0,255,0,0.4)', true, 1);

}
13 changes: 11 additions & 2 deletions examples/wip/physics-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function create() {

sprite1 = game.add.sprite(50, 200, 'atari');
sprite1.name = 'atari';
// sprite1.anchor.set(0.5);

sprite2 = game.add.sprite(700, 220, 'mushroom');
sprite2.name = 'mushroom';
Expand All @@ -37,6 +38,9 @@ function update() {
// object1, object2, collideCallback, processCallback, callbackContext
game.physics.arcade.collide(sprite1, sprite2, collisionHandler, null, this);

// var b = sprite1.getBounds();
// console.log(b);

}

function collisionHandler (obj1, obj2) {
Expand All @@ -46,9 +50,14 @@ function collisionHandler (obj1, obj2) {

}


function render() {

// game.debug.physicsBody(sprite1.body);
// game.debug.physicsBody(sprite2.body);
// var b = sprite1.getBounds();

// game.debug.geom(b, 'rgba(255,0,0,0.8)', true, 1);

game.debug.geom(sprite1.body, 'rgba(0,255,0,0.4)', true, 1);
game.debug.geom(sprite2.body, 'rgba(0,255,0,0.4)', true, 1);

}
4 changes: 3 additions & 1 deletion examples/wip/sci-fly2.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function create() {

game.physics.enable(sprite);

sprite.body.setSize(14, 14, 2, 0);
// sprite.body.setSize(14, 14, 2, 0);

console.log(sprite.body);

Expand Down Expand Up @@ -107,6 +107,8 @@ function render() {
// game.debug.text(game.physics.arcade._intersection.width, 32, 32);
// game.debug.text(game.physics.arcade._intersection.height, 32, 64);

game.debug.geom(sprite.body, 'rgba(0,255,0,0.4)', true, 1);

game.debug.text(sprite.body.overlapX, 32, 32);
game.debug.text(sprite.body.overlapY, 32, 64);

Expand Down
77 changes: 77 additions & 0 deletions examples/wip/tilemap new 1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });

function preload() {

game.load.tilemap('map', 'assets/tilemaps/maps/collision_test.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png');
game.load.image('phaser', 'assets/sprites/phaser-dude.png');
// game.load.image('phaser', 'assets/sprites/phaser-ship.png');

}

var map;
var layer;
var cursors;
var sprite;

function create() {

map = game.add.tilemap('map');

map.addTilesetImage('ground_1x1');

layer = map.createLayer('Tile Layer 1');

layer.resizeWorld();

map.setCollisionBetween(1, 12);

layer.debug = true;

sprite = game.add.sprite(260, 70, 'phaser');

game.physics.enable(sprite);

game.camera.follow(sprite);

// game.physics.arcade.gravity.y = 500;
// sprite.body.velocity.x = 100;

cursors = game.input.keyboard.createCursorKeys();

}

function update() {

game.physics.arcade.collide(sprite, layer);

sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;

if (cursors.up.isDown)
{
sprite.body.velocity.y = -100;
}
else if (cursors.down.isDown)
{
sprite.body.velocity.y = 100;
}

if (cursors.left.isDown)
{
sprite.body.velocity.x = -100;
}
else if (cursors.right.isDown)
{
sprite.body.velocity.x = 100;
}

}

function render() {

game.debug.text(sprite.body.velocity.x, 32, 32);
game.debug.text(sprite.body.velocity.y, 64, 32);

}
3 changes: 3 additions & 0 deletions examples/wip/tilesprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function create() {
// sprite = game.add.tileSprite(100, 100, 400, 300, 'starfield');

sprite = game.add.tileSprite(100, 100, 400, 300, 'mummy');
sprite.pivot.setTo(200, 200);

sprite.animations.add('walk');

Expand All @@ -32,6 +33,8 @@ function create() {

function update() {

sprite.rotation += 0.01;

if (cursors.left.isDown)
{
sprite.tilePosition.x += 8;
Expand Down
Binary file added resources/Ninja Physics Debug Tiles/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/26.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/27.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/28.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/29.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/Ninja Physics Debug Tiles/3.png
Binary file added resources/Ninja Physics Debug Tiles/30.png
Binary file added resources/Ninja Physics Debug Tiles/31.png
Binary file added resources/Ninja Physics Debug Tiles/32.png
Binary file added resources/Ninja Physics Debug Tiles/33.png
Binary file added resources/Ninja Physics Debug Tiles/4.png
Binary file added resources/Ninja Physics Debug Tiles/5.png
Binary file added resources/Ninja Physics Debug Tiles/6.png
Binary file added resources/Ninja Physics Debug Tiles/7.png
Binary file added resources/Ninja Physics Debug Tiles/8.png
Binary file added resources/Ninja Physics Debug Tiles/9.png
Loading

0 comments on commit 3e93f24

Please sign in to comment.