Esempio n. 1
0
        private void _SetupMove(Vector3D destination, float speed)
        {
            Vector3D dir_normal = PowerMath.Normalize(new Vector3D(destination.X - this.Target.Position.X,
                                                                   destination.Y - this.Target.Position.Y,
                                                                   0f));  // were not moving in 3d for now

            this.Velocity = new Vector3D(dir_normal.X * speed,
                                         dir_normal.Y * speed,
                                         dir_normal.Z * speed);

            this.ArrivalTime = new RelativeTickTimer(this.Target.World.Game,
                                                     (int)(PowerMath.Distance2D(this.Target.Position, destination) / speed));
            _startPosition = this.Target.Position;
            _endPosition   = destination;
            _startTick     = this.Target.World.Game.TickCounter;
        }
Esempio n. 2
0
        public Actor GetClosestTo(Vector3D position)
        {
            Actor closest         = null;
            float closestDistance = float.MaxValue;

            foreach (Actor actor in this.Actors)
            {
                float distance = PowerMath.Distance2D(actor.Position, position);
                if (distance < closestDistance)
                {
                    closest         = actor;
                    closestDistance = distance;
                }
            }

            return(closest);
        }
Esempio n. 3
0
        private void _SetupArcMove(Vector3D destination, float crestHeight, float gravity)
        {
            // TODO: handle when target and destination heights differ
            float absGravity   = Math.Abs(gravity);
            float arcLength    = (float)Math.Sqrt(2f * crestHeight / absGravity);
            int   arrivalTicks = (int)(arcLength * 2f);

            float    distance = PowerMath.Distance2D(this.Target.Position, destination);
            Vector3D normal   = PowerMath.Normalize(new Vector3D(destination.X - this.Target.Position.X,
                                                                 destination.Y - this.Target.Position.Y,
                                                                 0f));

            this.Velocity = new Vector3D(normal.X * (distance / arrivalTicks),
                                         normal.Y * (distance / arrivalTicks),
                                         absGravity * arcLength);

            this.ArrivalTime = new RelativeTickTimer(this.Target.World.Game, arrivalTicks);
            _startPosition   = this.Target.Position;
            _endPosition     = destination;
            _startTick       = this.Target.World.Game.TickCounter;
            _arcGravity      = gravity;
        }
Esempio n. 4
0
 public void SortByDistanceFrom(Vector3D position)
 {
     this.Actors = this.Actors.OrderBy(actor => PowerMath.Distance2D(actor.Position, position)).ToList();
 }