public void TestHasOcsilattedToEdge() { Target t1 = new Target (10, 20); Target t2 = new Target (510, 0); Target t3 = new Target (980, 10); Target t4 = new Target (-180, 10); Assert.IsTrue (Target.HasOscillatedToEdge(t1), "Test left edge"); Assert.IsFalse (Target.HasOscillatedToEdge(t2), "Test Middle"); Assert.IsTrue (Target.HasOscillatedToEdge(t3), "Test right edge"); Assert.IsTrue (Target.HasOscillatedToEdge(t4), "Test negative x value (off the screen)"); }
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)); }
public void TestGettingOuterTargets() { Target t1 = new Target (80, 0); Target t2 = new Target (10, 20); Target t3 = new Target (110, 0); Target t4 = new Target (400, 10); Target t5 = new Target (200, 100); List<Target> targets = new List<Target> () {t1, t2, t3, t4, t5}; List<Target> outer = Target.GetOuterTargets(targets); Target outerLeft = outer [0]; Target outerRight = outer [1]; // Outer left should be t2 as it has the lowest X value Assert.AreEqual (t2, outerLeft); // Outer right should be t4 as it has the highest X value Assert.AreEqual (t4, outerRight); }
public static bool HasOscillatedToEdge(Target t) { if (t.Rect.Left + (t.Rect.Width/2) < _border) return true; else if (t.Rect.Left + (t.Rect.Width/2) > 1000 - _border) return true; else return false; }
public static bool HasBulletHitTarget(RectangleShape b, Target t) { // check for a bounding box collision return !(b.Position.X > t.Rect.Left + t.Rect.Width || b.Position.X + b.Size.X < t.Rect.Left || b.Position.Y > t.Rect.Top + t.Rect.Height || b.Position.Y + b.Size.Y < t.Rect.Top); }
public void TestTargetCtor() { Target t = new Target (); Assert.AreEqual (60.0f, t.Rect.Height); Assert.AreEqual (60.0f, t.Rect.Width); }