Mercurial > mhrok3
changeset 22:b688f8cce051
make the razor blades hit walls
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Wed, 31 Oct 2012 18:31:08 +0100 |
| parents | 1e53472d9244 |
| children | d766e4073e97 |
| files | mhrok.js |
| diffstat | 1 files changed, 6 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mhrok.js Wed Oct 31 18:19:45 2012 +0100 +++ b/mhrok.js Wed Oct 31 18:31:08 2012 +0100 @@ -305,25 +305,28 @@ return false; }; - var Razor = function (x, y, direction) { + var Razor = function (x, y, direction, level) { MhrokLib.Mob.apply(this, arguments); this.x = x * 32; this.y = y * 24; this.z = y; this.direction = direction; this.ttl = 100; + this.level = level; }; Razor.prototype = Object.create(MhrokLib.Mob.prototype); Razor.prototype.classes += ' mhrok-razor'; Razor.prototype.animate = function (frame) { var dir = this.directions[this.direction]; + var x = Math.round(this.x / 32 - dir[0]); + var y = Math.round(this.y /24 - dir[1]); this.frame = (this.frame + 1) % 8; this.frameX = 0; this.frameY = this.frame; this.x += dir[0] * 8; this.y += dir[1] * 6; this.ttl -= 1; - if (this.ttl <= 0) { + if (this.ttl <= 0 || this.level.isBlocked(x + dir[0], y + dir[1])) { this.dead = true; }; }; @@ -365,7 +368,7 @@ }; Hero.prototype.stab = function (game) { this.animation = 'stab'; - game.mobs.push(new Razor(this.x/32, this.y/24, this.direction)); + game.mobs.push(new Razor(this.x/32, this.y/24, this.direction, game.level)); return true; };
