private void MoveMark(float Theta)
        {
            if (BasicMarker.MoveSound != null)
            {
                BasicMarker.MoveSound.Play(BasicMarker.MoveVolume, 0, 0);
            }

            float BestDistance = 100000;

            BasicGameForm BestForm = null;

            foreach (BasicGameForm form in FormChildren)
            {
                if (form != CurrentForm && Vector2.Distance(form.Position.get(), Position.get()) > 32)
                {
                    float d = (400 + Vector2.Distance(form.Position.get(), Position.get())) / 1000 *
                              (float)Math.Pow(1 + (float)Math.Abs(MathHelper.WrapAngle(Theta - Logic.ToAngle(form.Position.get() - Position.get()))), 1);

                    if (d < BestDistance &&
                        Math.Abs(MathHelper.WrapAngle(Theta - Logic.ToAngle(form.Position.get() - Position.get()))) < 1)
                    {
                        BestDistance = d;
                        BestForm     = form;
                    }
                }
            }

            if (BestForm != null)
            {
                SetCurrentForm(BestForm);
            }
        }
        protected override void DrawHealthBar(float HealthMult, Vector2 Position, float Size)
        {
            if (WaveManager.ActiveTeam != GetTeam())
            {
                return;
            }

            if (StarshipScene.DrawingShip == null || StarshipScene.DrawingShip.GetTeam() != GetTeam())
            {
                base.DrawHealthBar(HealthMult, Position, Size);
            }
            else
            {
                Position.Y -= Size;
                float SizeMult2 = (1f + SizeMult) * (1.75f - HealthMult);
                if (Vector2.Distance(Render.CurrentView.Size / 2, Position) > Render.CurrentView.Size.Y * 0.4f)
                {
                    Vector2 NewPosition = Vector2.Normalize(Position - Render.CurrentView.Size / 2) * (Render.CurrentView.Size.Y * 0.4f) + Render.CurrentView.Size / 2;
                    Render.DrawSprite(MRockPointer, NewPosition, new Vector2(Size) * SizeMult2, DrawRotation, TeamInfo.GetColor(GetTeam()));
                    base.DrawHealthBar(HealthMult, NewPosition, Size);
                    TargetDrawRotation = -Logic.ToAngle((Position - NewPosition));
                }
                else
                {
                    TargetDrawRotation = 0;
                    Render.DrawSprite(MRockPointer, Position, new Vector2(Size) * SizeMult2, DrawRotation, TeamInfo.GetColor(GetTeam()));
                    base.DrawHealthBar(HealthMult, Position, Size);
                }
            }
        }
        public override void Update(GameTime gameTime)
        {
            float   Mult      = 0.1f + TimeAlive / (float)LifeTime;
            float   Offset    = 200 * Mult;
            Vector3 Position3 = new Vector3(0, ParentUnit.Y, 0);

            float Theta       = -Logic.ToAngle(Speed) - (float)Math.PI * 1f;
            float TargetTheta = Theta + (float)(Math.PI * 1.05);
            float Alpha       = 1 - (float)LifeTime / TimeAlive;

            for (; Theta < TargetTheta; Theta += (float)Math.PI / 20)
            {
                Position3.X = Position.X() + (float)Math.Cos(Theta) * Offset;
                Position3.Z = Position.Y() + (float)Math.Sin(Theta) * Offset;
                ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor * Alpha, Offset * 4, 1);
                //ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, Offset, 0);
            }

            Position3.X = Position.X();
            Position3.Z = Position.Y();

            if (!Flashed)
            {
                Mult *= 2;
                ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, 80 * Mult, 0);
                ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, 80 * Mult, 4);
                Flashed = true;
            }


            QuadGrid quad = Parent2DScene.quadGrids.First.Value;

            foreach (Basic2DObject o in quad.Enumerate(Position.get(), new Vector2(Offset * 2)))
            {
                if (o.GetType().IsSubclassOf(typeof(UnitTurret)) && o != FirstHitTurret &&
                    Vector2.Distance(o.Position.get(), Position.get()) < Offset)
                {
                    UnitTurret u = (UnitTurret)o;
                    if (u.CanBeTargeted())
                    {
                        if (FirstHitTurret == null)
                        {
                            FirstHitTurret = u;
                        }
                        else
                        {
                            u.ShutDownTime = (int)(1000 * Level);
                        }
                    }
                }
            }

            base.Update(gameTime);
        }
        protected override void AI(GameTime gameTime)
        {
            EmpLauncher.Update(gameTime);
            if (SearchTime > MaxSearchTime)
            {
                PlayerShip TargetPlayer = AISearchForPlayers();
                if (TargetPlayer != null)
                {
                    EmpLauncher.Fire(Logic.ToAngle(TargetPlayer.Position.get() - Position.get()));
                }
            }

            base.AI(gameTime);
        }
        public override void Update(GameTime gameTime)
        {
            NoShootTime = -1;
            FreezeTime  = -1;

            if (stingRayEmpFireMode.Ammo > 0 && CurrentAttackTarget != null &&
                CurrentAttackTarget.GetType().IsSubclassOf(typeof(UnitTurret)) && !MarkedTurrets.Contains((UnitTurret)CurrentAttackTarget))
            {
                stingRayEmpFireMode.SetLevel(UnitLevel);
                stingRayEmpFireMode.Fire(Logic.ToAngle(CurrentAttackTarget.Position.get() - Position.get()));
                stingRayEmpFireMode.Ammo = 0;
                MarkedTurrets.AddLast((UnitTurret)CurrentAttackTarget);
            }
            base.Update(gameTime);
        }
