public static void StartFalling(this Entity2D entity, Vector2D velocity, Vector2D gravity) { AddSimplePhysicsDataIfNeeded(entity); entity.Get <SimplePhysics.Data>().Velocity = velocity; entity.Get <SimplePhysics.Data>().Gravity = gravity; entity.Start <SimplePhysics.Move>(); }
private static void AddSimplePhysicsDataIfNeeded(Entity2D entity) { if (!entity.Contains <SimplePhysics.Data>()) { entity.Add(new SimplePhysics.Data()); } }
private static void UpdateDuration(Entity2D entity, Data physics) { physics.Elapsed += Time.Delta; if (physics.Duration > 0.0f && physics.Elapsed >= physics.Duration) { entity.Dispose(); } }
public static void StartBouncingOffScreenEdges(this Entity2D entity, Vector2D velocity, Action bounced) { AddSimplePhysicsDataIfNeeded(entity); entity.Get <SimplePhysics.Data>().Velocity = velocity; entity.Get <SimplePhysics.Data>().Bounced = bounced; entity.Start <SimplePhysics.Move>(); entity.Start <SimplePhysics.BounceIfAtScreenEdge>(); }
private static void UpdatePhysics(Entity2D entity, Data physics) { physics.Velocity += physics.Gravity * Time.Delta; entity.Center += physics.Velocity * Time.Delta; physics.Elapsed += Time.Delta; if (physics.Duration > 0.0f && physics.Elapsed >= physics.Duration) { entity.IsActive = false; } }
public static void StartRotating(this Entity2D entity, float rotationSpeed) { AddSimplePhysicsDataIfNeeded(entity); entity.Get <SimplePhysics.Data>().RotationSpeed = rotationSpeed; entity.Start <SimplePhysics.Rotate>(); }