Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Bug 738999: Prevent dying mobs from reappearing
Browse files Browse the repository at this point in the history
  • Loading branch information
sork committed Mar 24, 2012
1 parent 4c23f09 commit e41fa31
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 38 deletions.
8 changes: 6 additions & 2 deletions client/js/camera.js
Expand Up @@ -57,8 +57,12 @@ define(function() {
},

isVisible: function(entity) {
if(entity.gridY >= this.gridY && entity.gridY < this.gridY + this.gridH
&& entity.gridX >= this.gridX && entity.gridX < this.gridX + this.gridW) {
return this.isVisiblePosition(entity.gridX, entity.gridY);
},

isVisiblePosition: function(x, y) {
if(y >= this.gridY && y < this.gridY + this.gridH
&& x >= this.gridX && x < this.gridX + this.gridW) {
return true;
} else {
return false;
Expand Down
18 changes: 10 additions & 8 deletions client/js/character.js
Expand Up @@ -67,16 +67,18 @@ define(['entity', 'transition', 'timer'], function(Entity, Transition, Timer) {
animate: function(animation, speed, count, onEndCount) {
var oriented = ['atk', 'walk', 'idle'];
o = this.orientation;

this.flipSpriteX = false;
this.flipSpriteY = false;

if(!(this.currentAnimation && this.currentAnimation.name === "death")) { // don't change animation if the character is dying
this.flipSpriteX = false;
this.flipSpriteY = false;

if(_.indexOf(oriented, animation) >= 0) {
animation += "_" + (o === Types.Orientations.LEFT ? "right" : Types.getOrientationAsString(o));
this.flipSpriteX = (this.orientation === Types.Orientations.LEFT) ? true : false;
}
if(_.indexOf(oriented, animation) >= 0) {
animation += "_" + (o === Types.Orientations.LEFT ? "right" : Types.getOrientationAsString(o));
this.flipSpriteX = (this.orientation === Types.Orientations.LEFT) ? true : false;
}

this.setAnimation(animation, speed, count, onEndCount);
this.setAnimation(animation, speed, count, onEndCount);
}
},

turnTo: function(orientation) {
Expand Down
59 changes: 32 additions & 27 deletions client/js/game.js
Expand Up @@ -1109,40 +1109,44 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
});

entity.onStep(function() {
self.registerEntityDualPosition(entity);

entity.forEachAttacker(function(attacker) {
if(attacker.isAdjacent(attacker.target)) {
attacker.lookAtTarget();
} else {
attacker.follow(entity);
}
});
if(!entity.isDying) {
self.registerEntityDualPosition(entity);

entity.forEachAttacker(function(attacker) {
if(attacker.isAdjacent(attacker.target)) {
attacker.lookAtTarget();
} else {
attacker.follow(entity);
}
});
}
});

entity.onStopPathing(function(x, y) {
if(entity.hasTarget() && entity.isAdjacent(entity.target)) {
entity.lookAtTarget();
}
if(!entity.isDying) {
if(entity.hasTarget() && entity.isAdjacent(entity.target)) {
entity.lookAtTarget();
}

if(entity instanceof Player) {
var gridX = entity.destination.gridX,
gridY = entity.destination.gridY;

if(self.map.isDoor(gridX, gridY)) {
var dest = self.map.getDoorDestination(gridX, gridY);
entity.setGridPosition(dest.x, dest.y);
if(entity instanceof Player) {
var gridX = entity.destination.gridX,
gridY = entity.destination.gridY;

if(self.map.isDoor(gridX, gridY)) {
var dest = self.map.getDoorDestination(gridX, gridY);
entity.setGridPosition(dest.x, dest.y);
}
}
}

entity.forEachAttacker(function(attacker) {
if(!attacker.isAdjacentNonDiagonal(entity) && attacker.id !== self.playerId) {
attacker.follow(entity);
}
});
entity.forEachAttacker(function(attacker) {
if(!attacker.isAdjacentNonDiagonal(entity) && attacker.id !== self.playerId) {
attacker.follow(entity);
}
});

self.unregisterEntityPosition(entity);
self.registerEntityPosition(entity);
self.unregisterEntityPosition(entity);
self.registerEntityPosition(entity);
}
});

entity.onRequestPath(function(x, y) {
Expand All @@ -1169,6 +1173,7 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
self.deathpositions[entity.id] = {x: entity.gridX, y: entity.gridY};
}

entity.isDying = true;
entity.setSprite(self.sprites[entity instanceof Mobs.Rat ? "rat" : "death"]);
entity.animate("death", 120, 1, function() {
log.info(entity.id + " was removed");
Expand Down
2 changes: 1 addition & 1 deletion client/js/renderer.js
Expand Up @@ -214,7 +214,7 @@ function(Camera, Item, Character, Player, Timer) {
if(grid && this.game.debugPathing) {
for(var y=0; y < grid.length; y += 1) {
for(var x=0; x < grid[y].length; x += 1) {
if(grid[y][x] === 1) {
if(grid[y][x] === 1 && this.game.camera.isVisiblePosition(x, y)) {
this.drawCellHighlight(x, y, "rgba(50, 50, 255, 0.5)");
}
}
Expand Down

0 comments on commit e41fa31

Please sign in to comment.