Esempio n. 1
0
        private void AdjustIntensity(Entity beamEntity, BeamComponent beamComponent)
        {
            // adjust intensity
            if (beamComponent.Intensity >= 1 && beamComponent.Beam.Lifetime > 0)
            {
                beamComponent.Age += (EntityWorld.Delta / 1000f);
                if (beamComponent.Age > beamComponent.Beam.Lifetime)
                {
                    beamComponent.IsPowered = false;
                }
            }

            if (beamComponent.IsPowered)
            {
                if (beamComponent.Beam.IntensityFadeInTime > 0)
                {
                    beamComponent.Intensity += (EntityWorld.Delta / beamComponent.Beam.IntensityFadeInTime) / 1000f;
                    if (beamComponent.Intensity > 1)
                        beamComponent.Intensity = 1;
                }
                else
                {
                    beamComponent.Intensity = 1;
                }
            }
            else
            {
                if (beamComponent.Beam.IntensityFadeOutTime > 0)
                {
                    beamComponent.Intensity -= (EntityWorld.Delta / beamComponent.Beam.IntensityFadeOutTime) / 1000f;
                    if (beamComponent.Intensity < 0)
                        beamComponent.Intensity = 0;
                }
                else
                {
                    beamComponent.Intensity = 0;
                }

                if (beamComponent.Intensity <= 0)
                {
                    beamEntity.Delete();
                }
            }
        }
Esempio n. 2
0
        private void TestBeamHit(Entity beamEntity, BeamComponent beamComponent)
        {
            if (_physicsWorld == null) return;
            var xform = beamEntity.GetComponent<Transform>();
            _hitFraction = 1;
            _hitObject = null;

            _physicsWorld.RayCast(
                RaycastCallback,
                xform.Position * Constants.PhysicsUnitScale,
                (xform.Position + Utilities.CreateVector2FromAngle(xform.Rotation) * beamComponent.Beam.Range) * Constants.PhysicsUnitScale);

            if (_hitObject != null)
            {
                _beamHitEventArgs.Beam = beamEntity;
                _beamHitEventArgs.Damage = beamComponent.DamagePerSecond.Roll(_dieRoller).Value * EntityWorld.Delta * 0.001f;
                _beamHitEventArgs.HitFraction = _hitFraction;
                _beamHitEventArgs.HitObject = _hitObject;
                _beamHitEventArgs.Position = _hitPosition;

                beamEntity.FireEvent(this, EventId.BeamHit, _beamHitEventArgs);
                _hitObject.FireEvent(this, EventId.BeamHit, _beamHitEventArgs);
                EntityWorld.FireEvent(this, EventId.BeamHit, _beamHitEventArgs);
                beamComponent.Range = beamComponent.Beam.Range * _hitFraction;
            }
        }