Example #1
0
        public void DeflectAgainst(V3 normal)
        {
            V3    V      = Velocity.Clone();
            V3    N      = normal;
            float dot    = (V * N) * 2F;
            V3    vec    = (V3)N.ScaleBy(dot);
            V3    newvel = Velocity - vec;

            Velocity = newvel;
        }
Example #2
0
        public void DeflectAgainst(Edge edge)
        {
            V3    V      = Velocity.Clone();
            V3    N      = edge.GetNormal2DRightHanded();
            float dot    = (V * N) * 2F;
            V3    vec    = (V3)N.ScaleBy(dot);
            V3    newvel = Velocity - vec;

            Velocity = newvel;
        }
Example #3
0
 public GravityObject Clone()
 {
     return(new GravityObject
     {
         Position = Position.Clone(),
         Velocity = Velocity.Clone(),
         Mass = Mass,
         Radius = Radius,
         IsStatic = IsStatic
     });
 }
Example #4
0
        public override Object Clone()
        {
            Particle myobj = (Particle)base.Clone();

            // must clone the Velocity and Neighborhood pattern if they exist
            if (Velocity != null)
            {
                Velocity = (double[])Velocity.Clone();
            }
            if (Neighborhood != null)
            {
                Neighborhood = (int[])Neighborhood.Clone();
            }
            return(myobj);
        }
Example #5
0
        public Object2DBase Clone()
        {
            var c = (Object2DBase)MemberwiseClone();

            if (Velocity != null)
            {
                c.Velocity = Velocity.Clone();
            }
            if (Accerelation != null)
            {
                c.Accerelation = Accerelation.Clone();
            }
            if (Position != null)
            {
                c.Position = Position.Clone();
            }
            return(c);
        }
Example #6
0
        public override IParticle Clone()
        {
            Firework2D temp = new Firework2D((Vector2D)Position.Clone(), (Vector2D)Velocity.Clone());

            temp.Particles.Clear();
            lock (Particles)
                Particles.ToList().ForEach((p) =>
                {
                    temp.Particles.Add((AParticle)p.Clone());
                });
            temp.Mass = Mass;
            temp.ParticleDiminishRate = ParticleDiminishRate;
            temp.Exploded             = Exploded;
            temp.Color = Color;
            temp.ExplosionPlacementRadius = ExplosionPlacementRadius;
            temp.ExplosionMag             = ExplosionMag;
            temp.Diameter       = Diameter;
            temp.ExplosionAlpha = ExplosionAlpha;
            return(temp);
        }
        public override void Update(float timeElapsed)
        {
            // Calculate the combined force from each steering behaviour.
            Vector2D steeringForce = SB.Calculate();

            // Acceleration = Force / Mass (Newton's laws of physics).
            Vector2D acceleration = steeringForce.Clone().divide(Mass);

            // Update velocity.
            Velocity.Add(acceleration.Clone().Multiply(timeElapsed));

            // Make sure the moving entity does not exceed maximum speed.
            Velocity.Truncate(MaxSpeed);

            // Update position.
            Pos.Add(Velocity.Clone().Multiply(timeElapsed));

            // Update heading if the velocity is bigger than 0
            if (Velocity.LengthSquared() > 0)
            {
                Heading = Velocity.Clone().Normalize();
            }
        }
Example #8
0
        public override IParticle Clone()
        {
            Particle2D temp = new Particle2D(Color.FromArgb(Color.ToArgb()), (Vector2D)Position.Clone(), (Vector2D)Velocity.Clone(), (Vector2D)Acceleration.Clone())
            {
                Diameter = Diameter,
                Mass     = Mass
            };

            return(temp);
        }
Example #9
0
        public void Update(int iterations)
        {
            input.Update(iterations, world, this);

            if (!acceleration.IsValid())
            {
                acceleration = new Vector(0, 0);
            }

            Velocity += acceleration * factor1;

            Velocity *= 0.97;

            oldPosition = Position.Clone();
            Position   += Velocity * factor2;

            Cell currentCell = GetCurrentCell();

            if (currentCell.CellType == CellType.Attractor && Collide(currentCell))
            {
                Score += 50;
                currentCell.CellType = CellType.Normal;
            }

            foreach (Bumpership b in world.Bumperships.Where(b => b != this && Collide(b)))
            {
                Position = oldPosition;

                Vector oldVelocityA = Velocity.Clone();
                Vector oldVelocityB = b.Velocity.Clone();

                Velocity   = Reflect(Velocity, Normalize(Position - b.Position));
                b.Velocity = Reflect(b.Velocity, Normalize(b.Position - Position));

                lastcollider   = b;
                b.lastcollider = this;

                if (Velocity.Length > b.Velocity.Length)
                {
                    b.Velocity += oldVelocityA * 0.8;
                    Velocity   *= 0.2;
                    Score      += 5;
                    b.Score    -= 5;
                }
                else
                {
                    b.Velocity += oldVelocityB * 0.8;
                    Velocity   *= 0.2;
                    b.Score    += 5;
                    Score      -= 5;
                }
            }

            if (currentCell.CellType == CellType.None)
            {
                if (lastcollider != null)
                {
                    lastcollider.Score += 50;
                    lastcollider        = null;
                }
                if (IsSpawnable())
                {
                    Score -= 50;
                    Spawn();
                }
            }

            foreach (Cell cell in GetTouchingCells().Where(Collide))
            {
                if (cell.CellType == CellType.Blocked && Collide(cell.Position, 0.5))
                {
                    Position = oldPosition;
                    Velocity = Reflect(Velocity, Normalize(Position - cell.Position));
                }
                else if (cell.CellType == CellType.Boost)
                {
                    Velocity *= 1.1;
                }
                else if (cell.CellType == CellType.SlowDown)
                {
                    Velocity *= 0.9;
                }
            }
        }