Added support code, client instantiation and deletion
This commit is contained in:
parent
aa3cf04cc6
commit
fd917022cf
5 changed files with 59 additions and 18 deletions
|
@ -367,5 +367,15 @@ namespace ZoFo.GameCore
|
|||
players.Remove(entity as Player);
|
||||
}
|
||||
|
||||
public void RegisterClientMadeObject(GameObject gameObject)
|
||||
{
|
||||
|
||||
if (gameObject is Particle) particles.Add(gameObject as Particle);
|
||||
else gameObjects.Add(gameObject);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -111,11 +111,11 @@ namespace ZoFo.GameCore.GameObjects
|
|||
public override void DeathEnd()
|
||||
{
|
||||
|
||||
Instantiate(new Particle(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
|
||||
Instantiate(new Particle(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
|
||||
Instantiate(new Particle(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
|
||||
Instantiate(new Particle(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
|
||||
Instantiate(new Particle(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
|
||||
Instantiate_OnClient(new Explosion(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
|
||||
Instantiate_OnClient(new Explosion(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
|
||||
Instantiate_OnClient(new Explosion(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
|
||||
Instantiate_OnClient(new Explosion(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
|
||||
Instantiate_OnClient(new Explosion(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
|
||||
|
||||
base.DeathEnd();
|
||||
}
|
||||
|
|
|
@ -270,7 +270,7 @@ public class Player : LivingEntity
|
|||
{
|
||||
for (int i = 3; i <= 3; i++)
|
||||
{
|
||||
Instantiate(new Particle(
|
||||
Instantiate(new Explosion(
|
||||
((position - graphicsComponent.ObjectDrawRectangle.Size.ToVector2() / 2) * (3 - i) / 3f) +
|
||||
((entity.position - graphicsComponent.ObjectDrawRectangle.Size.ToVector2() / 2) * i / 3f) + ExtentionClass.RandomVector() * 3
|
||||
));
|
||||
|
|
|
@ -10,21 +10,25 @@ using ZoFo.GameCore.Graphics;
|
|||
|
||||
namespace ZoFo.GameCore.GameObjects
|
||||
{
|
||||
internal class Particle : GameObject
|
||||
public class Particle : GameObject
|
||||
{
|
||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "explosion_1" }, "explosion_1");
|
||||
|
||||
public Particle(Vector2 position) : base(position)
|
||||
{
|
||||
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0,60,60).SetOrigin(position);
|
||||
AppManager.Instance.SoundManager.StartSound("gun-gunshot-01", Vector2.Zero, Vector2.Zero, 0.5f, (float)(Random.Shared.NextDouble()*2-1));
|
||||
}
|
||||
}
|
||||
public class Explosion : Particle
|
||||
{
|
||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "explosion_1" }, "explosion_1");
|
||||
|
||||
public Explosion(Vector2 position) : base(position)
|
||||
{
|
||||
graphicsComponent.ObjectDrawRectangle = new Rectangle(-30, -30, 60, 60).SetOrigin(position);
|
||||
AppManager.Instance.SoundManager.StartSound("gun-gunshot-01", Vector2.Zero, Vector2.Zero, 0.5f, (float)(Random.Shared.NextDouble() * 2 - 1));
|
||||
(graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += _ => {
|
||||
|
||||
if (AppManager.Instance.client!=null)
|
||||
{
|
||||
AppManager.Instance.client.DeleteObject(this);
|
||||
|
||||
}
|
||||
Delete_OnClient(this);
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -54,6 +54,33 @@ public abstract class GameObject
|
|||
|
||||
#region Client Side
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// вызывается для создания объектов на клиенте,
|
||||
/// соответственно используется по большей часте для создания эффектов
|
||||
/// (например на конец атаки или смерти будут создаваться взирывы, а их бессмысленно передавать каждый раз)
|
||||
/// </summary>
|
||||
/// <param name="gameObject"></param>
|
||||
public void Instantiate_OnClient(GameObject gameObject)
|
||||
{
|
||||
if (AppManager.Instance.client != null)
|
||||
AppManager.Instance.client.RegisterClientMadeObject(gameObject);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Используется для локального удаления объектов на клиенте, например, частицы взрыва удаляются после срабатывания,
|
||||
/// соответственно не надо это очевидное и предсказыемое удаление отправлять с сервераа на клиент
|
||||
/// </summary>
|
||||
/// <param name="gameObject"></param>
|
||||
public void Delete_OnClient(GameObject gameObject)
|
||||
{
|
||||
if (AppManager.Instance.client != null)
|
||||
AppManager.Instance.client.DeleteObject(gameObject);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Texture2D debugTexture;
|
||||
/// <summary>
|
||||
/// Для клиента
|
||||
|
|
Loading…
Add table
Reference in a new issue