Exemplo n.º 1
0
        public void Init(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation, Hull hullGuess = null)
        {
            this.prefab = prefab;

            spriteIndex = Rand.Int(prefab.Sprites.Count);

            animState = 0;
            animFrame = 0;

            currentHull = Hull.FindHull(position, hullGuess);

            this.position = position;
            prevPosition  = position;

            drawPosition = position;

            velocity = MathUtils.IsValid(speed) ? speed : Vector2.Zero;

            if (currentHull != null && currentHull.Submarine != null)
            {
                velocity += ConvertUnits.ToDisplayUnits(currentHull.Submarine.Velocity);
            }

            this.rotation = rotation + Rand.Range(prefab.StartRotationMinRad, prefab.StartRotationMaxRad);
            prevRotation  = rotation;

            angularVelocity = Rand.Range(prefab.AngularVelocityMinRad, prefab.AngularVelocityMaxRad);

            totalLifeTime = prefab.LifeTime;
            lifeTime      = prefab.LifeTime;

            size = prefab.StartSizeMin + (prefab.StartSizeMax - prefab.StartSizeMin) * Rand.Range(0.0f, 1.0f);

            sizeChange = prefab.SizeChangeMin + (prefab.SizeChangeMax - prefab.SizeChangeMin) * Rand.Range(0.0f, 1.0f);

            color = new Color(prefab.StartColor, 1.0f);
            alpha = prefab.StartAlpha;

            velocityChange = prefab.VelocityChangeDisplay;

            OnChangeHull = null;

            if (prefab.DeleteOnCollision || prefab.CollidesWithWalls)
            {
                hullGaps = currentHull == null ? new List <Gap>() : currentHull.ConnectedGaps;
            }

            if (prefab.RotateToDirection)
            {
                this.rotation = MathUtils.VectorToAngle(new Vector2(velocity.X, -velocity.Y));

                prevRotation = rotation;
            }
        }
Exemplo n.º 2
0
        public void Init(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation, Hull hullGuess = null, bool drawOnTop = false)
        {
            this.prefab = prefab;

            spriteIndex = Rand.Int(prefab.Sprites.Count);

            animState = 0;
            animFrame = 0;
            dragWait  = 0;
            dragVec   = Vector2.Zero;

            currentHull = Hull.FindHull(position, hullGuess);

            this.position = position;
            prevPosition  = position;

            drawPosition = position;

            velocity = MathUtils.IsValid(speed) ? speed : Vector2.Zero;

            if (currentHull?.Submarine != null)
            {
                velocity += ConvertUnits.ToDisplayUnits(currentHull.Submarine.Velocity);
            }

            this.rotation = rotation + Rand.Range(prefab.StartRotationMinRad, prefab.StartRotationMaxRad);
            prevRotation  = rotation;

            angularVelocity = Rand.Range(prefab.AngularVelocityMinRad, prefab.AngularVelocityMaxRad);

            totalLifeTime = prefab.LifeTime;
            lifeTime      = prefab.LifeTime;
            startDelay    = Rand.Range(prefab.StartDelayMin, prefab.StartDelayMax);

            size = prefab.StartSizeMin + (prefab.StartSizeMax - prefab.StartSizeMin) * Rand.Range(0.0f, 1.0f);

            sizeChange = prefab.SizeChangeMin + (prefab.SizeChangeMax - prefab.SizeChangeMin) * Rand.Range(0.0f, 1.0f);

            color       = prefab.StartColor;
            changeColor = prefab.StartColor != prefab.EndColor;

            velocityChange      = prefab.VelocityChangeDisplay;
            velocityChangeWater = prefab.VelocityChangeWaterDisplay;

            HighQualityCollisionDetection = false;

            OnChangeHull = null;

            subEmitters.Clear();
            hasSubEmitters = false;
            foreach (ParticleEmitterPrefab emitterPrefab in prefab.SubEmitters)
            {
                subEmitters.Add(new ParticleEmitter(emitterPrefab));
                hasSubEmitters = true;
            }

            if (prefab.UseCollision)
            {
                hullGaps = currentHull == null ? new List <Gap>() : currentHull.ConnectedGaps;
            }

            if (prefab.RotateToDirection)
            {
                this.rotation = MathUtils.VectorToAngle(new Vector2(velocity.X, -velocity.Y));

                prevRotation = rotation;
            }

            DrawOnTop = drawOnTop;
        }
