Jump to content

Weapon Plugin


Recommended Posts

I've just started creating  a schmup game using the Phaser Weapon plugin and would like to create bullets that cause different damage to the enemy according to which bullet type is selected. How can I set the damage value of a bullet created from the Weapon plugin or find the current damage value ie console.log(??). 

Link to comment
Share on other sites

Maybe the easiest way is to make an overlap handler that "knows" the damage for the bullets you're checking for. In other words, somewhere in update you have "game.physics.arcade.overlap(enemies, player.weapon1.bullets, this.onBulletsOverlap, null, this);". In "onBulletsOverlap" you know what kind of bullets hit (weapon1's bullets), so you can do the damage you need.

Alternately, you can create a custom bullet class and tell the weapon to use it via the "bulletClass" property on the weapon.

Link to comment
Share on other sites

Thanks drhayes. I've sorted it using  overlap and referencing the key of the weapon. 

weapon = game.add.weapon(30, 'bullet1');

weapon2 = game.add.weapon(30, 'bullet5');

this.physics.arcade.overlap(weapon.bullets, enemies, this.killEnemy, null, this);

this.physics.arcade.overlap(weapon2.bullets, enemies, this.killEnemy, null, this);

            console.log("kill both");
            /*===which bullet hit the enemy====*/
            /*===set bullet damage according to bullet key=====*/
            var damage;
            switch(bullet.key) {
                case 'bullet1':
                     damage = 1;
                 case 'bullet5':
                      damage = 10;
            enemy.health -= damage;
            if(enemy.health <=0)


Thanks for your help drhayes.

If anyones interested on how to implement this then you can view a very rough shmup code (view source) at http://www.davidbrind.co.uk/spaceshooter/index.html

Hope this helps others

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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