43 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System.Collections.Generic;
 | |
| 
 | |
| using Microsoft.Xna.Framework;
 | |
| 
 | |
| using Apos.Shapes;
 | |
| 
 | |
| using Syntriax.Engine.Core;
 | |
| using Syntriax.Engine.Physics2D.Primitives;
 | |
| using Syntriax.Engine.Core.Abstract;
 | |
| 
 | |
| namespace Pong.Behaviours;
 | |
| 
 | |
| public class ShapeAABBBehaviour : BehaviourOverride, IDisplayableShape
 | |
| {
 | |
|     private readonly List<Vector2D> vectors = [];
 | |
|     private ShapeBehaviour? shapeBehaviour = null;
 | |
|     private readonly static Vector2D screenScale = Vector2D.Down + Vector2D.Right;
 | |
| 
 | |
|     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;
 | |
| 
 | |
|     protected override void OnFirstActiveFrame()
 | |
|     {
 | |
|         BehaviourController.TryGetBehaviour(out shapeBehaviour);
 | |
|     }
 | |
| 
 | |
|     public void Draw(ShapeBatch shapeBatch)
 | |
|     {
 | |
|         if (shapeBehaviour is null)
 | |
|             return;
 | |
| 
 | |
|         shapeBehaviour.Shape.TransformShape(Transform, vectors);
 | |
|         AABB aabb = AABB.FromVectors(vectors);
 | |
| 
 | |
|         shapeBatch.DrawRectangle(aabb.Center.Scale(screenScale).Subtract(aabb.SizeHalf).ToVector2(), aabb.Size.ToVector2(), Color.Transparent, Color.Blue);
 | |
|     }
 | |
| }
 |