Engine-Pong/Game/Behaviours/ShapeAABBBehaviour.cs

48 lines
1.5 KiB
C#

using Microsoft.Xna.Framework;
using Apos.Shapes;
using Syntriax.Engine.Core;
using Syntriax.Engine.Input;
using Syntriax.Engine.Physics2D.Abstract;
using Syntriax.Engine.Physics2D.Primitives;
namespace Pong.Behaviours;
public class ShapeAABBBehaviour : BehaviourOverride, IDisplayableShape
{
private IShapeCollider2D? shapeCollider = null;
public ShapeAABBBehaviour() { }
public ShapeAABBBehaviour(float Thickness) { this.Thickness = Thickness; }
public ShapeAABBBehaviour(Color color) { Color = color; }
public ShapeAABBBehaviour(Color color, float Thickness) { this.Thickness = Thickness; Color = color; }
public Color Color { get; set; } = Color.White;
public float Thickness { get; set; } = .5f;
public bool display = true;
protected override void OnFirstActiveFrame()
{
BehaviourController.TryGetBehaviour(out shapeCollider);
if (BehaviourController.TryGetBehaviour(out IButtonInputs<Microsoft.Xna.Framework.Input.Keys>? keys))
keys.RegisterOnPress(Microsoft.Xna.Framework.Input.Keys.D, (_1, _2) => display = !display);
}
public void Draw(ShapeBatch shapeBatch)
{
if (!display)
return;
if (shapeCollider is null)
return;
AABB aabb = AABB.FromVectors(shapeCollider.ShapeWorld);
shapeBatch.BorderCircle(aabb.Center.ToDisplayVector2(), 7.5f, Color.Beige);
shapeBatch.DrawRectangle(aabb.Center.ApplyDisplayScale().Subtract(aabb.SizeHalf).ToVector2(), aabb.Size.ToVector2(), Color.Transparent, Color.Blue);
}
}