55 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System.Collections.Generic;
 | 
						|
 | 
						|
using Microsoft.Xna.Framework;
 | 
						|
 | 
						|
using Apos.Shapes;
 | 
						|
 | 
						|
using Engine.Physics2D;
 | 
						|
 | 
						|
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<Vector2D> vectors = [];
 | 
						|
 | 
						|
    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 - 1; i++)
 | 
						|
            shapeBatch.DrawLine(vectors[i].Scale(Vector2D.Down + Vector2D.Right).ToVector2(), vectors[i + 1].Scale(Vector2D.Down + Vector2D.Right).ToVector2(), Thickness, Color, Color);
 | 
						|
        shapeBatch.DrawLine(vectors[0].Scale(Vector2D.Down + Vector2D.Right).ToVector2(), vectors[^1].Scale(Vector2D.Down + Vector2D.Right).ToVector2(), Thickness, Color, Color);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
public static class ShapeTransform
 | 
						|
{
 | 
						|
    public static void TransformShape(this Shape shape, ITransform transform, List<Vector2D> vectors)
 | 
						|
    {
 | 
						|
        vectors.Clear();
 | 
						|
 | 
						|
        int count = shape.Vertices.Count;
 | 
						|
        for (int i = 0; i < count; i++)
 | 
						|
            vectors.Add
 | 
						|
            (
 | 
						|
                shape[i]
 | 
						|
                    .Scale(transform.Scale)
 | 
						|
                    .Rotate(transform.Rotation * Physics2D.DegreeToRadian)
 | 
						|
                    .Add(transform.Position)
 | 
						|
            );
 | 
						|
    }
 | 
						|
}
 |