feat: game start countdown added
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user