コード例 #1
0
 public Vector2 GetPosition()
 {
     if (TargetObject == null)
     {
         return(TargetPosition);
     }
     else
     {
         return(TargetObject.getPosition());
     }
 }
コード例 #2
0
        protected virtual bool AIFireGuns(GameTime gameTime)
        {
            NoShootTime -= gameTime.ElapsedGameTime.Milliseconds;
            if (NoShootTime < 1 && Guns != null && CurrentAttackTarget != null && Vector2.Distance(Position.get(), CurrentAttackTarget.Position.get()) < GetEngagementDistance())
            {
                Vector2 CurrentAttackTargetPosition = CurrentAttackTarget.getPosition();

                /*
                 * if (CurrentAttackTarget.GetType().IsSubclassOf(typeof(UnitBasic)))
                 * {
                 *  UnitBasic b = (UnitBasic)CurrentAttackTarget;
                 *  CurrentAttackTargetPosition += Vector2.Distance(CurrentAttackTarget.getPosition(), getPosition()) / Guns[0].GetFireSpeed() *
                 *      b.Speed * (b.MaxDragTime - b.DragTime) / b.MaxDragTime * gameTime.ElapsedGameTime.Milliseconds * 60 / 1000;
                 * }
                 */
                float TargetRotation = Logic.ToAngle(CurrentAttackTargetPosition - Position.get());

                foreach (GunBasic g in Guns)
                {
                    if (g != null)
                    {
                        g.SetRotation(TargetRotation);
                    }
                }
                foreach (GunBasic g in Guns)
                {
                    if (g != null)
                    {
                        g.AutoFire(gameTime);
                        if (!g.HasAmmo())
                        {
                            MaxEngagementDistance = -1;
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
コード例 #3
0
        private void AIGuns(GameTime gameTime)
        {
            if (!WaveStepState.WeaponsFree || Guns == null)
            {
                return;
            }

            if (VirusTime < 1)
            {
                if (CurrentAttackTarget == null)
                {
                    return;
                }

                Vector2 CurrentAttackTargetPosition = CurrentAttackTarget.getPosition();

                float TargetRotation = Logic.ToAngle(CurrentAttackTargetPosition - getPosition());
                if (Rotation.get() != TargetRotation)
                {
                    Rotation.set(MathHelper.ToDegrees(Logic.Clerp(Rotation.getAsRadians(), TargetRotation, MathHelper.ToRadians(RotationSpeed) * gameTime.ElapsedGameTime.Milliseconds / 1000 * 60)));
                    RotationMatrix = Matrix.CreateFromYawPitchRoll(Rotation.getAsRadians() + RotationOffset.X, RotationOffset.Y, RotationOffset.Z);
                }
            }
            else
            {
                Rotation.set(Rotation.get() + MathHelper.ToRadians(gameTime.ElapsedGameTime.Milliseconds * 20));
                RotationMatrix = Matrix.CreateFromYawPitchRoll(Rotation.getAsRadians() + RotationOffset.X, RotationOffset.Y, RotationOffset.Z);
            }

            foreach (GunBasic g in Guns)
            {
                g.SetRotation(Rotation.getAsRadians());
            }

            AutoFire(gameTime);
        }
コード例 #4
0
 public bool CheckCircle(BasicShipGameObject g, Vector2 StartPosition, Vector2 EndPosition, float LineWidth)
 {
     return(Logic.DistanceLineSegmentToPoint(StartPosition, EndPosition, g.getPosition()) < (g.getSize().X + AttackLineWidth) / 2);
 }
コード例 #5
0
        private void AIMove(GameTime gameTime)
        {
            MoveChangeTime += gameTime.ElapsedGameTime.Milliseconds;
            if (MoveChangeTime > MaxMoveChangeTime)
            {
                MoveChangeTime -= MaxMoveChangeTime;

                TargetPosition = Position.get();

                if (!DodgesBullets || BulletToDodge == null || BulletToDodge.TimeAlive > BulletToDodge.LifeTime)
                {
                    if (BulletToDodge != null)
                    {
                        BulletToDodge = null;
                    }

                    if (CurrentAttackTarget != null)
                    {
                        float d = Vector2.Distance(CurrentAttackTarget.getPosition(), getPosition());

                        if (!RunningAway)
                        {
                            if (d > MinEngagementDistance)
                            {
                                TargetPosition = CurrentAttackTarget.getPosition();
                            }
                            else if (d < MinEngagementDistance)
                            {
                                TargetPosition = Position.get();
                            }
                        }
                        else
                        {
                            TargetPosition = Position.get() + (Position.get() - CurrentAttackTarget.getPosition());
                        }

                        DisplacedFromPath = true;
                    }
                    else
                    {
                        if (TargetNode == null)
                        {
                            TargetNode        = PathFindingNode.GetBestNode(Position.get());
                            DisplacedFromPath = false;
                        }
                        else
                        {
                            DisplaceTime += gameTime.ElapsedGameTime.Milliseconds;
                            if (DisplaceTime > MaxDisplaceTime)
                            {
                                DisplaceTime     -= MaxDisplaceTime;
                                DisplacedFromPath = true;
                            }

                            if (DisplacedFromPath)
                            {
                                if (PathFindingManager.CollisionLine(Position.get(), TargetNode.Position.get()))
                                {
                                    TargetNode = PathFindingNode.GetBestNode(Position.get());
                                }
                                DisplacedFromPath = false;
                            }
                        }

                        TargetPosition = TargetNode.Position.get();

                        if (TargetNode.GetNext() != null && !PathFindingManager.CollisionLine(Position.get(), TargetNode.GetNext().Position.get()) ||
                            (Vector2.Distance(getPosition(), TargetPosition) < 16))
                        {
                            TargetNode = TargetNode.GetNext();
                        }
                    }
                }
                else
                {
                    Vector2 bPos = BulletToDodge.getPosition();
                    bPos += BulletToDodge.Speed / BulletToDodge.Speed.Length() * Vector2.Distance(bPos, Position.get());

                    TargetPosition = (Position.get() - (bPos - Position.get()));

                    BulletDodgeTime -= gameTime.ElapsedGameTime.Milliseconds;

                    if (BulletDodgeTime < 0)
                    {
                        TargetPosition = CurrentMoveTarget == null ? TargetPosition : CurrentMoveTarget.getPosition();
                        BulletToDodge  = null;
                    }

                    DisplacedFromPath = true;
                }
            }

            if (Vector2.Distance(getPosition(), TargetPosition) > 16)
            {
                Accelerate(gameTime, TargetPosition - getPosition());
            }
            else if (CurrentAttackTarget != null)
            {
                Rotation.set(MathHelper.ToDegrees(Logic.Clerp(Rotation.getAsRadians(), Logic.ToAngle(CurrentAttackTarget.Position.get() - Position.get()), RotationSpeed * gameTime.ElapsedGameTime.Milliseconds * 60.0f / 1000.0f)));
                RotationMatrix = Matrix.CreateFromYawPitchRoll(Rotation.getAsRadians() + RotationOffset.X, RotationOffset.Y, RotationOffset.Z);
            }
        }