示例#1
0
        public override void Update(float deltaTime)
        {
            base.Update(deltaTime);
            altitudeVariation += deltaTime;

            attackCooldown += deltaTime;

            if (target != null && !target.Alive)
            {
                target = null;
            }

            if (target == null)
            {
                target = CollisionManager.CollidesWithTurret(detectionBox);
            }

            if (target == null)
            {
                target = CollisionManager.CollidesWithForcefield(detectionBox);
            }

            if (target == null)
            {
                target = CollisionManager.CollidesWithBuilding(detectionBox);
            }

            else
            {
                if (attackCooldown >= 1000f / attackSpeed)
                {
                    double          projectileX         = X + Width / 2;
                    double          projectileY         = Y + Height;
                    float           projectileDirection = (float)Math.PI / 2;
                    EnemyProjectile p1 = new EnemyProjectile(content, projectileX, projectileY, projectileDirection, attackPower, "ufoprojectile");
                    EnemyProjectile p2 = new EnemyProjectile(content, projectileX - 15, projectileY, projectileDirection, attackPower, "ufoprojectile");
                    EnemyProjectile p3 = new EnemyProjectile(content, projectileX - 30, projectileY, projectileDirection, attackPower, "ufoprojectile");
                    EnemyProjectile p4 = new EnemyProjectile(content, projectileX + 15, projectileY, projectileDirection, attackPower, "ufoprojectile");
                    EnemyProjectile p5 = new EnemyProjectile(content, projectileX + 30, projectileY, projectileDirection, attackPower, "ufoprojectile");
                    attackCooldown = 0;
                    if (attackSound != null)
                    {
                        SoundManager.PlayClip(attackSound);
                    }
                }
            }

            if (direction == EnemyDirection.ToLeft)
            {
                X -= movingSpeed / 100 * deltaTime;

                if (X + Width < 0)
                {
                    direction = EnemyDirection.ToRight;
                }
            }
            else
            {
                X += movingSpeed / 100 * deltaTime;

                if (X > Game.GAME_WIDTH)
                {
                    direction = EnemyDirection.ToLeft;
                }
            }
            Y = Y - altitudeVariationModifier * Math.Sin(altitudeVariation / 300) * deltaTime * 6 / 100;
        }
示例#2
0
        public override void Update(float deltaTime)
        {
            base.Update(deltaTime);

            attackCooldown += deltaTime;

            target = CollisionManager.CollidesWithBuilding(rangeBox);

            if (target == null)
            {
                if (Direction == EnemyDirection.ToLeft)
                {
                    X -= movingSpeed / 100 * deltaTime;
                }
                else if (Direction == EnemyDirection.ToRight)
                {
                    X += movingSpeed / 100 * deltaTime;
                }
                EnableAnimation = true;

                beam = null;
            }
            else
            {
                bool forceField = typeof(Forcefield).IsInstanceOfType(target);

                if (beam == null)
                {
                    int beamX;
                    int beamY = Math.Max((int)Y + Height / 2, (int)target.Y + target.Height / 2);
                    int beamTargetX;

                    if (direction == EnemyDirection.ToLeft)
                    {
                        if (forceField)
                        {
                            beamX       = (int)target.X + target.Width;
                            beamTargetX = (int)X;
                        }
                        else
                        {
                            beamX       = (int)X;
                            beamTargetX = (int)target.X + target.Width;
                        }
                    }
                    else
                    {
                        if (forceField)
                        {
                            beamX       = (int)target.X;
                            beamTargetX = (int)X + Width;
                        }
                        else
                        {
                            beamX       = (int)X + Width;
                            beamTargetX = (int)target.X;
                        }
                    }

                    beam = new Electrobeam(content, beamX, beamY, beamTargetX, forceField);
                }

                if (attackCooldown >= 1000f / attackSpeed)
                {
                    target.InflictDamage(attackPower);

                    if (forceField)
                    {
                        healthBar.ColorScheme = HealthBar.HealthBarColoring.Forcefield;
                        healthBar.Health     += attackPower / 2;
                    }
                    else
                    {
                        healthBar.ColorScheme = HealthBar.HealthBarColoring.Normal;
                    }

                    if (healthBar.Health > healthBar.MaxHealth + healthBar.MaxHealth / 2)
                    {
                        healthBar.Health = healthBar.MaxHealth + healthBar.MaxHealth / 2;
                    }

                    attackCooldown = 0;
                }

                EnableAnimation = false;
            }

            if (beam != null)
            {
                beam.Update(deltaTime);
            }
        }