Ejemplo n.º 1
0
        private void CollisionDetected(PhysicsComponent Component, PhysicsComponent Other, bool TriggerRemaining)
        {
            if (this.IsDisposed)            // Prevent firing multiple times.
            {
                return;
            }
            if (this.LastTriggered.HasValue && (DateTime.Now - this.LastTriggered.Value) < MinimumTriggerDelay)
            {
                return;                 // Limit to MinimumTriggerDelay since the last event.
            }
            var Classification = Other.Parent.GetComponent <ClassificationComponent>();

            if (_Classification != EntityClassification.Any && (Classification == null || (Classification.Classification & this.Classification) == 0))
            {
                return;
            }
            bool Valid = OnCollision(Other.Parent, Classification == null ? EntityClassification.Unknown : Classification.Classification);

            if (Valid)
            {
                this._LastTriggered = DateTime.Now;
                if (DisposeOnCollision)
                {
                    this.Dispose();
                    if (TriggerRemaining)
                    {
                        // TODO: This should only trigger things not already triggered for this collision.
                        // (Aka, DisposeOnCollision is false and already triggered before this one).
                        foreach (var OtherEvent in Parent.Components.Select(c => c as CollisionEventComponent).Where(c => c != null && c != this).ToArray())
                        {
                            OtherEvent.CollisionDetected(Component, Other, false);
                        }
                        Parent.Dispose();
                    }
                }
            }
        }
Ejemplo n.º 2
0
 void Physics_Collided(PhysicsComponent Component, PhysicsComponent Other)
 {
     CollisionDetected(Component, Other, true);
 }
Ejemplo n.º 3
0
 private void CollisionDetected(PhysicsComponent Component, PhysicsComponent Other, bool TriggerRemaining)
 {
     if(this.IsDisposed) // Prevent firing multiple times.
         return;
     if(this.LastTriggered.HasValue && (DateTime.Now - this.LastTriggered.Value) < MinimumTriggerDelay)
         return; // Limit to MinimumTriggerDelay since the last event.
     var Classification = Other.Parent.GetComponent<ClassificationComponent>();
     if(_Classification != EntityClassification.Any && (Classification == null || (Classification.Classification & this.Classification) == 0))
         return;
     bool Valid = OnCollision(Other.Parent, Classification == null ? EntityClassification.Unknown : Classification.Classification);
     if(Valid) {
         this._LastTriggered = DateTime.Now;
         if(DisposeOnCollision) {
             this.Dispose();
             if(TriggerRemaining) {
                 // TODO: This should only trigger things not already triggered for this collision.
                 // (Aka, DisposeOnCollision is false and already triggered before this one).
                 foreach(var OtherEvent in Parent.Components.Select(c => c as CollisionEventComponent).Where(c => c != null && c != this).ToArray())
                     OtherEvent.CollisionDetected(Component, Other, false);
                 Parent.Dispose();
             }
         }
     }
 }
Ejemplo n.º 4
0
 protected override void OnInitialize()
 {
     base.OnInitialize();
     EquipmentComponent = Parent.GetComponent<EquipmentComponent>();
     AttributesComponent = this.GetDependency<AttributesComponent>();
     MovementComponent = this.GetDependency<MovementComponent>();
     SpriteComponent = this.GetDependency<SpriteComponent>();
     PhysicsSystem = Parent.Scene.GetSystem<PhysicsSystem>();
     PhysicsComponent = Parent.GetComponent<PhysicsComponent>();
     CombatPropertiesComponent = this.GetDependency<CombatPropertiesComponent>();
     _ShieldAnimation = new ShieldAnimation(this.Parent, "Sprites/Misc/Shield_Yellow2");
 }
Ejemplo n.º 5
0
 protected override void OnInitialize()
 {
     base.OnInitialize();
     AttributesComponent = this.GetDependency<AttributesComponent>();
     SEAComponent = Parent.GetComponent<StatusEffectPropertiesComponent>();
     CPComponent = this.GetDependency<CombatPropertiesComponent>();
     PC = this.GetDependency<PhysicsComponent>();
 }
Ejemplo n.º 6
0
 protected override void OnInitialize()
 {
     base.OnInitialize();
     MovementComponent = this.GetDependency<MovementComponent>();
     PathComponent = this.GetDependency<PathComponent>();
     MovementComponent = this.GetDependency<MovementComponent>();
     CombatComponent = this.GetDependency<CombatComponent>();
     PhysicsSystem = Parent.Scene.GetSystem<PhysicsSystem>();
     PhysicsComponent = this.GetDependency<PhysicsComponent>();
     AttributesComponent = this.GetDependency<AttributesComponent>();
     SpriteComponent = this.GetDependency<SpriteComponent>();
     HealthBarComponent = this.GetDependency<HealthBarComponent>();
     DamageComponent = this.GetDependency<DamageComponent>();
 }
Ejemplo n.º 7
0
 protected override void OnInitialize()
 {
     base.OnInitialize();
     AC = this.GetDependency<AttributesComponent>();
     MC = this.GetDependency<MovementComponent>();
     CC = this.GetDependency<CombatComponent>();
     PC = this.GetDependency<PhysicsComponent>();
     SC = this.GetDependency<SpriteComponent>();
     EC = this.GetDependency<EquipmentComponent>();
     ScoreComponent = this.GetDependency<ScoreComponent>();
     _IsAttacking = false;
     if (!AC.IsDiedRegistered)
         AC.Died += AC_Died;
 }
Ejemplo n.º 8
0
 protected override void OnInitialize()
 {
     base.OnInitialize();
     PhysicsComponent = GetDependency <PhysicsComponent>();
     SpriteComponent  = GetDependency <SpriteComponent>();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Notifies this PhysicsComponent that a collision occurred with the other component.
 /// </summary>
 public void NotifyCollision(PhysicsComponent Other)
 {
     if(this.Collided != null)
         this.Collided(this, Other);
 }
Ejemplo n.º 10
0
 protected override void OnInitialize()
 {
     base.OnInitialize();
     MovementComponent = this.GetDependency<MovementComponent>();
     PhysicsSystem = Parent.Scene.GetSystem<PhysicsSystem>();
     PhysicsComponent = Parent.GetComponent<PhysicsComponent>();
 }
Ejemplo n.º 11
0
 void Physics_Collided(PhysicsComponent Component, PhysicsComponent Other)
 {
     CollisionDetected(Component, Other, true);
 }
Ejemplo n.º 12
0
 protected override void OnInitialize()
 {
     base.OnInitialize();
     PhysicsComponent = GetDependency<PhysicsComponent>();
     SpriteComponent = GetDependency<SpriteComponent>();
 }