private void HandleTargetCollision() { foreach (Target t in _targets.ToArray()) { foreach (RectangleShape b in _player.bullets.ToArray()) { if (Target.HasBulletHitTarget(b, t)) { if (t is EquationTarget) { EquationTarget eqTarget = (EquationTarget)t; eqTarget.Selected(); Console.WriteLine("{0} {1} {2} = {3}", eqTarget.GetEquation.val1, eqTarget.GetEquation.type.ToString(), eqTarget.GetEquation.val2, eqTarget.GetEquation.solution); _isSolving = true; _eqToSolve = eqTarget; } else { // only remove now if normal target // equation targets get removed after being solved _targets.Remove(t); // normal target hit _score += 10; } _player.RemoveBullet(b); break; } } } }
public void TestTargetCollision() { Target t1 = new Target(10, 20); Target t2 = new Target(510, 20); Target t3 = new Target(10, 510); Target t4 = new Target(20, 10); // rect represents a bullets demensions RectangleShape rect = new RectangleShape(new Vector2f(10, 30)); rect.Position = new Vector2f(15, 25); // check for bounding box collision Assert.IsTrue(Target.HasBulletHitTarget(rect, t1)); Assert.IsFalse(Target.HasBulletHitTarget(rect, t2)); Assert.IsFalse(Target.HasBulletHitTarget(rect, t3)); Assert.IsTrue(Target.HasBulletHitTarget(rect, t4)); }