/// <summary> /// Creates a new meteor entity. /// </summary> /// <param name="type">The type of the new meteor</param> /// <param name="position">The position of the new meteor</param> /// <param name="direction">The direction of the new meteor</param> /// <param name="linearVelocity">The linear velocity of the new meteor</param> /// <param name="rotationVelocity">The rotation velocity of the new meteor</param> /// /// <returns>The new meteor entity.</returns> public Meteor CreateMeteor(MeteorType type, Vector2 position, Vector2 direction, float linearVelocity, float rotationVelocity, bool inject) { Meteor newMeteor = null; switch (type) { case MeteorType.TINY: newMeteor = new TinyMeteor(position, direction, linearVelocity, rotationVelocity); break; case MeteorType.SMALL: newMeteor = new SmallMeteor(position, direction, linearVelocity, rotationVelocity); break; case MeteorType.MEDIUM: newMeteor = new MediumMeteor(position, direction, linearVelocity, rotationVelocity); break; case MeteorType.BIG: newMeteor = new BigMeteor(position, direction, linearVelocity, rotationVelocity); break; } if (inject) { _entityManager.AddEntity(newMeteor); } return(newMeteor); }
/// <summary> /// Splits a meteor entity into 2 smaller meteors entities. /// </summary> /// <param name="meteor">The meteor that has to be split.</param> /// <param name="inject">Whether the smaller meteors should be injected into the entity manager.</param> public List <Meteor> SplitMeteor(Meteor meteor, bool inject) { if (meteor is TinyMeteor) { throw new InvalidOperationException("Can't split a meteor of type TinyMeteor"); } List <Meteor> newMeteors = new List <Meteor>(); float currentDirection = VectorHelper.VectorToAngle(meteor.Direction); Vector2 newDirection = Vector2.Zero; for (int i = 0; i < 2; i++) { if (i == 0) { newDirection = VectorHelper.AngleToVector(currentDirection + (float)(Math.PI / 2)); } else { newDirection = VectorHelper.AngleToVector(currentDirection - (float)(Math.PI / 2)); } if (meteor is SmallMeteor) { newMeteors.Add(CreateMeteor(MeteorType.TINY, meteor.Position, newDirection, inject)); } if (meteor is MediumMeteor) { newMeteors.Add(CreateMeteor(MeteorType.SMALL, meteor.Position, newDirection, inject)); } if (meteor is BigMeteor) { newMeteors.Add(CreateMeteor(MeteorType.MEDIUM, meteor.Position, newDirection, inject)); } } return(newMeteors); }