예제 #1
0
 private static bool IsOutOfBounds(ParticleData particle, ParticleEffectData ped, Vector2 center)
 {
     if (!ped.restrictOuter && !ped.restrictInner)
     {
         return(false);
     }
     if (ped.fieldOuterRadius > 0)
     {
         return((ped.restrictOuter && Vector2.Distance(center, particle.position) > ped.fieldOuterRadius) || (ped.restrictInner && Vector2.Distance(center, particle.position) <= ped.fieldInnerRadius));
     }
     else
     {
         return((ped.restrictOuter && Math.Abs(particle.position.X - center.X) > ped.fieldOuterWidth / 2 || Math.Abs(particle.position.Y - center.Y) > ped.fieldOuterHeight / 2) || (ped.restrictInner && Math.Abs(particle.position.X - center.X) <= ped.fieldInnerWidth / 2 && Math.Abs(particle.position.Y - center.Y) <= ped.fieldInnerHeight / 2));
     }
 }
예제 #2
0
        private static void ShowParticleEffect(SpriteBatch b, List <ParticleData> particleList, ParticleEffectData ped, Vector2 center, float drawDepth, bool screen = false)
        {
            for (int i = particleList.Count - 1; i >= 0; i--)
            {
                particleList[i].age++;
                if (particleList[i].age > particleList[i].lifespan)
                {
                    particleList.RemoveAt(i);
                    continue;
                }
                Vector2 direction = particleList[i].direction;
                if (direction == Vector2.Zero)
                {
                    switch (ped.movementType)
                    {
                    case "away":
                        direction = (center - particleList[i].position) * new Vector2(-1, -1);
                        direction.Normalize();
                        break;

                    case "towards":
                        direction = center - particleList[i].position;
                        direction.Normalize();
                        break;

                    case "up":
                        direction = new Vector2(0, -1);
                        break;

                    case "down":
                        direction = new Vector2(0, 1);
                        break;

                    case "left":
                        direction = new Vector2(-1, 0);
                        break;

                    case "right":
                        direction = new Vector2(1, 0);
                        break;

                    case "random":
                        direction = new Vector2((float)Game1.random.NextDouble() - 0.5f, (float)Game1.random.NextDouble() - 0.5f);
                        direction.Normalize();
                        break;
                    }
                    particleList[i].direction = direction;
                }
                particleList[i].position += particleList[i].direction * (ped.movementSpeed + ped.acceleration * particleList[i].age);
                if (IsOutOfBounds(particleList[i], ped, center))
                {
                    particleList.RemoveAt(i);
                    continue;
                }
                particleList[i].rotation += particleList[i].rotationRate;
            }
            if (particleList.Count < ped.maxParticles && Game1.random.NextDouble() < ped.particleChance)
            {
                var particle = new ParticleData();
                particle.lifespan     = Game1.random.Next(ped.minLifespan, ped.maxLifespan + 1);
                particle.scale        = ped.minParticleScale + (float)Game1.random.NextDouble() * (ped.maxParticleScale - ped.minParticleScale);
                particle.alpha        = ped.minAlpha + (float)Game1.random.NextDouble() * (ped.maxAlpha - ped.minAlpha);
                particle.rotationRate = ped.minRotationRate + (float)Game1.random.NextDouble() * (ped.maxRotationRate - ped.minRotationRate);
                particle.option       = Game1.random.Next(ped.spriteSheet.Height / ped.particleHeight);
                if (ped.fieldOuterRadius <= 0)
                {
                    double x;
                    double y;
                    if (screen)
                    {
                        if (ped.fieldOffsetX < 0)
                        {
                            ped.fieldOffsetX = Game1.viewport.Width / 2;
                        }
                        if (ped.fieldOffsetY < 0)
                        {
                            ped.fieldOffsetY = Game1.viewport.Height / 2;
                        }
                        if (ped.fieldOuterWidth < 0)
                        {
                            ped.fieldOuterWidth = Game1.viewport.Width;
                        }
                        if (ped.fieldOuterHeight < 0)
                        {
                            ped.fieldOuterHeight = Game1.viewport.Height;
                        }
                    }
                    else
                    {
                        if (ped.fieldOffsetX < 0)
                        {
                            ped.fieldOffsetX = Game1.currentLocation.map.DisplayWidth / 2;
                        }
                        if (ped.fieldOffsetY < 0)
                        {
                            ped.fieldOffsetY = Game1.currentLocation.map.DisplayHeight / 2;
                        }
                        if (ped.fieldOuterWidth < 0)
                        {
                            ped.fieldOuterWidth = Game1.currentLocation.map.DisplayWidth;
                        }
                        if (ped.fieldOuterHeight < 0)
                        {
                            ped.fieldOuterHeight = Game1.currentLocation.map.DisplayHeight;
                        }
                    }
                    if (ped.fieldInnerHeight > 0)
                    {
                        var innerTop    = (ped.fieldOuterHeight - ped.fieldInnerHeight) / 2;
                        var innerBottom = ped.fieldOuterHeight - innerTop;
                        var innerLeft   = (ped.fieldOuterWidth - ped.fieldInnerWidth) / 2;
                        var innerRight  = ped.fieldOuterWidth - innerLeft;
                        var pixel       = (int)((ped.fieldOuterWidth * innerTop * 2 + ped.fieldInnerHeight * innerLeft * 2) * Game1.random.NextDouble());
                        if (pixel >= ped.fieldOuterWidth * innerTop + ped.fieldInnerHeight * innerLeft * 2) // bottom
                        {
                            pixel = pixel - ped.fieldOuterWidth * innerTop - ped.fieldInnerHeight * innerLeft * 2;
                            x     = pixel % ped.fieldOuterWidth;
                            y     = innerBottom + pixel / ped.fieldOuterWidth;
                        }
                        else if (pixel >= ped.fieldOuterWidth * innerTop + ped.fieldInnerHeight * innerLeft) // right
                        {
                            pixel = pixel - ped.fieldOuterWidth * innerTop - ped.fieldInnerHeight * innerLeft;
                            x     = innerRight + pixel % innerLeft;
                            y     = innerTop + pixel / innerLeft;
                        }
                        else if (pixel >= ped.fieldOuterWidth * innerTop) // left
                        {
                            pixel = pixel - ped.fieldOuterWidth * innerTop;
                            x     = pixel % innerLeft;
                            y     = innerTop + pixel / innerLeft;
                        }
                        else // top
                        {
                            x = pixel % ped.fieldOuterWidth;
                            y = pixel / ped.fieldOuterWidth;
                        }
                    }
                    else
                    {
                        x = ped.fieldOuterWidth * Game1.random.NextDouble();
                        y = ped.fieldOuterHeight * Game1.random.NextDouble();
                    }
                    particle.position = center - new Vector2(ped.fieldOuterWidth, ped.fieldOuterHeight) / 2 + new Vector2((float)x, (float)y);
                }
                else
                {
                    particle.position = center + GetCirclePos(ped);
                }
                particleList.Add(particle);
            }
            int frames = ped.spriteSheet.Width / ped.particleWidth;

            foreach (var particle in particleList)
            {
                float depthOffset = ped.belowOffset >= 0 ? (ped.aboveOffset >= 0 ? (Game1.random.NextDouble() < 0.5 ? ped.aboveOffset : ped.belowOffset) : ped.belowOffset) : ped.aboveOffset;
                int   frame       = (int)Math.Round(particle.age * ped.frameSpeed) % frames;
                b.Draw(ped.spriteSheet, new Rectangle(Utility.Vector2ToPoint(screen ? particle.position : Game1.GlobalToLocal(particle.position)), new Point((int)(ped.particleWidth * particle.scale), (int)(ped.particleHeight * particle.scale))), new Rectangle(frame * ped.particleWidth, particle.option * ped.particleHeight, ped.particleWidth, ped.particleHeight), Color.White * particle.alpha, particle.rotation, new Vector2(ped.particleWidth / 2, ped.particleHeight / 2), SpriteEffects.None, drawDepth + depthOffset);
            }
        }