47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using Encompass;
|
|
using PongFE.Components;
|
|
using PongFE.Messages;
|
|
|
|
namespace PongFE.Engines
|
|
{
|
|
[Reads(
|
|
typeof(SpawnBallAfterDestroyComponent),
|
|
typeof(IncreaseScoreAfterDestroyComponent)
|
|
)]
|
|
[Receives(typeof(DestroyMessage))]
|
|
[Sends(
|
|
typeof(BallSpawnMessage),
|
|
typeof(ScoreMessage)
|
|
)]
|
|
public class DestroyEngine : Engine
|
|
{
|
|
public override void Update(double dt)
|
|
{
|
|
foreach (ref readonly var message in ReadMessages<DestroyMessage>())
|
|
{
|
|
if (HasComponent<SpawnBallAfterDestroyComponent>(message.Entity))
|
|
{
|
|
ref readonly var respawnComponent = ref GetComponent<SpawnBallAfterDestroyComponent>(message.Entity);
|
|
|
|
SendMessage(
|
|
new BallSpawnMessage(
|
|
new MoonTools.Structs.Position2D(640, 360),
|
|
300,
|
|
16,
|
|
16
|
|
),
|
|
respawnComponent.Seconds
|
|
);
|
|
}
|
|
|
|
if (HasComponent<IncreaseScoreAfterDestroyComponent>(message.Entity))
|
|
{
|
|
SendMessage(new ScoreMessage(message.DestroyedBy));
|
|
}
|
|
|
|
Destroy(message.Entity);
|
|
}
|
|
}
|
|
}
|
|
}
|