Skip to content

Commit ae5be7a

Browse files
committed
Merging in the new Weapon Plugin.
1 parent 84c60d4 commit ae5be7a

2 files changed

Lines changed: 912 additions & 0 deletions

File tree

src/plugins/weapon/Bullet.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Phaser.Bullet = function (game, x, y, key, frame) {
2+
3+
Phaser.Sprite.call(this, game, x, y, key, frame);
4+
5+
this.anchor.set(0.5);
6+
7+
this.data = {
8+
bulletManager: null,
9+
fromX: 0,
10+
fromY: 0,
11+
bodyDirty: true,
12+
rotateToVelocity: false,
13+
killType: 0,
14+
killDistance: 0
15+
};
16+
17+
};
18+
19+
Phaser.Bullet.prototype = Object.create(Phaser.Sprite.prototype);
20+
Phaser.Bullet.prototype.constructor = Phaser.Bullet;
21+
22+
Phaser.Bullet.prototype.kill = function () {
23+
24+
this.alive = false;
25+
this.exists = false;
26+
this.visible = false;
27+
28+
this.data.bulletManager.onKill.dispatch(this);
29+
30+
return this;
31+
32+
};
33+
34+
Phaser.Bullet.prototype.update = function () {
35+
36+
if (!this.exists)
37+
{
38+
return;
39+
}
40+
41+
if (this.data.killType > Phaser.Weapon.KILL_LIFESPAN)
42+
{
43+
if (this.data.killType === Phaser.Weapon.KILL_DISTANCE)
44+
{
45+
if (this.game.physics.arcade.distanceToXY(this, this.data.fromX, this.data.fromY, true) > this.data.killDistance)
46+
{
47+
this.kill();
48+
}
49+
}
50+
else
51+
{
52+
if (!this.data.bulletManager.bulletBounds.intersects(this))
53+
{
54+
this.kill();
55+
}
56+
}
57+
}
58+
59+
if (this.data.rotateToVelocity)
60+
{
61+
this.rotation = Math.atan2(this.body.velocity.y, this.body.velocity.x);
62+
}
63+
64+
if (this.data.bulletManager.bulletWorldWrap)
65+
{
66+
this.game.world.wrap(this, this.data.bulletManager.bulletWorldWrapPadding);
67+
}
68+
69+
};

0 commit comments

Comments
 (0)