예제 #1
0
 public Particle()
 {
     Position = new Point(0, 0);
     Direction = new DoublePoint(0, 0);
     DeltaColor = new double[4];
     Color = new double[4];
 }
예제 #2
0
        public ParticleSystem(int numOfCaches)
        {
            myNumOfCaches = numOfCaches;
            MaxParticles = 150;
            Particles = new List<Particle>();
            Active = true;

            Position = new Point(100, 100);
            PositionRandom = new Point(10, 10);
            Size = 45;
            SizeRandom = 8;
            Speed = 5;
            SpeedRandom = 1.5;
            LifeSpan = 9;
            LifeSpanRandom = 7;
            Angle = 0;
            AngleRandom = 360;
            Gravity = new DoublePoint(0.4, 0.2);
            StartColor = new int[] {250, 218, 68, 1};
            StartColorRandom = new int[] {5, 5, 5, 0};
            EndColor = new int[] {245, 35, 0, 0};
            EndColorRandom = new int[] {5, 5, 5, 0};
            Sharpness = 40;
            SharpnessRandom = 10;
            MaxEmitted = -1;

            ElapsedTime = 0;
            Duration = -1;
            EmissionRate = 0;
            EmitCounter = 0;
        }
예제 #3
0
        public IEnumerable<Point> Travel(int stepsTotal, Point scale, bool reverse)
        {
            DoublePoint cur = new DoublePoint(0, 0);
            DoublePoint dist = new DoublePoint(0, 0);

            double stp = ( (double) stepsTotal / ( (double) Waypoints.Count - 1 ) );

            if (reverse) {
                for (int index = Waypoints.Count - 1; index >= 1; index--) {
                    var waypoint = Waypoints[index];
                    var nextWaypoint = Waypoints[index - 1];

                    cur.X = waypoint.X * scale.X;
                    cur.Y = waypoint.Y * scale.Y;

                    dist.X = ( (double) nextWaypoint.X - waypoint.X ) / stp;
                    dist.Y = ( (double) nextWaypoint.Y - waypoint.Y ) / stp;

                    for (int i = 0; i < stp; i++) {
                        cur.X += dist.X * scale.X;
                        cur.Y += dist.Y * scale.Y;
                        yield return new Point((int) cur.X, (int) cur.Y);
                    }
                }
            } else {
                for (int index = 0; index < Waypoints.Count - 1; index++) {
                    var waypoint = Waypoints[index];
                    var nextWaypoint = Waypoints[index + 1];

                    cur.X = waypoint.X * scale.X;
                    cur.Y = waypoint.Y * scale.Y;

                    dist.X = ( (double) nextWaypoint.X - waypoint.X ) / stp;
                    dist.Y = ( (double) nextWaypoint.Y - waypoint.Y ) / stp;

                    for (int i = 0; i < stp; i++) {
                        cur.X += dist.X * scale.X;
                        cur.Y += dist.Y * scale.Y;
                        yield return new Point((int) cur.X, (int) cur.Y);
                    }
                }
            }
        }
예제 #4
0
 public Point Add(DoublePoint scaleFactor)
 {
     X += (int) scaleFactor.X;
     Y += (int) scaleFactor.Y;
     return this;
 }
예제 #5
0
 public DoublePoint Offset(DoublePoint windowLocation)
 {
     return new DoublePoint(X + windowLocation.X, Y + windowLocation.Y);
 }
예제 #6
0
 public DoublePoint Negate(DoublePoint windowLocation)
 {
     return new DoublePoint(X - windowLocation.X, Y - windowLocation.Y);
 }
예제 #7
0
 public DoublePoint(DoublePoint pos)
 {
     X = pos.X;
     Y = pos.Y;
 }
예제 #8
0
        private void initParticle(Particle particle)
        {
            var cache = RandomCaches();

            particle.System = this;

            particle.Position.X = (int) ( Position.X + PositionRandom.X * Random() );
            particle.Position.Y = (int) ( Position.Y + PositionRandom.Y * Random() );

            var newAngle = ( Angle + AngleRandom * Random() ) * ( Math.PI / 180 ); // convert to radians
            var vector = new DoublePoint(Math.Cos(newAngle), Math.Sin(newAngle)); // Could move to lookup for speed
            var vectorSpeed = Speed + SpeedRandom * Random();
            particle.Direction = vector.Multiply(vectorSpeed);

            particle.Size = cache.Size;
            particle.Size = particle.Size < 0 ? 0 : ~~(int) particle.Size;
            particle.TimeToLive = cache.TimeToLive;

            particle.Sharpness = cache.Sharpness;
            particle.Sharpness = particle.Sharpness > 100 ? 100 : particle.Sharpness < 0 ? 0 : particle.Sharpness;
            // internal circle gradient size - affects the sharpness of the radial gradient
            particle.SizeSmall = (int) ( ( particle.Size / 200 ) * particle.Sharpness ); //(size/2/100)

            double[] start = cache.Start;

            double[] end = cache.End;

            particle.Color = start;
            particle.DeltaColor[0] = ( end[0] - start[0] ) / particle.TimeToLive;
            particle.DeltaColor[1] = ( end[1] - start[1] ) / particle.TimeToLive;
            particle.DeltaColor[2] = ( end[2] - start[2] ) / particle.TimeToLive;
            particle.DeltaColor[3] = ( end[3] - start[3] ) / particle.TimeToLive;

            particle.BuildCache(1, cache);

            if (Game.DebugText[1].Falsey())
                Game.DebugText[1] = 0;
            Game.DebugText[1] = (int) Game.DebugText[1] + 1;
        }