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 P2 examples. And fixed Camera.atLimit value.
- Loading branch information
1 parent
fc788f9
commit 84741f0
Showing
8 changed files
with
249 additions
and
11 deletions.
There are no files selected for viewing
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,82 @@ | ||
|
||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); | ||
|
||
function preload() { | ||
|
||
game.load.image('stars', 'assets/misc/starfield.jpg'); | ||
game.load.image('ship', 'assets/sprites/thrust_ship2.png'); | ||
game.load.image('ball', 'assets/sprites/shinyball.png'); | ||
game.load.spritesheet('diamonds', 'assets/sprites/diamonds32x24x5.png', 32, 24); | ||
|
||
} | ||
|
||
var ship; | ||
var starfield; | ||
var diamonds; | ||
var cursors; | ||
|
||
function create() { | ||
|
||
game.world.setBounds(0, 0, 1920, 1200); | ||
|
||
game.physics.startSystem(Phaser.Physics.P2JS); | ||
game.physics.p2.defaultRestitution = 0.8; | ||
|
||
// starfield = game.add.tileSprite(0, 0, 800, 600, 'stars'); | ||
// starfield.fixedToCamera = true; | ||
|
||
diamonds = game.add.group(); | ||
// diamonds.enableBody = true; | ||
// diamonds.physicsBodyType = Phaser.Physics.P2JS; | ||
|
||
for (var i = 0; i < 50; i++) | ||
{ | ||
// var d = diamonds.create(game.world.randomX, game.world.randomY, 'diamonds', game.rnd.integerInRange(0, 5)); | ||
// game.physics.p2.enable(d, true); | ||
|
||
var d = diamonds.create(game.world.randomX, game.world.randomY, 'ball'); | ||
game.physics.p2.enable(d); | ||
d.body.setCircle(16); | ||
} | ||
|
||
ship = game.add.sprite(200, 200, 'ship'); | ||
|
||
game.physics.p2.enable(ship, true); | ||
|
||
game.camera.follow(ship); | ||
|
||
cursors = game.input.keyboard.createCursorKeys(); | ||
|
||
} | ||
|
||
function update() { | ||
|
||
if (cursors.left.isDown) | ||
{ | ||
ship.body.rotateLeft(100); | ||
} | ||
else if (cursors.right.isDown) | ||
{ | ||
ship.body.rotateRight(100); | ||
} | ||
else | ||
{ | ||
ship.body.setZeroRotation(); | ||
} | ||
|
||
if (cursors.up.isDown) | ||
{ | ||
ship.body.thrust(400); | ||
} | ||
else if (cursors.down.isDown) | ||
{ | ||
ship.body.reverse(400); | ||
} | ||
|
||
// starfield.tilePosition.add(ship.body.velocity.x / 4, ship.body.velocity.y / 4); | ||
|
||
} | ||
|
||
function render() { | ||
|
||
} |
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,65 @@ | ||
|
||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); | ||
|
||
function preload() { | ||
|
||
game.load.image('stars', 'assets/misc/starfield.jpg'); | ||
game.load.image('ship', 'assets/sprites/thrust_ship2.png'); | ||
|
||
} | ||
|
||
var ship; | ||
var starfield; | ||
var cursors; | ||
|
||
function create() { | ||
|
||
game.world.setBounds(0, 0, 1920, 1200); | ||
|
||
game.physics.startSystem(Phaser.Physics.P2JS); | ||
game.physics.p2.defaultRestitution = 0.8; | ||
|
||
starfield = game.add.tileSprite(0, 0, 800, 600, 'stars'); | ||
starfield.fixedToCamera = true; | ||
|
||
ship = game.add.sprite(200, 200, 'ship'); | ||
|
||
game.physics.p2.enable(ship); | ||
|
||
game.camera.follow(ship); | ||
|
||
cursors = game.input.keyboard.createCursorKeys(); | ||
|
||
} | ||
|
||
function update() { | ||
|
||
if (cursors.left.isDown) | ||
{ | ||
ship.body.rotateLeft(100); | ||
} | ||
else if (cursors.right.isDown) | ||
{ | ||
ship.body.rotateRight(100); | ||
} | ||
else | ||
{ | ||
ship.body.setZeroRotation(); | ||
} | ||
|
||
if (cursors.up.isDown) | ||
{ | ||
ship.body.thrust(400); | ||
} | ||
else if (cursors.down.isDown) | ||
{ | ||
ship.body.reverse(400); | ||
} | ||
|
||
starfield.tilePosition.add(ship.body.velocity.x, ship.body.velocity.y); | ||
|
||
} | ||
|
||
function render() { | ||
|
||
} |
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,88 @@ | ||
|
||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); | ||
|
||
function preload() { | ||
|
||
game.load.image('stars', 'assets/misc/starfield.jpg'); | ||
game.load.spritesheet('ship', 'assets/sprites/humstar.png', 32, 32); | ||
game.load.image('ball', 'assets/sprites/shinyball.png'); | ||
|
||
} | ||
|
||
var ship; | ||
var starfield; | ||
var cursors; | ||
|
||
function create() { | ||
|
||
game.world.setBounds(0, 0, 1600, 1200); | ||
|
||
game.physics.startSystem(Phaser.Physics.P2JS); | ||
game.physics.p2.defaultRestitution = 0.9; | ||
|
||
starfield = game.add.tileSprite(0, 0, 800, 600, 'stars'); | ||
starfield.fixedToCamera = true; | ||
|
||
balls = game.add.group(); | ||
balls.enableBody = true; | ||
balls.physicsBodyType = Phaser.Physics.P2JS; | ||
|
||
for (var i = 0; i < 50; i++) | ||
{ | ||
var ball = balls.create(game.world.randomX, game.world.randomY, 'ball'); | ||
ball.body.setCircle(16); | ||
} | ||
|
||
ship = game.add.sprite(200, 200, 'ship'); | ||
ship.scale.set(2); | ||
ship.smoothed = false; | ||
ship.animations.add('fly', [0,1,2,3,4,5], 10, true); | ||
ship.play('fly'); | ||
|
||
// Create our physics body - a 28px radius circle. Set the 'false' parameter below to 'true' to enable debugging | ||
game.physics.p2.enable(ship, false); | ||
ship.body.setCircle(28); | ||
|
||
game.camera.follow(ship); | ||
|
||
cursors = game.input.keyboard.createCursorKeys(); | ||
|
||
} | ||
|
||
function update() { | ||
|
||
ship.body.setZeroVelocity(); | ||
|
||
if (cursors.left.isDown) | ||
{ | ||
ship.body.moveLeft(200); | ||
} | ||
else if (cursors.right.isDown) | ||
{ | ||
ship.body.moveRight(200); | ||
} | ||
|
||
if (cursors.up.isDown) | ||
{ | ||
ship.body.moveUp(200); | ||
} | ||
else if (cursors.down.isDown) | ||
{ | ||
ship.body.moveDown(200); | ||
} | ||
|
||
if (!game.camera.atLimit.x) | ||
{ | ||
starfield.tilePosition.x += (ship.body.velocity.x * 16) * game.time.physicsElapsed; | ||
} | ||
|
||
if (!game.camera.atLimit.y) | ||
{ | ||
starfield.tilePosition.y += (ship.body.velocity.y * 16) * game.time.physicsElapsed; | ||
} | ||
|
||
} | ||
|
||
function render() { | ||
|
||
} |
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
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