Shake monsters when damaged
[ld40.git] / ld40.js
diff --git a/ld40.js b/ld40.js
index 6a1eb77ea15a4a09b5d5c371c93c5941f4eb4ced..53e41f87ce314147e88d5301a5a3b91ea399bfc0 100644 (file)
--- a/ld40.js
+++ b/ld40.js
@@ -44,7 +44,7 @@
                 this.lasttime_shoot = 0;
                 this.lasttime_mode = 0;
                 this.lasttime_damage = 0;
-                this.speed = 150;
+                this.speed = SPEED_PLAYER;
                 this.switchmode(MODE_DETERMINATION);
                 this.weapon = new JusticeBlaster(game, this);
                 this.weapon.bulletSpeed = SPEED_PPROJECTILE;
                 }
             }
 
+            kill() {
+                this.health = 0;
+                this.healthBar.update(this.love, this.maxHealth, this.health);
+                super.kill();
+            }
+
             loveUp() {
                 this.love++
                 this.maxHealth += this.love;
                 game.physics.arcade.enable(this);
             }
 
+            damage(amount) {
+                super.damage(amount);
+                if (this.alive) { game.add.tween(this).to({ x: this.x + (Math.random() - 0.5) * 10 }, 10, Phaser.Easing.Sinusoidal.InOut, true, 0, 8, true); }
+            }
+
             kill() {
                 super.kill();
                 player.loveUp();
             nexttime_determination = Math.random() * WAIT_DETERMINATION;
 
             monsters = game.add.group();
-            monsters.add(new Monster(400, 500));
-            monsters.children.forEach(function(monster) { monster.enablePhysics(); });
-            nexttime_monsterspawn = WAIT_MONSTERSPAWN;
+            nexttime_monsterspawn = WAIT_MONSTERSPAWN / 4;
 
             player = new Player(game.world.width / 2, game.world.height / 2);
             player.enablePhysics();
             game.camera.follow(player);
             cursors = game.input.keyboard.createCursorKeys();
 
-            keyboard_handler = keyPress_default;
-
         }
 
         function update () {
                 var monster = new Monster(Math.random() * game.world.width, Math.random() * game.world.height);
                 monster.enablePhysics();
                 monsters.add(monster);
-                nexttime_monsterspawn = game.time.now + (WAIT_MONSTERSPAWN / player.love) + (Math.random() * WAIT_MONSTERSPAWN);
+                var waittime = WAIT_MONSTERSPAWN - ((Math.random() * 2000) * player.love);
+                nexttime_monsterspawn = game.time.now + waittime;
+                console.log('Next monster in ' + waittime);
             }
 
             if ((game.time.now - player.lastmovetime) > WAIT_KEY) player.body.velocity.x = player.body.velocity.y = 0;
-            if (keyboard_handler) keyboard_handler();
-
-        }
-
-        function keyPress_default() {
-
-            // Maybe needed later.
 
         }