feat: Apo.Shapes Added
This commit is contained in:
8
Game/Behaviours/IDisplayableShape.cs
Normal file
8
Game/Behaviours/IDisplayableShape.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Apos.Shapes;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public interface IDisplayableShape
|
||||
{
|
||||
void Draw(ShapeBatch shapeBatch);
|
||||
}
|
54
Game/Behaviours/ShapeBehaviour.cs
Normal file
54
Game/Behaviours/ShapeBehaviour.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user