Skip to content

Commit 268470e

Browse files
committed
Added blaster example to the Test Suite and fixed a rotation bug in the particle emitter.
1 parent 6466361 commit 268470e

10 files changed

Lines changed: 235 additions & 146 deletions

File tree

Phaser/gameobjects/Emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ module Phaser {
372372

373373
particle.acceleration.y = this.gravity;
374374

375-
if (this.minRotation != this.maxRotation)
375+
if (this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0)
376376
{
377377
particle.angularVelocity = this.minRotation + this._game.math.random() * (this.maxRotation - this.minRotation);
378378
}

Phaser/gameobjects/Sprite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ module Phaser {
289289
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
290290
}
291291

292-
if (this.flipped === true || this.rotation !== 0)
292+
if (this.flipped === true || this.rotation !== 0 || this.rotationOffset !== 0)
293293
{
294294
//this._game.stage.context.translate(0, 0);
295295
this._game.stage.context.restore();

Tests/Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@
107107
<DependentUpon>ballscroller.ts</DependentUpon>
108108
</Content>
109109
<TypeScriptCompile Include="scrollzones\parallax.ts" />
110+
<TypeScriptCompile Include="scrollzones\blasteroids.ts" />
111+
<Content Include="scrollzones\blasteroids.js">
112+
<DependentUpon>blasteroids.ts</DependentUpon>
113+
</Content>
110114
<Content Include="scrollzones\parallax.js">
111115
<DependentUpon>parallax.ts</DependentUpon>
112116
</Content>
@@ -121,10 +125,6 @@
121125
<Content Include="scrollzones\simple scrollzone.js">
122126
<DependentUpon>simple scrollzone.ts</DependentUpon>
123127
</Content>
124-
<TypeScriptCompile Include="scrollzones\texture repeat.ts" />
125-
<Content Include="scrollzones\texture repeat.js">
126-
<DependentUpon>texture repeat.ts</DependentUpon>
127-
</Content>
128128
<Content Include="sprites\align.js">
129129
<DependentUpon>align.ts</DependentUpon>
130130
</Content>

Tests/assets/sprites/particle1.png

766 Bytes
Loading

Tests/phaser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,7 @@ var Phaser;
15931593
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
15941594
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
15951595
}
1596-
if(this.flipped === true || this.rotation !== 0) {
1596+
if(this.flipped === true || this.rotation !== 0 || this.rotationOffset !== 0) {
15971597
//this._game.stage.context.translate(0, 0);
15981598
this._game.stage.context.restore();
15991599
}
@@ -10469,7 +10469,7 @@ var Phaser;
1046910469
particle.velocity.y = this.minParticleSpeed.y;
1047010470
}
1047110471
particle.acceleration.y = this.gravity;
10472-
if(this.minRotation != this.maxRotation) {
10472+
if(this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0) {
1047310473
particle.angularVelocity = this.minRotation + this._game.math.random() * (this.maxRotation - this.minRotation);
1047410474
} else {
1047510475
particle.angularVelocity = this.minRotation;

Tests/scrollzones/blasteroids.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/// <reference path="../../Phaser/Game.ts" />
2+
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
3+
(function () {
4+
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
5+
function init() {
6+
myGame.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
7+
myGame.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
8+
myGame.loader.addImageFile('jet', 'assets/sprites/particle1.png');
9+
myGame.loader.addImageFile('bullet', 'assets/misc/bullet1.png');
10+
myGame.loader.load();
11+
}
12+
var scroller;
13+
var emitter;
14+
var ship;
15+
var bullets;
16+
var speed = 0;
17+
var fireRate = 0;
18+
var shipMotion;
19+
function create() {
20+
scroller = myGame.createScrollZone('starfield', 0, 0, 1024, 1024);
21+
emitter = myGame.createEmitter(myGame.stage.centerX + 16, myGame.stage.centerY + 12);
22+
emitter.makeParticles('jet', 250, 0, false, 0);
23+
emitter.setRotation(0, 0);
24+
bullets = myGame.createGroup(50);
25+
// Create our bullet pool
26+
for(var i = 0; i < 50; i++) {
27+
var tempBullet = new Phaser.Sprite(myGame, myGame.stage.centerX, myGame.stage.centerY, 'bullet');
28+
tempBullet.exists = false;
29+
tempBullet.rotationOffset = 90;
30+
bullets.add(tempBullet);
31+
}
32+
ship = myGame.createSprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
33+
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
34+
ship.rotationOffset = 90;
35+
}
36+
function update() {
37+
// Recycle bullets
38+
bullets.forEach(recycleBullet);
39+
ship.angularVelocity = 0;
40+
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
41+
ship.angularVelocity = -200;
42+
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
43+
ship.angularVelocity = 200;
44+
}
45+
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
46+
speed += 0.1;
47+
if(speed > 10) {
48+
speed = 10;
49+
}
50+
} else {
51+
speed -= 0.1;
52+
if(speed < 0) {
53+
speed = 0;
54+
}
55+
}
56+
shipMotion = myGame.motion.velocityFromAngle(ship.angle, speed);
57+
scroller.setSpeed(shipMotion.x, shipMotion.y);
58+
// emit particles
59+
if(speed > 2) {
60+
// We use the opposite of the motion because the jets emit out the back of the ship
61+
// The 20 and 30 values just keep them nice and fast
62+
emitter.setXSpeed(-(shipMotion.x * 20), -(shipMotion.x * 30));
63+
emitter.setYSpeed(-(shipMotion.y * 20), -(shipMotion.y * 30));
64+
emitter.emitParticle();
65+
}
66+
if(myGame.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) {
67+
fire();
68+
}
69+
}
70+
function recycleBullet(bullet) {
71+
if(bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640) {
72+
bullet.exists = false;
73+
}
74+
}
75+
function fire() {
76+
if(myGame.time.now > fireRate) {
77+
var b = bullets.getFirstAvailable();
78+
b.x = ship.x;
79+
b.y = ship.y - 26;
80+
var bulletMotion = myGame.motion.velocityFromAngle(ship.angle, 400);
81+
b.revive();
82+
b.angle = ship.angle;
83+
b.velocity.setTo(bulletMotion.x, bulletMotion.y);
84+
fireRate = myGame.time.now + 100;
85+
}
86+
}
87+
})();

Tests/scrollzones/blasteroids.ts

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/// <reference path="../../Phaser/Game.ts" />
2+
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
3+
4+
(function () {
5+
6+
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
7+
8+
function init() {
9+
10+
myGame.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
11+
myGame.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
12+
myGame.loader.addImageFile('jet', 'assets/sprites/particle1.png');
13+
myGame.loader.addImageFile('bullet', 'assets/misc/bullet1.png');
14+
15+
myGame.loader.load();
16+
17+
}
18+
19+
var scroller: Phaser.ScrollZone;
20+
var emitter: Phaser.Emitter;
21+
var ship: Phaser.Sprite;
22+
var bullets: Phaser.Group;
23+
24+
var speed: number = 0;
25+
var fireRate: number = 0;
26+
var shipMotion: Phaser.Point;
27+
28+
function create() {
29+
30+
scroller = myGame.createScrollZone('starfield', 0, 0, 1024, 1024);
31+
32+
emitter = myGame.createEmitter(myGame.stage.centerX + 16, myGame.stage.centerY + 12);
33+
emitter.makeParticles('jet', 250, 0, false, 0);
34+
emitter.setRotation(0, 0);
35+
36+
bullets = myGame.createGroup(50);
37+
38+
// Create our bullet pool
39+
for (var i = 0; i < 50; i++)
40+
{
41+
var tempBullet = new Phaser.Sprite(myGame, myGame.stage.centerX, myGame.stage.centerY, 'bullet');
42+
tempBullet.exists = false;
43+
tempBullet.rotationOffset = 90;
44+
bullets.add(tempBullet);
45+
}
46+
47+
ship = myGame.createSprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
48+
49+
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
50+
ship.rotationOffset = 90;
51+
52+
}
53+
54+
function update() {
55+
56+
// Recycle bullets
57+
bullets.forEach(recycleBullet);
58+
59+
ship.angularVelocity = 0;
60+
61+
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
62+
{
63+
ship.angularVelocity = -200;
64+
}
65+
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
66+
{
67+
ship.angularVelocity = 200;
68+
}
69+
70+
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
71+
{
72+
speed += 0.1;
73+
74+
if (speed > 10)
75+
{
76+
speed = 10;
77+
}
78+
}
79+
else
80+
{
81+
speed -= 0.1;
82+
83+
if (speed < 0) {
84+
speed = 0;
85+
}
86+
}
87+
88+
shipMotion = myGame.motion.velocityFromAngle(ship.angle, speed);
89+
90+
scroller.setSpeed(shipMotion.x, shipMotion.y);
91+
92+
// emit particles
93+
if (speed > 2)
94+
{
95+
// We use the opposite of the motion because the jets emit out the back of the ship
96+
// The 20 and 30 values just keep them nice and fast
97+
emitter.setXSpeed(-(shipMotion.x * 20), -(shipMotion.x * 30));
98+
emitter.setYSpeed(-(shipMotion.y * 20), -(shipMotion.y * 30));
99+
emitter.emitParticle();
100+
}
101+
102+
if (myGame.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
103+
{
104+
fire();
105+
}
106+
107+
}
108+
109+
function recycleBullet(bullet:Phaser.Sprite) {
110+
111+
if (bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640)
112+
{
113+
bullet.exists = false;
114+
}
115+
116+
}
117+
118+
function fire() {
119+
120+
if (myGame.time.now > fireRate)
121+
{
122+
var b:Phaser.Sprite = bullets.getFirstAvailable();
123+
124+
b.x = ship.x;
125+
b.y = ship.y - 26;
126+
127+
var bulletMotion = myGame.motion.velocityFromAngle(ship.angle, 400);
128+
129+
b.revive();
130+
b.angle = ship.angle;
131+
b.velocity.setTo(bulletMotion.x, bulletMotion.y);
132+
133+
fireRate = myGame.time.now + 100;
134+
}
135+
136+
}
137+
138+
})();

Tests/scrollzones/texture repeat.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)