Exemplo n.º 6
0
        public override void Update(GameTime gameTime)
        {
            int Mult = 4;

            Vector3 Position3 = new Vector3(Position.X(), 0, Position.Y());

            ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor2, 60 * Mult, 1);
            ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor2, (70 + Rand.F() * 70) * Mult, 1);
            ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor2, (10 + Rand.F() * 20) * Mult, 2);
            ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor2, (10 + Rand.F() * 20) * Mult, 0);
            FlareSystem.AddLightning(Position3, ParticleColor2, 4, 20, 4, 10);

            SearchTime += gameTime.ElapsedGameTime.Milliseconds;
            if (SearchTime > MaxSearchTime || (AttackTarget != null && !AttackTarget.CanBeTargeted()))
            {
                SearchTime  -= MaxSearchTime;
                AttackTarget = null;
                float BestDistance = SearchDistance;

                QuadGrid quad = Parent2DScene.quadGrids.First.Value;
                foreach (Basic2DObject o in quad.Enumerate(Position.get(), new Vector2(SearchDistance * 2)))
                {
                    if (o.GetType().IsSubclassOf(typeof(UnitTurret)))
                    {
                        UnitBasic s = (UnitBasic)o;

                        if (s.CanBeTargeted() && !s.IsAlly(ParentUnit))
                        {
                            float d = Vector2.Distance(Position.get(), o.Position.get());

                            if (d < BestDistance && !o.GetType().Equals(typeof(CrystalWall)))
                            {
                                BestDistance = d;
                                AttackTarget = s;
                            }
                        }
                    }
                }
            }

            if (AttackTarget != null)
            {
                Speed = Logic.ToVector2(Logic.Clerp(Logic.ToAngle(Speed), Logic.ToAngle(AttackTarget.Position.get() - Position.get()),
                                                    TurnSpeed * gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f)) * SpeedL;
            }

            base.Update(gameTime);
        }
Exemplo n.º 7
0
        public override void Trigger()
        {
            if (RechargeTime >= MaxRechargeTime)
            {
                RechargeTime = 0;
                WindowMissileBullet b = new WindowMissileBullet();
                ParentShip.ParentLevel.AddObject(b);
                b.SetShipParent(ParentShip);
                b.SetPosition(ParentShip.getPosition());
                b.SetStartingPosition(b.getPosition());
                b.SetSpeed(BulletStartSpeed * Logic.ToVector2(Logic.ToAngle(ParentShip.AdjustedAimPointer - ParentShip.getPosition())));
                b.SetDamage(BulletDamage, BulletPushTime, BulletVelocityMult);
                b.SetAttackType(AttackType.Blue);
                b.SetModifierFactor(1);
                b.SetLifeTime(BulletLifeTime);
                b.SetExplosive(ExplosionDistance, ExplosionDamage);
            }

            base.Trigger();
        }
Exemplo n.º 8
0
 public override void Update(GameTime gameTime)
 {
     if (Shots > 0)
     {
         PauseTime += gameTime.ElapsedGameTime.Milliseconds;
         if (PauseTime > MaxPauseTime)
         {
             if (MissileAttackTarget == null || !MissileAttackTarget.CanBeTargeted())
             {
                 float BestDistance = 100000;
                 foreach (BasicShipGameObject o in FactionManager.SortedUnits[WaveManager.ActiveTeam])
                 {
                     if (o.GetType().IsSubclassOf(typeof(UnitTurret)))
                     {
                         float d = Vector2.Distance(Position.get(), o.Position.get());
                         if (d < BestDistance)
                         {
                             BestDistance        = d;
                             MissileAttackTarget = (UnitTurret)o;
                         }
                     }
                 }
             }
             else
             {
                 float TargetRotation = Logic.ToAngle(MissileAttackTarget.Position.get() - Position.get());
                 Rotation.set(MathHelper.ToDegrees(Logic.Clerp(Rotation.getAsRadians(), TargetRotation, RotationSpeed * gameTime.ElapsedGameTime.Milliseconds * 60.0f / 1000.0f)));
                 RotationMatrix = Matrix.CreateFromYawPitchRoll(Rotation.getAsRadians() + RotationOffset.X, RotationOffset.Y, RotationOffset.Z);
                 if (Math.Abs(Rotation.getAsRadians() - TargetRotation) < 0.1f)
                 {
                     PauseTime = 0;
                     Shots     = 1;
                     EmpFireMode.SetParent(this);
                     EmpFireMode.Fire(TargetRotation);
                 }
             }
         }
     }
     base.Update(gameTime);
 }
        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);
        }
        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);
        }
