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

            Building target = CollisionManager.CollidesWithForcefield(this);

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

            if (target != null)
            {
                target.InflictDamage(attackPower);
                Alive = false;
            }
        }
示例#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;
        }