public void Collide(Explosion exp, List<GameObject> allObjects) { for (int i = 0; i < allObjects.Count; i++) { GameObject obj = allObjects[i]; if ((obj.Top == exp.Top - exp.CurrentRadius && obj.Left == exp.Left && !exp.StopUp) || (obj.Top == exp.Top && obj.Left == exp.Left + exp.CurrentRadius && !exp.StopRight) || (obj.Top == exp.Top + exp.CurrentRadius && obj.Left == exp.Left && !exp.StopDown) || (obj.Top == exp.Top && obj.Left == exp.Left - exp.CurrentRadius && !exp.StopLeft) ) { if (obj is Bomb) { Bomb bomb = (Bomb)obj; bomb.Explode(); } else if (obj is ComputerPlayer) { if (KilledComputerPlayer != null) { KilledComputerPlayer(obj, new EventArgs()); } } else if (!(obj is IndestructibleBrick)) { obj.IsDestroyed = true; } else { if (obj.Top == exp.Top - exp.CurrentRadius && obj.Left == exp.Left) { exp.StopUp = true; } else if (obj.Top == exp.Top && obj.Left == exp.Left + exp.CurrentRadius) { exp.StopRight = true; } else if (obj.Top == exp.Top + exp.CurrentRadius && obj.Left == exp.Left) { exp.StopDown = true; } else if (obj.Top == exp.Top && obj.Left == exp.Left - exp.CurrentRadius) { exp.StopLeft = true; } } } } allObjects.RemoveAll(obj => obj.IsDestroyed); }
public void CatchExplosion(object sender, EventArgs e) { Bomb bomb = (Bomb)sender; Explosion newExp = new Explosion(bomb.Left, bomb.Top); newExp.OnUpdate += delegate(object _sender, EventArgs _e) { expHandler.Collide((Explosion)_sender, renderedObjects); }; newExp.OnUpdate += expHandler.UpdateBlast; newExp.OnDissappear += delegate(object _sender, EventArgs _e) { Explosion exp = (Explosion)_sender; foreach (CoordinateArgs coords in exp.CleanUpCoords) { renderer.CleanUp(this, coords); } }; this.explosions.Add(newExp); }