public void TestPosition() { MoveableGameObject ball = new MoveableGameObject(testForm, 298, 414, 20, 20, true, 20, 8.161641f, 8.161641f, true, Color.Yellow); Rectangle rec = ball.GetPosition(); Rectangle testRec = new Rectangle(298, 414, 20, 20); Assert.AreEqual(rec, testRec); }
public void TestGlueing() { MoveableGameObject ball = new MoveableGameObject(testForm, 298, 414, 20, 20, true, 20, 8.161641f, 8.161641f, true, Color.Yellow); ball.UnGlue(); Assert.AreEqual(false, ball.IsGlued()); ball.Glue(); Assert.AreEqual(true, ball.IsGlued()); }
public void TestPosition() { MoveableGameObject ball = new MoveableGameObject(298, 414, 20, 20, true, 20, 8.161641f, 8.161641f, true, System.Drawing.Brushes.Yellow); Rectangle rec = ball.GetRecPosition(); Rectangle testRec = new Rectangle(298, 414, 20, 20); Assert.AreEqual(rec, testRec); }
public void TestGlueing() { MoveableGameObject ball = new MoveableGameObject(298, 414, 20, 20, true, 20, 8.161641f, 8.161641f, true, System.Drawing.Brushes.Yellow); ball.UnGlue(); Assert.AreEqual(false, ball.GetBlnIsGlued()); ball.Glue(); Assert.AreEqual(true, ball.GetBlnIsGlued()); }
public void CollisionCheck(MoveableGameObject objectToCheck, Vector2 originalPosition, Vector2 destination, Rectangle boundingRectangle) { Vector2 movementToTry = destination - originalPosition; Vector2 furthestFreePosition = originalPosition; int movementStepCount = (int)(movementToTry.Length() * 2) + 1; Vector2 oneStep = movementToTry / movementStepCount; for (int i = 1; i <= movementStepCount; i++) { Vector2 positionToTry = originalPosition + oneStep * i; Rectangle testBoundary = CreateCollisionTestRectangle(positionToTry, boundingRectangle.Width, boundingRectangle.Height); GameObject objectOverlapping = RectangleOverlapping(testBoundary); if (objectOverlapping == null) { furthestFreePosition = positionToTry; } else if (objectOverlapping._tag.Equals("Obstacle")) { objectToCheck._position = furthestFreePosition; Rectangle collisionTestX = CreateCollisionTestRectangle(new Vector2(objectToCheck._position.X - 1, objectToCheck._position.Y), boundingRectangle.Width + 2, boundingRectangle.Height); Rectangle collisionTestY = CreateCollisionTestRectangle(new Vector2(objectToCheck._position.X, objectToCheck._position.Y - 1), boundingRectangle.Width, boundingRectangle.Height + 2); //bounce! if (RectangleOverlapping(collisionTestX) != null) { objectToCheck._velocity.X *= -1 * _frog._bounce; objectToCheck._velocity.Y *= _frog._bounce; } if (RectangleOverlapping(collisionTestY) != null) { objectToCheck._velocity.Y *= -1 * _frog._bounce; objectToCheck._velocity.X *= _frog._bounce; } objectToCheck.AddVelocity(); break; } else if (objectOverlapping._tag.Equals("Hazard")) { ResetFrog(); } else if (_goal != null && objectOverlapping._tag.Equals("Goal")) { if (_frog._velocity.Length() <= 0f) { GameManager._instance._currentState = GameManager.GameStates.WON; } } } }
public void TestChangePosition() { MoveableGameObject ball = new MoveableGameObject(testForm, 298, 414, 20, 20, true, 20, 8.161641f, 8.161641f, true, Color.Yellow); Rectangle testRecOne = new Rectangle(100, 100, 20, 20); ball.ChangePosition(100, 100); Assert.AreEqual(ball.GetPosition(), testRecOne); ball.ChangePosition(200); Rectangle testRecTwo = new Rectangle(200, 100, 20, 20); Assert.AreEqual(ball.GetPosition(), testRecTwo); }
public void TestChangePosition() { MoveableGameObject ball = new MoveableGameObject(298, 414, 20, 20, true, 20, 8.161641f, 8.161641f, true, System.Drawing.Brushes.Yellow); Rectangle testRecOne = new Rectangle(100, 100, 20, 20); ball.ChangePosition(100, 100); Assert.AreEqual(ball.GetRecPosition(), testRecOne); ball.ChangePosition(200); Rectangle testRecTwo = new Rectangle(200, 100, 20, 20); Assert.AreEqual(ball.GetRecPosition(), testRecTwo); }