Cleanup: Monster also uses JusticeBlaster as a weapon
authorMegaBrutal <code+git@megabrutal.com>
Wed, 27 Dec 2017 23:45:00 +0000 (00:45 +0100)
committerMegaBrutal <code+git@megabrutal.com>
Wed, 27 Dec 2017 23:45:00 +0000 (00:45 +0100)
To further simplify the code, the Monster class should also use
the JusticeBlaster weapon class as its weapon.

modified:   ld40.js

ld40.js

diff --git a/ld40.js b/ld40.js
index d32c5ff..6a1eb77 100644 (file)
--- a/ld40.js
+++ b/ld40.js
@@ -22,7 +22,8 @@
         const MODE_DETERMINATION       =      0;
         const MODE_JUSTICE             =      1;
         const SPEED_PLAYER             =    150;
-        const SPEED_PROJECTILE         =    500;
+        const SPEED_PPROJECTILE                =    500;
+        const SPEED_MPROJECTILE                =    200;
 
         window.addEventListener("keydown", function(e) {
             // Prevent default browser action for arrows and spacebar
@@ -46,6 +47,7 @@
                 this.speed = 150;
                 this.switchmode(MODE_DETERMINATION);
                 this.weapon = new JusticeBlaster(game, this);
+                this.weapon.bulletSpeed = SPEED_PPROJECTILE;
                 this.healthBar = new HealthBar(60, game.world.height - (WALL_BORDERBOTTOM / 2));
             }
 
                 this.anchor.setTo(0.5, 0.5);
                 this.health = MONSTER_HEALTH;
                 this.nexttime_shoot = game.time.now;
-                this.weapon = new Phaser.Weapon(game, this);
-                this.weapon.x = x;
-                this.weapon.y = y;
-                this.weapon.createBullets(20, 'projectile');
+                this.weapon = new JusticeBlaster(game, this);
+                this.weapon.bulletSpeed = SPEED_MPROJECTILE;
+                this.weapon.trackSprite(this);
             }
 
             enablePhysics() {
                     this.weapon.fireAtSprite(player);
                     this.nexttime_shoot = game.time.now + (WAIT_MONSTERSHOOT / 2) + (Math.random() * WAIT_MONSTERSHOOT);
                 }
-                game.physics.arcade.overlap(player, this.weapon.bullets, function(p,b) { p.damage(p.love); });
+                game.physics.arcade.overlap(player, this.weapon.bullets, function(p,b) { b.overlap_player(p); });
             }
         }
 
                 entity.damage(player.love);
                 this.kill();
             }
+
+            overlap_player(player) {
+                player.damage(player.love);
+                this.kill();
+            }
         }
 
         class JusticeBlaster extends Phaser.Weapon {
             constructor(game, parent) {
                 super(game, parent);
                 this.bulletClass = Justice;
-                this.bulletSpeed = SPEED_PROJECTILE;
                 this.multiFire = true;
                 this.createBullets(100, null);
             }