Hi!
Im trying to write my own version of bomberman and I`ve got problem with explosion, which is deleting boxes correctly but unfortunatelly it kills its neighbours too (some of them, and not always…)
What I found is when overlap occurs it spot sometimes more boxes - why ?
Some of my code:
this.boxesLayer = this.map.createDynamicLayer(“boxes”, this.tileset, 0, 0);
this.physics.add.overlap(this.boxesLayer, this.explosions,
this.destroyBoxes,null,this);
destroyBoxes(explo,box)
{
this.boxesLayer.removeTileAt(box.x,box.y);
}
explode(){
let range = this.player.range;
let x = this.x;
let y = this.y;
let step = 32;
let boxRight = false;
let boxLeft = false;
let boxUp = false;
let boxDown = false;
for(let i = 0; i < range; i++){
if(!this.scene.blocksLayer.getTileAtWorldXY(x + i*step, y) && !boxRight)
new Explosion(this.scene,x + i*step, y);
if(this.scene.boxesLayer.getTileAtWorldXY(x + i*step, y) ||
this.scene.blocksLayer.getTileAtWorldXY(x + i*step, y))
boxRight = true;
if(!this.scene.blocksLayer.getTileAtWorldXY(x - i*step, y) && !boxLeft)
new Explosion(this.scene,x - i*step, y);
if(this.scene.boxesLayer.getTileAtWorldXY(x - i*step, y) ||
this.scene.blocksLayer.getTileAtWorldXY(x - i*step, y))
boxLeft = true;
if(!this.scene.blocksLayer.getTileAtWorldXY(x, y+i*step) && !boxDown)
new Explosion(this.scene,x, y+i*step);
if(this.scene.boxesLayer.getTileAtWorldXY(x, y+i*step) ||
this.scene.blocksLayer.getTileAtWorldXY(x, y+i*step))
boxDown = true;
if(!this.scene.blocksLayer.getTileAtWorldXY(x, y-i*step) && !boxUp)
new Explosion(this.scene,x, y-i*step);
if(this.scene.boxesLayer.getTileAtWorldXY(x, y-i*step) ||
this.scene.blocksLayer.getTileAtWorldXY(x, y-i*step))
boxUp = true;
}
}