chore: added a drawable circle script to add a visual flare to the trail by making it look disconnected from the ball
This commit is contained in:
34
Shared/Behaviours/DrawableCircle.cs
Normal file
34
Shared/Behaviours/DrawableCircle.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Engine.Core;
|
||||
using Engine.Systems.Graphics;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public class DrawableCircle : Behaviour2D, IDrawableTriangle, IPreDraw
|
||||
{
|
||||
private const float CIRCLE_SEGMENT_COUNT = 32f;
|
||||
|
||||
private readonly Circle circle = new();
|
||||
private Circle worldCircle = new();
|
||||
|
||||
public ColorRGBA Color { get; set; } = new ColorRGBA(255, 255, 255);
|
||||
|
||||
public void PreDraw() => UpdateWorldCircle();
|
||||
|
||||
public void Draw(ITriangleBatch triangleBatch)
|
||||
{
|
||||
for (int i = 0; i < CIRCLE_SEGMENT_COUNT; i++)
|
||||
{
|
||||
float iPi1 = i / CIRCLE_SEGMENT_COUNT * 2f * Math.Pi;
|
||||
float iPi2 = (i + 1f).Mod(CIRCLE_SEGMENT_COUNT) / CIRCLE_SEGMENT_COUNT * 2f * Math.Pi;
|
||||
|
||||
Vector2D firstVertex = new Vector2D(Math.Sin(iPi1), Math.Cos(iPi1)) * worldCircle.Radius;
|
||||
Vector2D secondVertex = new Vector2D(Math.Sin(iPi2), Math.Cos(iPi2)) * worldCircle.Radius;
|
||||
triangleBatch.Draw(new(worldCircle.Center, worldCircle.Center + firstVertex, worldCircle.Center + secondVertex), Color);
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateWorldCircle() => worldCircle = circle.Transform(Transform);
|
||||
|
||||
public DrawableCircle(Circle circle) { this.circle = circle; }
|
||||
public DrawableCircle(Circle circle, ColorRGBA color) { this.circle = circle; Color = color; }
|
||||
}
|
||||
@@ -81,6 +81,7 @@ public static class PongUniverse
|
||||
.BehaviourController.AddBehaviour<Transform2D>().SetTransform(position: new Vector2D(0, 0f), scale: new Vector2D(10f, 10f))
|
||||
.BehaviourController.AddBehaviour<DrawableColliderCircle>(new Circle(Vector2D.Zero, 1f))
|
||||
.BehaviourController.AddBehaviour<Ball>()
|
||||
.BehaviourController.AddBehaviour<DrawableCircle>(new Circle(Vector2D.Zero, 2.5f), new ColorRGBA(35, 20, 35))
|
||||
.BehaviourController.AddBehaviour<BallTrail>()
|
||||
.BehaviourController.AddBehaviour<RigidBody2D>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user