Jump to content

Extend Weapon Plugin (TypeScript)


Auxilinaut
 Share

Recommended Posts

Hello,

I'm trying to make separate weapon classes in an Asteroids-type game, for example a Missile.ts, Laser.ts, etc.

What I have so far is this (Missile.ts):

module Spaceroni {

    export class Missile extends Phaser.Weapon {

        constructor(game: Phaser.Game) {

            super(game, game.plugins);
            
            this.bulletKillType = Phaser.Weapon.KILL_LIFESPAN;
            this.bulletSpeed = 1500;
            this.fireRate = 20;

        }

    }

}

In my Player.ts I have

weapon: Spaceroni.Missile;

up top and I'm adding a weapon in its constructor with

this.weapon = game.add.weapon(30, 'missile');

This isn't working (bulletSpeed and fireRate aren't changing), I think because game.add.weapon() creates a new weapon instance, separate from my Missile class. I would like to avoid putting all of this Missile-specific code directly into the Player class since I want to be able to change the weapon based on power-ups, as well as add the Missile weapon to enemies.

Any ideas on how to properly extend the weapon plugin?

Thanks in advance!

Link to comment
Share on other sites

Hi, you need a helper similar to game.add.weapon:

Phaser.GameObjectFactory.prototype.missile = function (quantity, key, frame, group) {
  var missile = this.game.plugins.add(Spaceroni.Missile);

  missile.createBullets(quantity, key, frame, group);

  return missile;
};

// …

this.weapon = game.add.missile(30, 'missile');

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...