feat: Basic Pong Setting
This commit is contained in:
@@ -18,6 +18,8 @@ public class CircleBehaviour : Syntriax.Engine.Physics2D.Collider2DCircleBehavio
|
||||
|
||||
public void Draw(ShapeBatch shapeBatch)
|
||||
{
|
||||
Recalculate();
|
||||
|
||||
shapeBatch.BorderCircle(CircleWorld.Center.ToDisplayVector2(), CircleWorld.Radius, Color);
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Input;
|
||||
using Syntriax.Engine.Physics2D;
|
||||
using Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
@@ -11,12 +12,24 @@ public class MovementBallBehaviour(Vector2D StartDirection, float Speed) : Behav
|
||||
public Vector2D StartDirection { get; private set; } = Vector2D.Normalize(StartDirection);
|
||||
public float Speed { get; set; } = Speed;
|
||||
|
||||
private IRigidBody2D rigidBody = null!;
|
||||
|
||||
protected override void OnFirstActiveFrame()
|
||||
{
|
||||
if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? rigidBody))
|
||||
throw new Exception($"Where's my {nameof(IRigidBody2D)}????");
|
||||
if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? foundRigidBody))
|
||||
throw new Exception($"{nameof(IRigidBody2D)} is missing on {GameObject.Name}.");
|
||||
if (!BehaviourController.TryGetBehaviour(out ICollider2D? foundCollider))
|
||||
throw new Exception($"{nameof(ICollider2D)} is missing on {GameObject.Name}.");
|
||||
|
||||
rigidBody.Velocity = StartDirection * Speed;
|
||||
foundRigidBody.Velocity = StartDirection * Speed;
|
||||
foundCollider.OnCollisionDetected += OnCollisionDetected;
|
||||
|
||||
rigidBody = foundRigidBody;
|
||||
}
|
||||
|
||||
private void OnCollisionDetected(ICollider2D collider2D, CollisionDetectionInformation information)
|
||||
{
|
||||
rigidBody.Velocity = rigidBody.Velocity.Reflect(information.Normal);
|
||||
}
|
||||
|
||||
// protected override void OnUpdate(GameTime time)
|
||||
|
@@ -35,9 +35,7 @@ public class MovementBoxBehaviour(Keys Up, Keys Down, float High, float Low, flo
|
||||
protected override void OnFirstActiveFrame()
|
||||
{
|
||||
if (!BehaviourController.TryGetBehaviour<IButtonInputs<Keys>>(out var behaviourResult))
|
||||
throw new Exception($"{nameof(IButtonInputs<Keys>)} is missing on ${GameObject.Name}.");
|
||||
|
||||
inputs = behaviourResult;
|
||||
inputs = behaviourResult ?? BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
||||
|
||||
inputs.RegisterOnPress(Up, OnUpPressed);
|
||||
inputs.RegisterOnRelease(Up, OnUpReleased);
|
||||
|
@@ -8,16 +8,18 @@ namespace Pong.Behaviours;
|
||||
|
||||
public class ShapeBehaviour : Syntriax.Engine.Physics2D.Collider2DShapeBehaviour, IDisplayableShape
|
||||
{
|
||||
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) : 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;
|
||||
|
||||
public void Draw(ShapeBatch shapeBatch)
|
||||
{
|
||||
Recalculate();
|
||||
|
||||
int count = ShapeWorld.Vertices.Count;
|
||||
|
||||
shapeBatch.BorderCircle(Transform.Position.ToDisplayVector2(), 5f, Color.DarkRed);
|
||||
|
Reference in New Issue
Block a user