using System.Numerics; using Encompass; using PongFE.Components; using PongFE.Messages; namespace PongFE.Engines { [Reads( typeof(BounceResponseComponent), typeof(VelocityComponent) )] [Receives(typeof(BounceMessage))] [Sends(typeof(UpdateVelocityMessage))] public class BounceEngine : Engine { public override void Update(double dt) { foreach (ref readonly var message in ReadMessages()) { if (HasComponent(message.Entity) && HasComponent(message.Entity)) { System.Console.WriteLine("hello bounce!"); ref readonly var velocityComponent = ref GetComponent(message.Entity); Vector2 newVelocity; if (message.HitOrientation == HitOrientation.Horizontal) { newVelocity = new Vector2(-velocityComponent.Velocity.X, velocityComponent.Velocity.Y); } else { newVelocity = new Vector2(velocityComponent.Velocity.X, -velocityComponent.Velocity.Y); } SendMessage(new UpdateVelocityMessage(message.Entity, newVelocity)); } } } } }