2024-01-24 18:40:12 +03:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
|
|
|
using Apos.Shapes;
|
|
|
|
|
|
|
|
using Syntriax.Engine.Core;
|
2024-01-31 12:32:16 +03:00
|
|
|
using Syntriax.Engine.Core.Abstract;
|
2024-01-26 19:21:26 +03:00
|
|
|
using Syntriax.Engine.Input;
|
2024-01-24 19:25:31 +03:00
|
|
|
using Syntriax.Engine.Physics2D.Abstract;
|
2024-01-26 19:21:26 +03:00
|
|
|
using Syntriax.Engine.Physics2D.Primitives;
|
2024-01-24 18:40:12 +03:00
|
|
|
|
|
|
|
namespace Pong.Behaviours;
|
|
|
|
|
|
|
|
public class ShapeAABBBehaviour : BehaviourOverride, IDisplayableShape
|
|
|
|
{
|
2024-01-24 19:25:31 +03:00
|
|
|
private IShapeCollider2D? shapeCollider = null;
|
2024-01-24 18:40:12 +03:00
|
|
|
|
|
|
|
public Color Color { get; set; } = Color.White;
|
|
|
|
public float Thickness { get; set; } = .5f;
|
2024-01-26 19:21:26 +03:00
|
|
|
public bool display = true;
|
2024-01-24 18:40:12 +03:00
|
|
|
|
|
|
|
protected override void OnFirstActiveFrame()
|
|
|
|
{
|
2024-01-24 19:25:31 +03:00
|
|
|
BehaviourController.TryGetBehaviour(out shapeCollider);
|
2024-01-26 19:21:26 +03:00
|
|
|
|
|
|
|
if (BehaviourController.TryGetBehaviour(out IButtonInputs<Microsoft.Xna.Framework.Input.Keys>? keys))
|
|
|
|
keys.RegisterOnPress(Microsoft.Xna.Framework.Input.Keys.D, (_1, _2) => display = !display);
|
2024-01-24 18:40:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Draw(ShapeBatch shapeBatch)
|
|
|
|
{
|
2024-01-26 19:21:26 +03:00
|
|
|
if (!display)
|
|
|
|
return;
|
|
|
|
|
2024-01-24 19:25:31 +03:00
|
|
|
if (shapeCollider is null)
|
2024-01-24 18:40:12 +03:00
|
|
|
return;
|
|
|
|
|
2024-01-24 19:25:31 +03:00
|
|
|
AABB aabb = AABB.FromVectors(shapeCollider.ShapeWorld);
|
|
|
|
|
|
|
|
shapeBatch.BorderCircle(aabb.Center.ToDisplayVector2(), 7.5f, Color.Beige);
|
2024-01-24 18:40:12 +03:00
|
|
|
|
2024-01-25 12:12:53 +03:00
|
|
|
shapeBatch.DrawRectangle(aabb.Center.ApplyDisplayScale().Subtract(aabb.SizeHalf).ToVector2(), aabb.Size.ToVector2(), Color.Transparent, Color.Blue);
|
2024-01-24 18:40:12 +03:00
|
|
|
}
|
2024-01-31 12:51:23 +03:00
|
|
|
|
|
|
|
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; }
|
2024-01-24 18:40:12 +03:00
|
|
|
}
|