Permalink
Browse files

fixed not escaping from own bomb once planted

  • Loading branch information...
1 parent 7237d76 commit 125134307f7b5682d817eae624595edef1b2a272 @MrJaba committed Apr 18, 2010
Showing with 12 additions and 8 deletions.
  1. +5 −5 public/javascripts/game.js
  2. +7 −3 public/javascripts/sprite.js
View
10 public/javascripts/game.js
@@ -153,18 +153,18 @@ MrJaba.Bomberman = function(){
})
},
- mapContainsBombAt: function(x, y){
- var containsBomb = false;
+ fetchBombAt: function(x, y){
+ var mapBomb = null;
$.each(MrJaba.Bomberman.bombs, function(uuid, bomb){
var bombX = (bomb.getX() + bomb.frameWidth/2);
var bombY = (bomb.getY() + MrJaba.Bomberman.Images.getImage('Bomb').height/2);
var boardX = parseInt(bombX / MrJaba.Bomberman.Images.tileWidth());
var boardY = parseInt(bombY / MrJaba.Bomberman.Images.visibleTileHeight());
- if( !containsBomb && boardX === x && boardY === y){
- containsBomb = true;
+ if( mapBomb === null && boardX === x && boardY === y){
+ mapBomb = bomb;
}
})
- return containsBomb;
+ return mapBomb;
},
updateBombPositions: function(positions){
View
10 public/javascripts/sprite.js
@@ -88,15 +88,19 @@ Sprite.prototype = {
canMoveTo:function(newX, newY){
var tileX = this.getTileX(newX);
var tileY = this.getTileY(newY);
- //if( this.inSameTile(tileX, tileY) ){ return true; }
if( tileX < MrJaba.Bomberman.map.length && tileY < MrJaba.Bomberman.map[tileX].length){
var intoTile = MrJaba.Bomberman.map[tileX][tileY];
- var containsBomb = MrJaba.Bomberman.mapContainsBombAt(tileX, tileY);
- return intoTile.walkable && !containsBomb && newX >= 0 && newX < this.canvas.width && newY >= -40 && newY < this.canvas.height;
+ var bomb = MrJaba.Bomberman.fetchBombAt(tileX, tileY);
+ if( this.canEscapeFromTheBombIJustDropped(tileX, tileY, bomb) ){ return true; }
+ return intoTile.walkable && bomb === null && newX >= 0 && newX < this.canvas.width && newY >= -40 && newY < this.canvas.height;
}
return false;
},
+ canEscapeFromTheBombIJustDropped:function(tileX, tileY, bomb){
+ return this.inSameTile(tileX, tileY) && bomb !== null && bomb.getId() === MrJaba.Bomberman.uuid;
+ },
+
inSameTile:function(newTileX, newTileY){
return (newTileX === this.getTileX() && newTileY === this.getTileY());
}

0 comments on commit 1251343

Please sign in to comment.