public UFO(float initX, float initY, HorizontalDirection.Name leftOrRight, AudioSource newUfoSound, AudioSource newDeathSound)
            : base()
        {
            SceneManager.Self.ActiveScene.SetUfoId(this.Id);
            this.SetName(Name.UFOCoordinator);
            this.Collider.Color = Colors.Yellow;
            this.SetPosition(initX, initY);

            this.SetColor(Colors.Red);
            this.SetSprite(SpriteBatch.Name.Aliens, SpriteEntityManager.Self.Find(Sprite.Name.UFO));

            // Set the sounds
            this.sndUfo   = newUfoSound;
            this.sndDeath = newDeathSound;

            // Factor the direction of the UFO into the speed
            // The extra -1 is to make sure left-spawned UFOs go right, and vice versa
            this.speed *= HorizontalDirection.ConvertToFloat(leftOrRight) * -1.0f;
        }
Exemplo n.º 2
0
        /// <summary>
        ///		Create a new UFO, does NOT schedule anything
        /// </summary>
        private void SpawnNewUFO()
        {
            // Decide randomly whether to spawn the UFO left or right
            HorizontalDirection.Name leftOrRight = HorizontalDirection.ConvertFromInt(Randomizer.RandomRange(0, 2));
            float xSpawn = 0.0f;

            if (leftOrRight == HorizontalDirection.Name.Left)
            {
                xSpawn = UFOCoordinator.SpawnLeftX;
            }
            else
            {
                xSpawn = UFOCoordinator.SpawnRightX;
            }

            // Create the UFO
            UFO ufo = new UFO(xSpawn, UFOCoordinator.SpawnY, leftOrRight, this.sndUfo, this.sndUfoDeath);

            this.AddChild(ufo);
            GameObjectManager.Active.Attach(ufo);

            // Keep a reference
            ufoReference = ufo;
        }