Mercurial > mhrok3
changeset 19:46740b0df19c
zombie ai
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Wed, 31 Oct 2012 15:18:02 +0100 |
| parents | 8bfcdb4f37fe |
| children | 8612a4068d43 |
| files | mhrok.js |
| diffstat | 1 files changed, 16 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mhrok.js Wed Oct 31 14:07:51 2012 +0100 +++ b/mhrok.js Wed Oct 31 15:18:02 2012 +0100 @@ -284,13 +284,26 @@ (function () { - var Zombie = function () { + var Zombie = function (x, y) { MhrokLib.Char.apply(this, arguments); + this.x = x * 32; + this.y = y * 24; + this.z = y; }; Zombie.prototype = Object.create(MhrokLib.Char.prototype); Zombie.prototype.classes += ' mhrok-zombie'; Zombie.prototype.update = function (game) { - this.walk('south'); + if (game.hero.y > this.y) { + this.walk('south'); + } else if (game.hero.y < this.y) { + this.walk('north'); + } else if (game.hero.x > this.x) { + this.walk('east'); + } else if (game.hero.x < this.x) { + this.walk('west'); + } else { + this.animation = 'stand'; + }; }; @@ -321,7 +334,7 @@ this.map_element.innerHTML = this.level.html(); this.hero = new MhrokLib.Hero(); this.mobs.push(this.hero); - this.mobs.push(new Zombie()); + this.mobs.push(new Zombie(10, 8)); }; Game.prototype = Object.create(MhrokLib.Game.prototype);
