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.
Group.callAll now supports nested functions and a context, making it …
…really powerful!
- Loading branch information
1 parent
19ac33f
commit 685054e
Showing
6 changed files
with
174 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,72 @@ | ||
|
||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); | ||
|
||
var phaser; | ||
|
||
function preload() { | ||
|
||
game.load.image('phaser', 'assets/sprites/phaser-dude.png'); | ||
game.load.image('bullet', 'assets/misc/bullet0.png'); | ||
|
||
} | ||
|
||
var sprite; | ||
var bullet; | ||
var bullets; | ||
var bulletTime = 0; | ||
|
||
function create() { | ||
|
||
game.stage.backgroundColor = '#736357'; | ||
game.stage.backgroundColor = '#2d2d2d'; | ||
|
||
bullets = game.add.group(); | ||
bullets.createMultiple(10, 'bullet'); | ||
bullets.callAll('events.onOutOfBounds.add', 'events.onOutOfBounds', resetBullet, this); | ||
|
||
phaser = game.add.sprite(300, 300, 'phaser'); | ||
sprite = game.add.sprite(400, 550, 'phaser'); | ||
|
||
// Stop the following keys from propagating up to the browser | ||
game.input.keyboard.addKeyCapture([ Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.SPACEBAR ]); | ||
|
||
} | ||
|
||
function update() { | ||
|
||
if (game.input.keyboard.justPressed(Phaser.Keyboard.UP)) | ||
sprite.body.velocity.x = 0; | ||
sprite.body.velocity.y = 0; | ||
|
||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) | ||
{ | ||
phaser.y--; | ||
sprite.body.velocity.x = -200; | ||
} | ||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) | ||
{ | ||
sprite.body.velocity.x = 200; | ||
} | ||
|
||
if (game.input.keyboard.justPressed(Phaser.Keyboard.DOWN)) | ||
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) | ||
{ | ||
phaser.y++; | ||
fireBullet(); | ||
} | ||
|
||
} | ||
|
||
function fireBullet () { | ||
|
||
if (game.time.now > bulletTime) | ||
{ | ||
bullet = bullets.getFirstExists(false); | ||
|
||
if (bullet) | ||
{ | ||
bullet.reset(sprite.x + 6, sprite.y - 8); | ||
bullet.body.velocity.y = -300; | ||
bulletTime = game.time.now + 250; | ||
} | ||
} | ||
|
||
} | ||
|
||
// Called if the bullet goes out of the screen | ||
function resetBullet (bullet) { | ||
bullet.kill(); | ||
} | ||
|
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