Exemplo n.º 3
0
        public void Init(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation, Hull hullGuess = null)
        {
            this.prefab = prefab;

            spriteIndex = Rand.Int(prefab.Sprites.Count);

            animState = 0;
            animFrame = 0;
            dragWait  = 0;
            dragVec   = Vector2.Zero;

            currentHull = Hull.FindHull(position, hullGuess);

            this.position = position;
            prevPosition  = position;

            drawPosition = position;

            velocity = MathUtils.IsValid(speed) ? speed : Vector2.Zero;

            if (currentHull != null && currentHull.Submarine != null)
            {
                velocity += ConvertUnits.ToDisplayUnits(currentHull.Submarine.Velocity);
            }

            this.rotation = rotation + Rand.Range(prefab.StartRotationMinRad, prefab.StartRotationMaxRad);
            prevRotation  = rotation;

            angularVelocity = Rand.Range(prefab.AngularVelocityMinRad, prefab.AngularVelocityMaxRad);

            if (GameMain.NilMod.ParticleWhitelist.Find(p => p == prefab.Name) != null)
            {
                totalLifeTime = prefab.LifeTime;
                lifeTime      = prefab.LifeTime;
            }
            else
            {
                totalLifeTime = prefab.LifeTime * GameMain.NilMod.ParticleLifeMultiplier;
                lifeTime      = prefab.LifeTime * GameMain.NilMod.ParticleLifeMultiplier;
            }

            size = prefab.StartSizeMin + (prefab.StartSizeMax - prefab.StartSizeMin) * Rand.Range(0.0f, 1.0f);

            sizeChange = prefab.SizeChangeMin + (prefab.SizeChangeMax - prefab.SizeChangeMin) * Rand.Range(0.0f, 1.0f);

            color = new Color(prefab.StartColor, 1.0f);
            alpha = prefab.StartAlpha;

            velocityChange      = prefab.VelocityChangeDisplay;
            velocityChangeWater = prefab.VelocityChangeWaterDisplay;

            OnChangeHull = null;

            subEmitters.Clear();
            foreach (ParticleEmitterPrefab emitterPrefab in prefab.SubEmitters)
            {
                subEmitters.Add(new ParticleEmitter(emitterPrefab));
            }

            if (prefab.DeleteOnCollision || prefab.CollidesWithWalls)
            {
                hullGaps = currentHull == null ? new List <Gap>() : currentHull.ConnectedGaps;
            }

            if (prefab.RotateToDirection)
            {
                this.rotation = MathUtils.VectorToAngle(new Vector2(velocity.X, -velocity.Y));

                prevRotation = rotation;
            }
        }
Exemplo n.º 4
0
        public void Init(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation, Hull hullGuess = null, bool drawOnTop = false, float collisionIgnoreTimer = 0f, Tuple <Vector2, Vector2> tracerPoints = null)
        {
            this.prefab = prefab;
            debugName   = $"Particle ({prefab.Name})";

            spriteIndex = Rand.Int(prefab.Sprites.Count);

            animState = 0;
            animFrame = 0;

            currentHull = Hull.FindHull(position, hullGuess);

            size = prefab.StartSizeMin + (prefab.StartSizeMax - prefab.StartSizeMin) * Rand.Range(0.0f, 1.0f);

            if (tracerPoints != null)
            {
                size     = new Vector2(Vector2.Distance(tracerPoints.Item1, tracerPoints.Item2), size.Y);
                position = (tracerPoints.Item1 + tracerPoints.Item2) / 2;
            }

            sizeChange = prefab.SizeChangeMin + (prefab.SizeChangeMax - prefab.SizeChangeMin) * Rand.Range(0.0f, 1.0f);

            this.position = position;
            prevPosition  = position;

            drawPosition = position;

            velocity = MathUtils.IsValid(speed) ? speed : Vector2.Zero;

            if (currentHull?.Submarine != null)
            {
                velocity += ConvertUnits.ToDisplayUnits(currentHull.Submarine.Velocity);
            }

            this.rotation = rotation + Rand.Range(prefab.StartRotationMinRad, prefab.StartRotationMaxRad);
            prevRotation  = rotation;

            angularVelocity = Rand.Range(prefab.AngularVelocityMinRad, prefab.AngularVelocityMaxRad);


            if (prefab.LifeTimeMin <= 0.0f)
            {
                totalLifeTime = prefab.LifeTime;
                lifeTime      = prefab.LifeTime;
            }
            else
            {
                totalLifeTime = Rand.Range(prefab.LifeTimeMin, prefab.LifeTime);
                lifeTime      = totalLifeTime;
            }

            startDelay = Rand.Range(prefab.StartDelayMin, prefab.StartDelayMax);

            UseMiddleColor  = prefab.UseMiddleColor;
            color           = prefab.StartColor;
            changeColor     = prefab.StartColor != prefab.EndColor;
            ColorMultiplier = Vector4.One;

            velocityChange      = prefab.VelocityChangeDisplay;
            velocityChangeWater = prefab.VelocityChangeWaterDisplay;

            HighQualityCollisionDetection = false;

            OnChangeHull = null;

            subEmitters.Clear();
            hasSubEmitters = false;
            foreach (ParticleEmitterPrefab emitterPrefab in prefab.SubEmitters)
            {
                subEmitters.Add(new ParticleEmitter(emitterPrefab));
                hasSubEmitters = true;
            }

            if (prefab.UseCollision)
            {
                hullGaps = currentHull == null ? new List <Gap>() : currentHull.ConnectedGaps;
            }

            if (prefab.RotateToDirection)
            {
                this.rotation = MathUtils.VectorToAngle(new Vector2(velocity.X, -velocity.Y));

                prevRotation = rotation;
            }

            DrawOnTop = drawOnTop;

            this.collisionIgnoreTimer = collisionIgnoreTimer;
        }