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;
                }
                MosCraciun(false);
            }
            else
            {
                MosCraciun(true);
                if ((attackCooldown >= 1000f / attackSpeed) ||
                    (burstFire && (currentBurstProjectile < burstFireAmmount)) && (attackCooldown >= 1000f / burstFireSpeed))
                {
                    if (burstFire)
                    {
                        ++currentBurstProjectile;
                        if (attackCooldown >= 1000f / attackSpeed)
                        {
                            currentBurstProjectile = 1;
                        }
                    }

                    double projectileX;
                    float  projectileDirection = (float)((GameManager.RNG.NextDouble() - .5f) * Math.PI / precision);
                    if (direction == EnemyDirection.ToLeft)
                    {
                        projectileX          = X;
                        projectileDirection += (float)Math.PI;
                    }
                    else
                    {
                        projectileX = X + Width;
                        //projectileDirection = 0;
                    }
                    EnemyProjectile p = new EnemyProjectile(content, projectileX, Y + Height / 2, projectileDirection, attackPower, laserAssetName);
                    attackCooldown = 0;
                    if (attackSound != null)
                    {
                        SoundManager.PlayClip(attackSound);
                    }
                }
            }
        }
示例#2
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;
        }