Exemplo n.º 11
0
        protected override void AI(GameTime gameTime)
        {
            float TargetRevolutionSpeed = 0.01f;

            if (CurrentAttackTarget != null && CurrentAttackTarget.CanBeTargeted() &&
                (Vector2.Distance(Position.get(), CurrentAttackTarget.Position.get()) < GetEngagementDistance() || Commited))
            {
                if (ChargeTime > MaxChargeTime / 2)
                {
                    TargetRevolutionSpeed = 0.1f;
                }

                ChargeTime += gameTime.ElapsedGameTime.Milliseconds;
                float Alpha = ChargeTime / (float)MaxChargeTime;

                Vector3 Position3 = new Vector3(Position.X(), Y, Position.Y());
                ParticleManager.CreateParticle(Position3, Vector3.Zero, LaserColor * Alpha, LaserStartSize + LaserEndSize * Alpha * 8, 1);
                FlareSystem.AddLightning(Position3, LaserColor * Alpha, 40, LaserStartSize + LaserEndSize * Alpha / 4, 3, 15);

                if (!Commited && ChargeTime > CommitTime)
                {
                    Commited       = true;
                    AttackPosition = CurrentAttackTarget.Position.get();
                    AttackPosition = Position.get() + Vector2.Normalize(AttackPosition - Position.get()) * GetEngagementDistance();
                }

                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);
                }

                if (ChargeTime > MaxChargeTime)
                {
                    if (Vector2.Distance(AttackPosition, Position.get()) > 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            ParticleManager.CreateParticle(new Vector3(Position.X(), Y, Position.Y()), Vector3.Zero, LaserColor, LaserStartSize + LaserEndSize, 0);
                        }

                        if (Shots > 1)
                        {
                            FireShot(Position.get(), AttackPosition, AttackLineWidth);
                            ChargeTime = MaxChargeTime - ShotTime;
                            Shots--;
                        }
                        else
                        {
                            FireShot(Position.get(), AttackPosition, AttackLineWidth);
                            ChargeTime = 0;
                            Shots      = MaxShots;
                            FreezeTime = AttackFreezeTime;
                            Commited   = false;
                        }
                    }
                    else
                    {
                        ChargeTime = 0;
                        Shots      = MaxShots;
                    }
                }

                SearchTime += gameTime.ElapsedGameTime.Milliseconds;
                if (SearchTime > MaxSearchTime)
                {
                    SearchTime -= MaxSearchTime;
                    AISearch(gameTime);
                }
            }
            else
            {
                if (ChargeTime > 0)
                {
                    ChargeTime -= gameTime.ElapsedGameTime.Milliseconds;
                    float Alpha = ChargeTime / MaxChargeTime;
                    ParticleManager.CreateParticle(new Vector3(Position.X(), Y, Position.Y()), Vector3.Zero, LaserColor * Alpha, LaserStartSize + LaserEndSize * Alpha, 1);
                    if (ChargeTime < 0)
                    {
                        ChargeTime = 0;
                    }
                }
                base.AI(gameTime);
            }

            RevolutionSpeed    += (TargetRevolutionSpeed - RevolutionSpeed) * gameTime.ElapsedGameTime.Milliseconds * 60 / 1000f * 0.1f;
            RotationOffsetSpeed = new Vector3(0, 0, RevolutionSpeed);
        }
Exemplo n.º 12
0
        public override void Update(GameTime gameTime)
        {
            if (Math.Abs(Y) > 10)
            {
                float YMoveAmount = gameTime.ElapsedGameTime.Milliseconds * 60 / 100000f;

                if (Y > 0)
                {
                    Y -= YMoveAmount;
                }
                else
                {
                    Y += YMoveAmount;
                }
            }

            WorldMatrix      = Matrix.CreateScale(Size.X() / BulletInstancer.ModelScale) * Matrix.CreateRotationY(Logic.ToAngle(Speed) + (float)Math.PI) * Matrix.CreateTranslation(new Vector3(Position.X(), Y, Position.Y()));
            PreviousPosition = Position.get();
            AddTime(gameTime.ElapsedGameTime.Milliseconds);
        }
 public void Accelerate(GameTime gameTime, Vector2 Amount)
 {
     Rotation.set(MathHelper.ToDegrees(Logic.Clerp(Rotation.getAsRadians(), Logic.ToAngle(Amount), RotationSpeed * gameTime.ElapsedGameTime.Milliseconds * 60.0f / 1000.0f)));
     SetSpeed(Logic.ToVector2(Rotation.getAsRadians()) * Acceleration * 5 * (FieldStateTime > 0 ? fieldState == FieldState.SpeedBoost ? 1.25f : 0.33f : 1));
     RotationMatrix = Matrix.CreateFromYawPitchRoll(Rotation.getAsRadians() + RotationOffset.X, RotationOffset.Y, RotationOffset.Z);
 }
        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);
            }
        }