feat: Ball Speed Up Over Time
This commit is contained in:
parent
0b2158cc7b
commit
ad60412d5f
|
@ -9,6 +9,7 @@ public class MovementBallBehaviour : BehaviourOverride
|
|||
{
|
||||
public Vector2D StartDirection { get; private set; } = Vector2D.Zero;
|
||||
public float Speed { get; set; } = 500f;
|
||||
public float SpeedUpMultiplier { get; set; } = .0125f;
|
||||
|
||||
private IRigidBody2D rigidBody = null!;
|
||||
|
||||
|
@ -32,6 +33,15 @@ public class MovementBallBehaviour : BehaviourOverride
|
|||
rigidBody = foundRigidBody;
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (rigidBody.Velocity.MagnitudeSquared <= 0.01f)
|
||||
return;
|
||||
|
||||
Vector2D speedUp = rigidBody.Velocity.Normalized * (float)Time.Elapsed.TotalMilliseconds;
|
||||
rigidBody.Velocity += speedUp * SpeedUpMultiplier;
|
||||
}
|
||||
|
||||
private void OnCollisionDetected(ICollider2D collider2D, CollisionDetectionInformation information)
|
||||
{
|
||||
rigidBody.Velocity = rigidBody.Velocity.Reflect(information.Normal);
|
||||
|
|
|
@ -39,7 +39,9 @@ public class PongScoreboard(int WinScore) : BehaviourOverride
|
|||
|
||||
private void CheckFinish()
|
||||
{
|
||||
if (ScoreSum == WinScore)
|
||||
int halfwayScore = (int)(WinScore * .5f);
|
||||
|
||||
if (ScoreLeft > halfwayScore || ScoreRight > halfwayScore)
|
||||
OnFinished?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,6 +169,7 @@ public class Game1 : Game
|
|||
pongScoreboard.OnScored += () =>
|
||||
{
|
||||
gameObjectBall.Transform.Position = Vector2D.Zero;
|
||||
rigidBodyBall.Velocity = rigidBodyBall.Velocity.Normalized * movementBallBehaviour.Speed;
|
||||
textBehaviourLeft.Text = pongScoreboard.ScoreLeft.ToString();
|
||||
textBehaviourRight.Text = pongScoreboard.ScoreRight.ToString();
|
||||
};
|
||||
|
@ -182,7 +183,7 @@ public class Game1 : Game
|
|||
{
|
||||
gameObjectBall.StateEnable.Enabled = true;
|
||||
rigidBodyBall.BehaviourController.GameObject.Transform.Position = Vector2D.Zero;
|
||||
rigidBodyBall.Velocity = Vector2D.One * movementBallBehaviour.Speed;
|
||||
rigidBodyBall.Velocity = Vector2D.One.Normalized * movementBallBehaviour.Speed;
|
||||
textBehaviourLeft.Text = pongScoreboard.ScoreLeft.ToString();
|
||||
textBehaviourRight.Text = pongScoreboard.ScoreRight.ToString();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue