feat: game start countdown added

This commit is contained in:
2025-07-27 18:55:32 +03:00
parent 863c3a8d7a
commit a781d92996
4 changed files with 140 additions and 27 deletions

View File

@@ -1,11 +1,15 @@
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Syntriax.Engine.Core;
using Syntriax.Engine.Integration.MonoGame;
using Syntriax.Engine.Network;
using Syntriax.Engine.Physics2D;
using Syntriax.Engine.Systems.Tween;
namespace Pong.Behaviours;
public class Ball : Behaviour2D, IFirstFrameUpdate, IPhysicsUpdate, INetworkEntity,
public class Ball : Behaviour2D, IFirstFrameUpdate, ILoadContent, IPhysicsUpdate, INetworkEntity,
IPacketListenerClient<Ball.BallUpdatePacket>,
IPacketListenerClient<Ball.BallResetPacket>
{
@@ -19,6 +23,8 @@ public class Ball : Behaviour2D, IFirstFrameUpdate, IPhysicsUpdate, INetworkEnti
private INetworkCommunicatorServer? networkServer = null;
private ITween? networkTween = null;
private SoundEffect? bounceSoundEffect = null;
public void FirstActiveFrame()
{
BehaviourController.GetRequiredBehaviour<ICollider2D>().OnCollisionDetected.AddListener(OnCollisionDetected);
@@ -28,6 +34,11 @@ public class Ball : Behaviour2D, IFirstFrameUpdate, IPhysicsUpdate, INetworkEnti
networkServer = Universe.FindBehaviour<INetworkCommunicatorServer>();
}
public void LoadContent(ContentManager content)
{
bounceSoundEffect = content.Load<SoundEffect>("Audio/Bounce");
}
public void LaunchBall(Vector2D launchDirection)
{
ResetBall();
@@ -74,6 +85,9 @@ public class Ball : Behaviour2D, IFirstFrameUpdate, IPhysicsUpdate, INetworkEnti
else
Transform.Position = packet.Position;
if (RigidBody.Velocity.MagnitudeSquared >= .01f)
bounceSoundEffect?.Play();
RigidBody.Velocity = packet.Velocity;
physicsEngine2D.StepIndividual(RigidBody, sender.Ping);
}