refactor: Constructor Placements
This commit is contained in:
parent
e7ee460323
commit
d66b119119
|
@ -15,13 +15,6 @@ public class BallBehaviour : BehaviourOverride
|
|||
private readonly Random random = new();
|
||||
private IRigidBody2D rigidBody = null!;
|
||||
|
||||
public BallBehaviour(Vector2D startDirection, float speed)
|
||||
{
|
||||
StartDirection = Vector2D.Normalize(startDirection);
|
||||
Speed = speed;
|
||||
}
|
||||
public BallBehaviour() { }
|
||||
|
||||
protected override void OnFirstActiveFrame()
|
||||
{
|
||||
if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? foundRigidBody))
|
||||
|
@ -78,4 +71,11 @@ public class BallBehaviour : BehaviourOverride
|
|||
else
|
||||
rigidBody.Velocity = rigidBody.Velocity.Reflect(information.Normal);
|
||||
}
|
||||
|
||||
public BallBehaviour() { }
|
||||
public BallBehaviour(Vector2D startDirection, float speed)
|
||||
{
|
||||
StartDirection = Vector2D.Normalize(startDirection);
|
||||
Speed = speed;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,6 @@ namespace Pong.Behaviours;
|
|||
|
||||
public class CircleBehaviour : Syntriax.Engine.Physics2D.Collider2DCircleBehaviour, IDisplayableShape
|
||||
{
|
||||
public CircleBehaviour(Circle circle) : base(circle) { }
|
||||
public CircleBehaviour(Circle circle, float thickness) : base(circle) { Thickness = thickness; }
|
||||
public CircleBehaviour(Circle circle, Color color) : base(circle) { Color = color; }
|
||||
public CircleBehaviour(Circle circle, Color color, float thickness) : base(circle) { Thickness = thickness; Color = color; }
|
||||
|
||||
public Color Color { get; set; } = Color.White;
|
||||
public float Thickness { get; set; } = .5f;
|
||||
|
||||
|
@ -26,4 +21,9 @@ public class CircleBehaviour : Syntriax.Engine.Physics2D.Collider2DCircleBehavio
|
|||
|
||||
shapeBatch.BorderCircle(CircleWorld.Center.ToDisplayVector2(), CircleWorld.Radius, Color);
|
||||
}
|
||||
|
||||
public CircleBehaviour(Circle circle) : base(circle) { }
|
||||
public CircleBehaviour(Circle circle, float thickness) : base(circle) { Thickness = thickness; }
|
||||
public CircleBehaviour(Circle circle, Color color) : base(circle) { Color = color; }
|
||||
public CircleBehaviour(Circle circle, Color color, float thickness) : base(circle) { Thickness = thickness; Color = color; }
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
|
|||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public class MonoGameCameraBehaviour(GraphicsDeviceManager Graphics) : BehaviourOverride
|
||||
{
|
||||
public System.Action<MonoGameCameraBehaviour>? OnMatrixTransformChanged { get; set; } = null;
|
||||
|
@ -12,9 +13,10 @@ public class MonoGameCameraBehaviour(GraphicsDeviceManager Graphics) : Behaviour
|
|||
private Matrix _matrixTransform = Matrix.Identity;
|
||||
|
||||
private Viewport _viewport = default;
|
||||
public GraphicsDeviceManager Graphics { get; } = Graphics;
|
||||
private float _zoom = 1f;
|
||||
|
||||
public GraphicsDeviceManager Graphics { get; } = Graphics;
|
||||
|
||||
public Matrix MatrixTransform
|
||||
{
|
||||
get => _matrixTransform;
|
||||
|
|
|
@ -5,6 +5,7 @@ using Syntriax.Engine.Physics2D;
|
|||
using Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public class MovementBallBehaviour : BehaviourOverride
|
||||
{
|
||||
public Vector2D StartDirection { get; private set; } = Vector2D.Zero;
|
||||
|
@ -13,13 +14,6 @@ public class MovementBallBehaviour : BehaviourOverride
|
|||
|
||||
private IRigidBody2D rigidBody = null!;
|
||||
|
||||
public MovementBallBehaviour(Vector2D startDirection, float speed)
|
||||
{
|
||||
StartDirection = Vector2D.Normalize(startDirection);
|
||||
Speed = speed;
|
||||
}
|
||||
public MovementBallBehaviour() { }
|
||||
|
||||
protected override void OnFirstActiveFrame()
|
||||
{
|
||||
if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? foundRigidBody))
|
||||
|
@ -44,10 +38,16 @@ public class MovementBallBehaviour : BehaviourOverride
|
|||
|
||||
private void OnCollisionDetected(ICollider2D collider2D, CollisionDetectionInformation information)
|
||||
{
|
||||
// if (information.Left.BehaviourController.GameObject == GameObject)
|
||||
if (Syntriax.Engine.Core.Math.Abs(information.Normal.Dot(Vector2D.Right)) > .25)
|
||||
rigidBody.Velocity = information.Left.Transform.Position.FromTo(information.Right.Transform.Position).Normalized * rigidBody.Velocity.Magnitude;
|
||||
else
|
||||
rigidBody.Velocity = rigidBody.Velocity.Reflect(information.Normal);
|
||||
}
|
||||
|
||||
public MovementBallBehaviour() { }
|
||||
public MovementBallBehaviour(Vector2D startDirection, float speed)
|
||||
{
|
||||
StartDirection = Vector2D.Normalize(startDirection);
|
||||
Speed = speed;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,6 @@ 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;
|
||||
|
@ -45,4 +40,9 @@ public class ShapeAABBBehaviour : BehaviourOverride, IDisplayableShape
|
|||
|
||||
shapeBatch.DrawRectangle(aabb.Center.ApplyDisplayScale().Subtract(aabb.SizeHalf).ToVector2(), aabb.Size.ToVector2(), Color.Transparent, Color.Blue);
|
||||
}
|
||||
|
||||
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; }
|
||||
}
|
||||
|
|
|
@ -9,11 +9,6 @@ namespace Pong.Behaviours;
|
|||
|
||||
public class ShapeBehaviour : Syntriax.Engine.Physics2D.Collider2DShapeBehaviour, IDisplayableShape
|
||||
{
|
||||
public ShapeBehaviour(Shape shape) : base(shape) { }
|
||||
public ShapeBehaviour(Shape shape, float thickness) : base(shape) { Thickness = thickness; }
|
||||
public ShapeBehaviour(Shape shape, Color color) : base(shape) { Color = color; }
|
||||
public ShapeBehaviour(Shape shape, Color color, float thickness) : base(shape) { Thickness = thickness; Color = color; }
|
||||
|
||||
public Color Color { get; set; } = Color.White;
|
||||
public float Thickness { get; set; } = .5f;
|
||||
|
||||
|
@ -30,4 +25,9 @@ public class ShapeBehaviour : Syntriax.Engine.Physics2D.Collider2DShapeBehaviour
|
|||
shapeBatch.DrawLine(ShapeWorld[i].ToDisplayVector2(), ShapeWorld[i + 1].ToDisplayVector2(), Thickness, Color, Color);
|
||||
shapeBatch.DrawLine(ShapeWorld[0].ToDisplayVector2(), ShapeWorld[^1].ToDisplayVector2(), Thickness, Color, Color);
|
||||
}
|
||||
|
||||
public ShapeBehaviour(Shape shape) : base(shape) { }
|
||||
public ShapeBehaviour(Shape shape, float thickness) : base(shape) { Thickness = thickness; }
|
||||
public ShapeBehaviour(Shape shape, Color color) : base(shape) { Color = color; }
|
||||
public ShapeBehaviour(Shape shape, Color color, float thickness) : base(shape) { Thickness = thickness; Color = color; }
|
||||
}
|
||||
|
|
|
@ -8,9 +8,6 @@ namespace Pong.Behaviours;
|
|||
|
||||
public class TextBehaviour : BehaviourOverride, IDisplayableSprite
|
||||
{
|
||||
public TextBehaviour() { }
|
||||
public TextBehaviour(SpriteFont font) => Font = font;
|
||||
|
||||
public SpriteFont? Font { get; set; } = null;
|
||||
public int Size { get; set; } = 16;
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
@ -22,4 +19,7 @@ public class TextBehaviour : BehaviourOverride, IDisplayableSprite
|
|||
|
||||
spriteBatch.DrawString(Font, Text, Transform.Position.ToDisplayVector2(), Color.White, Transform.Rotation, Vector2.One * .5f, Transform.Scale.Magnitude, SpriteEffects.None, 0f);
|
||||
}
|
||||
|
||||
public TextBehaviour() { }
|
||||
public TextBehaviour(SpriteFont font) => Font = font;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,6 @@ public class TextScoreBehaviour : TextBehaviour
|
|||
|
||||
private PongManagerBehaviour? pongManager = null;
|
||||
|
||||
public TextScoreBehaviour(bool IsLeft) => this.IsLeft = IsLeft;
|
||||
public TextScoreBehaviour(bool IsLeft, SpriteFont font) : base(font) => this.IsLeft = IsLeft;
|
||||
|
||||
protected override void OnFirstActiveFrame()
|
||||
{
|
||||
if (!GameObject.GameManager.TryFindBehaviour(out pongManager))
|
||||
|
@ -30,4 +27,7 @@ public class TextScoreBehaviour : TextBehaviour
|
|||
else
|
||||
Text = pongManager.ScoreRight.ToString();
|
||||
}
|
||||
|
||||
public TextScoreBehaviour(bool IsLeft) => this.IsLeft = IsLeft;
|
||||
public TextScoreBehaviour(bool IsLeft, SpriteFont font) : base(font) => this.IsLeft = IsLeft;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
|
|
Loading…
Reference in New Issue