public void TestChangeVectorDirection() { double xTo1 = 1.0; double yTo1 = 1.0; double xTo2 = 0.0; double yTo2 = 1.0; double xTo3 = 1.0; double yTo3 = 0.0; double xFrom = 0.0; double yFrom = 0.0; VectorMovement testMovement = new VectorMovement(0.0, 1.0); testMovement.SetDirection(xTo1, yTo1, xFrom, yFrom); Assert.AreEqual(45.0, testMovement.Direction); testMovement.SetDirection(xTo2, yTo2, xFrom, yFrom); Assert.AreEqual(90.0, testMovement.Direction); testMovement.SetDirection(xTo3, yTo3, xFrom, yFrom); Assert.AreEqual(0.0, testMovement.Direction); }
/// <summary> /// ProcessMovement, overide method, determines item movement. /// </summary> public override void ProcessMovement() { if (_itemType == ItemType.Star) { _vectorMovement.Step(); _vectorMovement.SetDirection(GameObjects.Player.X, GameObjects.Player.Y, X, Y); X += _vectorMovement.DeltaX; Y += _vectorMovement.DeltaY; foreach (HitBox hitBox in HitBoxes) { hitBox.X += _vectorMovement.DeltaX; hitBox.Y += _vectorMovement.DeltaY; } } else { _gravMovement.Step(); X += _gravMovement.DeltaX; Y += _gravMovement.DeltaY; foreach (HitBox hitBox in HitBoxes) { hitBox.X += _gravMovement.DeltaX; hitBox.Y += _gravMovement.DeltaY; } } }
/// <summary> /// ProcessMovement Method, steps items through their movement patterns /// </summary> public override void ProcessMovement() { switch (_flag) { case true: _flagMovement.Step(); _flagMovement.SetDirection(GameObjects.Player.Position, this.Position); X += _flagMovement.DeltaX; Y += _flagMovement.DeltaY; foreach (Bounding hitBox in Hitboxes) { hitBox.Offset(_flagMovement.Delta); } break; case false: _movement.Step(); X += _movement.DeltaX; Y += _movement.DeltaY; foreach (Bounding hitBox in Hitboxes) { hitBox.Offset(_movement.Delta); } break; } }