mirror of
https://github.com/photonstorm/phaser
synced 2024-11-21 20:23:19 +00:00
Added blaster example to the Test Suite and fixed a rotation bug in the particle emitter.
This commit is contained in:
parent
6466361f5f
commit
268470ef62
10 changed files with 235 additions and 146 deletions
|
@ -372,7 +372,7 @@ module Phaser {
|
|||
|
||||
particle.acceleration.y = this.gravity;
|
||||
|
||||
if (this.minRotation != this.maxRotation)
|
||||
if (this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0)
|
||||
{
|
||||
particle.angularVelocity = this.minRotation + this._game.math.random() * (this.maxRotation - this.minRotation);
|
||||
}
|
||||
|
|
|
@ -289,7 +289,7 @@ module Phaser {
|
|||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
}
|
||||
|
||||
if (this.flipped === true || this.rotation !== 0)
|
||||
if (this.flipped === true || this.rotation !== 0 || this.rotationOffset !== 0)
|
||||
{
|
||||
//this._game.stage.context.translate(0, 0);
|
||||
this._game.stage.context.restore();
|
||||
|
|
|
@ -107,6 +107,10 @@
|
|||
<DependentUpon>ballscroller.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="scrollzones\parallax.ts" />
|
||||
<TypeScriptCompile Include="scrollzones\blasteroids.ts" />
|
||||
<Content Include="scrollzones\blasteroids.js">
|
||||
<DependentUpon>blasteroids.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="scrollzones\parallax.js">
|
||||
<DependentUpon>parallax.ts</DependentUpon>
|
||||
</Content>
|
||||
|
@ -121,10 +125,6 @@
|
|||
<Content Include="scrollzones\simple scrollzone.js">
|
||||
<DependentUpon>simple scrollzone.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="scrollzones\texture repeat.ts" />
|
||||
<Content Include="scrollzones\texture repeat.js">
|
||||
<DependentUpon>texture repeat.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="sprites\align.js">
|
||||
<DependentUpon>align.ts</DependentUpon>
|
||||
</Content>
|
||||
|
|
BIN
Tests/assets/sprites/particle1.png
Normal file
BIN
Tests/assets/sprites/particle1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
|
@ -1593,7 +1593,7 @@ var Phaser;
|
|||
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
||||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
}
|
||||
if(this.flipped === true || this.rotation !== 0) {
|
||||
if(this.flipped === true || this.rotation !== 0 || this.rotationOffset !== 0) {
|
||||
//this._game.stage.context.translate(0, 0);
|
||||
this._game.stage.context.restore();
|
||||
}
|
||||
|
@ -10469,7 +10469,7 @@ var Phaser;
|
|||
particle.velocity.y = this.minParticleSpeed.y;
|
||||
}
|
||||
particle.acceleration.y = this.gravity;
|
||||
if(this.minRotation != this.maxRotation) {
|
||||
if(this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0) {
|
||||
particle.angularVelocity = this.minRotation + this._game.math.random() * (this.maxRotation - this.minRotation);
|
||||
} else {
|
||||
particle.angularVelocity = this.minRotation;
|
||||
|
|
87
Tests/scrollzones/blasteroids.js
Normal file
87
Tests/scrollzones/blasteroids.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
|
||||
myGame.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
myGame.loader.addImageFile('jet', 'assets/sprites/particle1.png');
|
||||
myGame.loader.addImageFile('bullet', 'assets/misc/bullet1.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var scroller;
|
||||
var emitter;
|
||||
var ship;
|
||||
var bullets;
|
||||
var speed = 0;
|
||||
var fireRate = 0;
|
||||
var shipMotion;
|
||||
function create() {
|
||||
scroller = myGame.createScrollZone('starfield', 0, 0, 1024, 1024);
|
||||
emitter = myGame.createEmitter(myGame.stage.centerX + 16, myGame.stage.centerY + 12);
|
||||
emitter.makeParticles('jet', 250, 0, false, 0);
|
||||
emitter.setRotation(0, 0);
|
||||
bullets = myGame.createGroup(50);
|
||||
// Create our bullet pool
|
||||
for(var i = 0; i < 50; i++) {
|
||||
var tempBullet = new Phaser.Sprite(myGame, myGame.stage.centerX, myGame.stage.centerY, 'bullet');
|
||||
tempBullet.exists = false;
|
||||
tempBullet.rotationOffset = 90;
|
||||
bullets.add(tempBullet);
|
||||
}
|
||||
ship = myGame.createSprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
|
||||
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
|
||||
ship.rotationOffset = 90;
|
||||
}
|
||||
function update() {
|
||||
// Recycle bullets
|
||||
bullets.forEach(recycleBullet);
|
||||
ship.angularVelocity = 0;
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
ship.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
ship.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
speed += 0.1;
|
||||
if(speed > 10) {
|
||||
speed = 10;
|
||||
}
|
||||
} else {
|
||||
speed -= 0.1;
|
||||
if(speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
shipMotion = myGame.motion.velocityFromAngle(ship.angle, speed);
|
||||
scroller.setSpeed(shipMotion.x, shipMotion.y);
|
||||
// emit particles
|
||||
if(speed > 2) {
|
||||
// We use the opposite of the motion because the jets emit out the back of the ship
|
||||
// The 20 and 30 values just keep them nice and fast
|
||||
emitter.setXSpeed(-(shipMotion.x * 20), -(shipMotion.x * 30));
|
||||
emitter.setYSpeed(-(shipMotion.y * 20), -(shipMotion.y * 30));
|
||||
emitter.emitParticle();
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) {
|
||||
fire();
|
||||
}
|
||||
}
|
||||
function recycleBullet(bullet) {
|
||||
if(bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640) {
|
||||
bullet.exists = false;
|
||||
}
|
||||
}
|
||||
function fire() {
|
||||
if(myGame.time.now > fireRate) {
|
||||
var b = bullets.getFirstAvailable();
|
||||
b.x = ship.x;
|
||||
b.y = ship.y - 26;
|
||||
var bulletMotion = myGame.motion.velocityFromAngle(ship.angle, 400);
|
||||
b.revive();
|
||||
b.angle = ship.angle;
|
||||
b.velocity.setTo(bulletMotion.x, bulletMotion.y);
|
||||
fireRate = myGame.time.now + 100;
|
||||
}
|
||||
}
|
||||
})();
|
138
Tests/scrollzones/blasteroids.ts
Normal file
138
Tests/scrollzones/blasteroids.ts
Normal file
|
@ -0,0 +1,138 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
|
||||
myGame.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
myGame.loader.addImageFile('jet', 'assets/sprites/particle1.png');
|
||||
myGame.loader.addImageFile('bullet', 'assets/misc/bullet1.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var scroller: Phaser.ScrollZone;
|
||||
var emitter: Phaser.Emitter;
|
||||
var ship: Phaser.Sprite;
|
||||
var bullets: Phaser.Group;
|
||||
|
||||
var speed: number = 0;
|
||||
var fireRate: number = 0;
|
||||
var shipMotion: Phaser.Point;
|
||||
|
||||
function create() {
|
||||
|
||||
scroller = myGame.createScrollZone('starfield', 0, 0, 1024, 1024);
|
||||
|
||||
emitter = myGame.createEmitter(myGame.stage.centerX + 16, myGame.stage.centerY + 12);
|
||||
emitter.makeParticles('jet', 250, 0, false, 0);
|
||||
emitter.setRotation(0, 0);
|
||||
|
||||
bullets = myGame.createGroup(50);
|
||||
|
||||
// Create our bullet pool
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var tempBullet = new Phaser.Sprite(myGame, myGame.stage.centerX, myGame.stage.centerY, 'bullet');
|
||||
tempBullet.exists = false;
|
||||
tempBullet.rotationOffset = 90;
|
||||
bullets.add(tempBullet);
|
||||
}
|
||||
|
||||
ship = myGame.createSprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
|
||||
|
||||
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
|
||||
ship.rotationOffset = 90;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
// Recycle bullets
|
||||
bullets.forEach(recycleBullet);
|
||||
|
||||
ship.angularVelocity = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
ship.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
ship.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
speed += 0.1;
|
||||
|
||||
if (speed > 10)
|
||||
{
|
||||
speed = 10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
speed -= 0.1;
|
||||
|
||||
if (speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
shipMotion = myGame.motion.velocityFromAngle(ship.angle, speed);
|
||||
|
||||
scroller.setSpeed(shipMotion.x, shipMotion.y);
|
||||
|
||||
// emit particles
|
||||
if (speed > 2)
|
||||
{
|
||||
// We use the opposite of the motion because the jets emit out the back of the ship
|
||||
// The 20 and 30 values just keep them nice and fast
|
||||
emitter.setXSpeed(-(shipMotion.x * 20), -(shipMotion.x * 30));
|
||||
emitter.setYSpeed(-(shipMotion.y * 20), -(shipMotion.y * 30));
|
||||
emitter.emitParticle();
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
|
||||
{
|
||||
fire();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function recycleBullet(bullet:Phaser.Sprite) {
|
||||
|
||||
if (bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640)
|
||||
{
|
||||
bullet.exists = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function fire() {
|
||||
|
||||
if (myGame.time.now > fireRate)
|
||||
{
|
||||
var b:Phaser.Sprite = bullets.getFirstAvailable();
|
||||
|
||||
b.x = ship.x;
|
||||
b.y = ship.y - 26;
|
||||
|
||||
var bulletMotion = myGame.motion.velocityFromAngle(ship.angle, 400);
|
||||
|
||||
b.revive();
|
||||
b.angle = ship.angle;
|
||||
b.velocity.setTo(bulletMotion.x, bulletMotion.y);
|
||||
|
||||
fireRate = myGame.time.now + 100;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
|
@ -1,51 +0,0 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
|
||||
myGame.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
myGame.loader.addImageFile('jet', 'assets/sprites/jets.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var scroller;
|
||||
var emitter;
|
||||
var ship;
|
||||
var speed = 0;
|
||||
function create() {
|
||||
scroller = myGame.createScrollZone('starfield', 0, 0, 1024, 1024);
|
||||
emitter = myGame.createEmitter(myGame.stage.centerX + 16, myGame.stage.centerY + 12);
|
||||
emitter.makeParticles('jet', 250, 0, false, 0);
|
||||
//emitter.lifespan
|
||||
ship = myGame.createSprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
|
||||
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
|
||||
ship.rotationOffset = 90;
|
||||
}
|
||||
function update() {
|
||||
ship.angularVelocity = 0;
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
ship.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
ship.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
speed += 0.1;
|
||||
if(speed > 10) {
|
||||
speed = 10;
|
||||
}
|
||||
} else {
|
||||
speed -= 0.1;
|
||||
if(speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
var motion = myGame.motion.velocityFromAngle(ship.angle, speed);
|
||||
scroller.setSpeed(motion.x, motion.y);
|
||||
// emit particles
|
||||
if(speed > 2) {
|
||||
emitter.setXSpeed(-(motion.x * 20), -(motion.x * 30));
|
||||
emitter.setYSpeed(-(motion.y * 20), -(motion.y * 30));
|
||||
emitter.emitParticle();
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -1,85 +0,0 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
|
||||
myGame.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
myGame.loader.addImageFile('jet', 'assets/sprites/jets.png');
|
||||
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var scroller: Phaser.ScrollZone;
|
||||
var emitter: Phaser.Emitter;
|
||||
var ship: Phaser.Sprite;
|
||||
|
||||
var speed: number = 0;
|
||||
|
||||
function create() {
|
||||
|
||||
scroller = myGame.createScrollZone('starfield', 0, 0, 1024, 1024);
|
||||
|
||||
emitter = myGame.createEmitter(myGame.stage.centerX + 16, myGame.stage.centerY + 12);
|
||||
emitter.makeParticles('jet', 250, 0, false, 0);
|
||||
//emitter.lifespan
|
||||
|
||||
|
||||
ship = myGame.createSprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
|
||||
|
||||
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
|
||||
ship.rotationOffset = 90;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
ship.angularVelocity = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
ship.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
ship.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
speed += 0.1;
|
||||
|
||||
if (speed > 10)
|
||||
{
|
||||
speed = 10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
speed -= 0.1;
|
||||
|
||||
if (speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(ship.angle, speed);
|
||||
|
||||
scroller.setSpeed(motion.x, motion.y);
|
||||
|
||||
// emit particles
|
||||
if (speed > 2)
|
||||
{
|
||||
emitter.setXSpeed(-(motion.x * 20), -(motion.x * 30));
|
||||
emitter.setYSpeed(-(motion.y * 20), -(motion.y * 30));
|
||||
emitter.emitParticle();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
|
@ -1593,7 +1593,7 @@ var Phaser;
|
|||
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
||||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
}
|
||||
if(this.flipped === true || this.rotation !== 0) {
|
||||
if(this.flipped === true || this.rotation !== 0 || this.rotationOffset !== 0) {
|
||||
//this._game.stage.context.translate(0, 0);
|
||||
this._game.stage.context.restore();
|
||||
}
|
||||
|
@ -10469,7 +10469,7 @@ var Phaser;
|
|||
particle.velocity.y = this.minParticleSpeed.y;
|
||||
}
|
||||
particle.acceleration.y = this.gravity;
|
||||
if(this.minRotation != this.maxRotation) {
|
||||
if(this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0) {
|
||||
particle.angularVelocity = this.minRotation + this._game.math.random() * (this.maxRotation - this.minRotation);
|
||||
} else {
|
||||
particle.angularVelocity = this.minRotation;
|
||||
|
|
Loading…
Reference in a new issue