forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New split physics system is implemented. Still tidying-up, but Arcade…
…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
1 parent
2bab4fd
commit 3e93f24
Showing
63 changed files
with
3,160 additions
and
1,663 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.