changeset 24:b4068c1de2c3

razors kill zombies
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Wed, 31 Oct 2012 18:56:10 +0100
parents d766e4073e97
children b8a1082da1eb
files mhrok.js
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mhrok.js	Wed Oct 31 18:43:10 2012 +0100
+++ b/mhrok.js	Wed Oct 31 18:56:10 2012 +0100
@@ -260,6 +260,14 @@
         }, this);
         this.mobs_element.innerHTML = html;
     };
+    Game.prototype.mobsAt = function (x, y) {
+        return this.mobs.filter(function (mob) {
+            if (Math.round(mob.x / 32) === x &&
+                Math.round(mob.y / 24) === y) {
+                return true;
+            };
+        }, this);
+    };
 
     return {
         Game: Game,
@@ -331,6 +339,11 @@
             this.game.level.isBlocked(x + dir[0], y + dir[1])) {
             this.dead = true;
         };
+        this.game.mobsAt(x, y).forEach(function (mob) {
+            if (mob !== this && mob !== this.game.hero) {
+                mob.dead = true;
+            };
+        }, this);
     };
 
 
@@ -401,6 +414,8 @@
         ]);
         this.map_element.innerHTML = this.level.html();
         this.mobs.push(new Zombie(10, 8));
+        this.mobs.push(new Zombie(16, 4));
+        this.mobs.push(new Zombie(12, 12));
         this.hero = new Hero();
         this.mobs.push(this.hero);
     };