Browse code

use blue bullet for hero

devnewton authored on 13/10/2016 at 13:39:45
Showing 3 changed files
... ...
@@ -4,9 +4,12 @@ import {Vulnerable} from "./features/Vulnerable.ts";
4 4
 
5 5
 export class Bullet extends Phaser.Sprite implements Vulnerable {
6 6
 
7
-    constructor(game: Phaser.Game) {
8
-        super(game, 0, 0, 'bullets');
9
-        (<ShmuprpgGame>game).addSpriteAnimation(this, 'bullet.red', 4);
7
+    bulletAnimation: string;
8
+
9
+    constructor(game: Phaser.Game, animation = 'bullet.red', atlas = 'bullets') {
10
+        super(game, 0, 0, atlas);
11
+        this.bulletAnimation = animation;
12
+        (<ShmuprpgGame>game).addSpriteAnimation(this, this.bulletAnimation, 4);
10 13
         this.game.physics.enable(this, Phaser.Physics.ARCADE);
11 14
         this.anchor.setTo(0.5, 0.5);
12 15
         this.checkWorldBounds = true;
... ...
@@ -24,6 +27,6 @@ export class Bullet extends Phaser.Sprite implements Vulnerable {
24 24
         this.game.physics.arcade.velocityFromRotation(angle, speed, this.body.velocity);
25 25
         this.angle = angle;
26 26
         this.body.gravity.set(gravityX, gravityY);
27
-        this.play('bullet.red', 4, true);
27
+        this.play(this.bulletAnimation, 4, true);
28 28
     }
29 29
 }
... ...
@@ -3,10 +3,11 @@ import { ShmuprpgGame } from "../ShmuprpgGame.ts";
3 3
 import { MachineGun } from "./MachineGun.ts";
4 4
 import { Controls } from "../utils/Controls.ts";
5 5
 import {Vulnerable} from "./features/Vulnerable.ts";
6
+import {Bullet} from "./Bullet.ts";
6 7
 
7 8
 export class Hero extends Phaser.Sprite implements Vulnerable {
8 9
 
9
-    weapon: MachineGun;
10
+    weapon: HeroMachineGun;
10 11
     controls: Controls;
11 12
 
12 13
     constructor(game: Phaser.Game) {
... ...
@@ -23,7 +24,7 @@ export class Hero extends Phaser.Sprite implements Vulnerable {
23 23
         this.game.physics.enable(this, Phaser.Physics.ARCADE);
24 24
         this.body.setSize(16, 16, 24, 48);
25 25
         this.body.collideWorldBounds = true;
26
-        this.weapon = new MachineGun(this.game);
26
+        this.weapon = new HeroMachineGun(this.game);
27 27
         this.game.add.existing(this.weapon);
28 28
     }
29 29
 
... ...
@@ -86,3 +87,9 @@ export class Hero extends Phaser.Sprite implements Vulnerable {
86 86
         return this;
87 87
     }
88 88
 }
89
+
90
+class HeroMachineGun extends MachineGun {
91
+    createBullet(): Bullet {
92
+        return new Bullet(this.game, 'bullet.blue');
93
+    }
94
+}
89 95
\ No newline at end of file
... ...
@@ -2,6 +2,4 @@
2 2
 
3 3
 export interface Vulnerable {
4 4
     getVulnerableRectangles(): Array<Phaser.Rectangle>;
5
-
6
-
7 5
 }
8 6
\ No newline at end of file