private bool CheckAgeAndRespawn(Entity e)
        {
            RespawnComponent respawn = e.GetComponent <RespawnComponent>();
            LifeComponent    life    = e.GetComponent <LifeComponent>();

            if (respawn != null && life != null)
            {
                if (respawn.TimeSinceRespawn >= respawn.Timeout)
                {
                    respawn.TimeSinceRespawn = 0;
                    e.GetComponent <IntentComponent>().IntentManager.Initialize();
                    TransformComponent position = e.GetComponent <TransformComponent>();
                    MotionComponent    motion   = e.GetComponent <MotionComponent>();
                    position.Position      = respawn.Location;
                    position.Rotation      = 0;
                    motion.Velocity        = Vector2.Zero;
                    motion.AngularVelocity = 0;
                    life.Lives--;
                    e.AddComponent(new ShieldComponent());
                    this.signalManager.AddSignal(SignalType.LifeLost, e.EntityId);
                    if (life.Lives < 0)
                    {
                        e.Destroy();
                        this.signalManager.AddSignal(SignalType.EntityDestroyed, e.EntityId);
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public override void Update(float elapsedSeconds)
        {
            foreach (Entity e in this.actives.Values)
            {
                RespawnComponent respawn = e.GetComponent <RespawnComponent>();
                System.Diagnostics.Debug.Assert(respawn != null, "RespawnComponent not found");

                if (respawn.TimeSinceRespawn >= respawn.Timeout && e.ContainsComponents(EntityWorld.ComponentManager.GetComponentId <ShieldComponent>()))
                {
                    e.RemoveComponent <ShieldComponent>();
                }
                else
                {
                    respawn.TimeSinceRespawn += elapsedSeconds;
                }
            }
        }