refactor: MovementBallBehaviour

This commit is contained in:
Syntriax 2024-01-28 15:44:20 +03:00
parent ca92b12833
commit 7ad2cc5912
1 changed files with 11 additions and 35 deletions

View File

@ -1,19 +1,24 @@
using System; using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Syntriax.Engine.Core; using Syntriax.Engine.Core;
using Syntriax.Engine.Input;
using Syntriax.Engine.Physics2D; using Syntriax.Engine.Physics2D;
using Syntriax.Engine.Physics2D.Abstract; using Syntriax.Engine.Physics2D.Abstract;
namespace Pong.Behaviours; namespace Pong.Behaviours;
public class MovementBallBehaviour(Vector2D StartDirection, float Speed) : BehaviourOverride public class MovementBallBehaviour : BehaviourOverride
{ {
public Vector2D StartDirection { get; private set; } = Vector2D.Normalize(StartDirection); public Vector2D StartDirection { get; private set; } = Vector2D.Zero;
public float Speed { get; set; } = Speed; public float Speed { get; set; } = 500f;
private IRigidBody2D rigidBody = null!; private IRigidBody2D rigidBody = null!;
public MovementBallBehaviour(Vector2D startDirection, float speed)
{
StartDirection = Vector2D.Normalize(startDirection);
Speed = speed;
}
public MovementBallBehaviour() { }
protected override void OnFirstActiveFrame() protected override void OnFirstActiveFrame()
{ {
if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? foundRigidBody)) if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? foundRigidBody))
@ -31,33 +36,4 @@ public class MovementBallBehaviour(Vector2D StartDirection, float Speed) : Behav
{ {
rigidBody.Velocity = rigidBody.Velocity.Reflect(information.Normal); rigidBody.Velocity = rigidBody.Velocity.Reflect(information.Normal);
} }
// protected override void OnUpdate(GameTime time)
// {
// GameObject.Transform.Position += StartDirection * (time.ElapsedGameTime.Nanoseconds * .001f) * Speed;
// float absY = MathF.Abs(GameObject.Transform.Position.Y);
// float differenceY = absY - PlayAreaBehaviour.PlayArea.Y * 0.5f;
// if (differenceY > 0f)
// {
// if (GameObject.Transform.Position.Y > 0f)
// GameObject.Transform.Position -= Vector2.UnitY * differenceY * 2f;
// else
// GameObject.Transform.Position += Vector2.UnitY * differenceY * 2f;
// StartDirection = new(StartDirection.X, -StartDirection.Y);
// }
// float absX = MathF.Abs(GameObject.Transform.Position.X);
// float differenceX = absX - PlayAreaBehaviour.PlayArea.X * 0.5f;
// if (differenceX > 0f)
// {
// if (GameObject.Transform.Position.X > 0f)
// GameObject.Transform.Position -= Vector2.UnitX * differenceX * 2f;
// else
// GameObject.Transform.Position += Vector2.UnitX * differenceX * 2f;
// StartDirection = new(-StartDirection.X, StartDirection.Y);
// }
// }
} }