using System.Collections.Generic; using Microsoft.Xna.Framework; using Apos.Shapes; using Syntriax.Engine.Core; using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Physics2D.Primitives; namespace Pong.Behaviours; public class ShapeBehaviour : BehaviourOverride, IDisplayableShape { private readonly List vectors = []; private readonly static Vector2D screenScale = Vector2D.Down + Vector2D.Right; public ShapeBehaviour(Shape Shape) { this.Shape = Shape; } public ShapeBehaviour(Shape Shape, float Thickness) { this.Shape = Shape; this.Thickness = Thickness; } public ShapeBehaviour(Shape Shape, Color color) { this.Shape = Shape; Color = color; } public ShapeBehaviour(Shape Shape, Color color, float Thickness) { this.Shape = Shape; this.Thickness = Thickness; Color = color; } public Shape Shape { get; } = default!; public Color Color { get; set; } = Color.White; public float Thickness { get; set; } = .5f; public void Draw(ShapeBatch shapeBatch) { Shape.TransformShape(GameObject.Transform, vectors); for (int i = 0; i < vectors.Count; i++) vectors[i] = vectors[i].Scale(screenScale); for (int i = 0; i < vectors.Count - 1; i++) shapeBatch.DrawLine(vectors[i].ToVector2(), vectors[i + 1].ToVector2(), Thickness, Color, Color); shapeBatch.DrawLine(vectors[0].ToVector2(), vectors[^1].ToVector2(), Thickness, Color, Color); } } public static class ShapeTransform { public static void TransformShape(this Shape shape, ITransform transform, List vectors) { vectors.Clear(); int count = shape.Vertices.Count; for (int i = 0; i < count; i++) vectors.Add(transform.TransformVector2D(shape[i])); } }