Lots of Stuff That I Can't Break Into Smaller Commits
This commit is contained in:
29
Game/Behaviours/RotatableBehaviour.cs
Normal file
29
Game/Behaviours/RotatableBehaviour.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
using Apos.Shapes;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public class RotatableBehaviour : BehaviourOverride
|
||||
{
|
||||
private KeyboardInputsBehaviour? inputs = null;
|
||||
|
||||
protected override void OnFirstActiveFrame()
|
||||
{
|
||||
if (BehaviourController.TryGetBehaviour(out inputs))
|
||||
inputs.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (inputs is null)
|
||||
return;
|
||||
|
||||
if (inputs.IsPressed(Microsoft.Xna.Framework.Input.Keys.NumPad4))
|
||||
Transform.Rotation += Time.Elapsed.Nanoseconds * 0.0025f;
|
||||
if (inputs.IsPressed(Microsoft.Xna.Framework.Input.Keys.NumPad6))
|
||||
Transform.Rotation -= Time.Elapsed.Nanoseconds * 0.0025f;
|
||||
}
|
||||
}
|
@@ -1,19 +1,17 @@
|
||||
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;
|
||||
using Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public class ShapeAABBBehaviour : BehaviourOverride, IDisplayableShape
|
||||
{
|
||||
private readonly List<Vector2D> vectors = [];
|
||||
private ShapeBehaviour? shapeBehaviour = null;
|
||||
private Shape transformedShape = new([]);
|
||||
private IShapeCollider2D? shapeCollider = null;
|
||||
private readonly static Vector2D screenScale = Vector2D.Down + Vector2D.Right;
|
||||
|
||||
public ShapeAABBBehaviour() { }
|
||||
@@ -26,16 +24,17 @@ public class ShapeAABBBehaviour : BehaviourOverride, IDisplayableShape
|
||||
|
||||
protected override void OnFirstActiveFrame()
|
||||
{
|
||||
BehaviourController.TryGetBehaviour(out shapeBehaviour);
|
||||
BehaviourController.TryGetBehaviour(out shapeCollider);
|
||||
}
|
||||
|
||||
public void Draw(ShapeBatch shapeBatch)
|
||||
{
|
||||
if (shapeBehaviour is null)
|
||||
if (shapeCollider is null)
|
||||
return;
|
||||
|
||||
shapeBehaviour.Shape.TransformShape(Transform, vectors);
|
||||
AABB aabb = AABB.FromVectors(vectors);
|
||||
AABB aabb = AABB.FromVectors(shapeCollider.ShapeWorld);
|
||||
|
||||
shapeBatch.BorderCircle(aabb.Center.ToDisplayVector2(), 7.5f, Color.Beige);
|
||||
|
||||
shapeBatch.DrawRectangle(aabb.Center.Scale(screenScale).Subtract(aabb.SizeHalf).ToVector2(), aabb.Size.ToVector2(), Color.Transparent, Color.Blue);
|
||||
}
|
||||
|
@@ -1,49 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
using Apos.Shapes;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Physics2D.Primitives;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public class ShapeBehaviour : BehaviourOverride, IDisplayableShape
|
||||
public class ShapeBehaviour : Syntriax.Engine.Physics2D.Collider2DShapeBehaviour, IDisplayableShape
|
||||
{
|
||||
private readonly List<Vector2D> vectors = [];
|
||||
private readonly static Vector2D screenScale = Vector2D.Down + Vector2D.Right;
|
||||
public ShapeBehaviour(Shape Shape) { this.ShapeLocal = Shape; }
|
||||
public ShapeBehaviour(Shape Shape, float Thickness) { this.ShapeLocal = Shape; this.Thickness = Thickness; }
|
||||
public ShapeBehaviour(Shape Shape, Color color) { this.ShapeLocal = Shape; Color = color; }
|
||||
public ShapeBehaviour(Shape Shape, Color color, float Thickness) { this.ShapeLocal = Shape; this.Thickness = Thickness; Color = color; }
|
||||
|
||||
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; i++)
|
||||
vectors[i] = vectors[i].Scale(screenScale);
|
||||
Recalculate();
|
||||
int count = ShapeWorld.Vertices.Count;
|
||||
|
||||
for (int i = 0; i < vectors.Count - 1; i++)
|
||||
shapeBatch.DrawLine(vectors[i].ToVector2(), vectors[i + 1].ToVector2(), Thickness, Color, Color);
|
||||
shapeBatch.DrawLine(vectors[0].ToVector2(), vectors[^1].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(transform.TransformVector2D(shape[i]));
|
||||
shapeBatch.BorderCircle(Transform.Position.ToDisplayVector2(), 5f, Color.DarkRed);
|
||||
|
||||
for (int i = 0; i < count - 1; i++)
|
||||
shapeBatch.DrawLine(ShapeWorld[i].ToDisplayVector2(), ShapeWorld[i + 1].ToDisplayVector2(), Thickness, Color, Color);
|
||||
shapeBatch.DrawLine(ShapeWorld[0].ToDisplayVector2(), ShapeWorld[^1].ToDisplayVector2(), Thickness, Color, Color);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user