/// <summary>
        /// Runs when the BuzzardDropEgg fires. It creates an Egg object
        /// and sends it in the direction the Buzzard was going. The graphic
        /// is changed to just the Buzzard as it flies to the left of the screen
        /// and disappears.
        /// </summary>
        public void NotifyDrop(object sender, EventArgs e)
        {
            Buzzard buzzard = sender as Buzzard;
            // Create a new Egg
            Egg egg = new Egg();

            egg.coords = buzzard.coords;
            egg.speed  = buzzard.speed;

            if (buzzard.angle > 90 && buzzard.angle < 270)
            {
                egg.stateMachine.Change("fall_left");
            }
            else if (buzzard.angle > 270 && buzzard.angle < 90)
            {
                egg.stateMachine.Change("fall_right");
            }
            else
            {
                egg.stateMachine.Change("fall");
            }

            // Create a new EggControl
            EggControl eCtrl = new EggControl(egg.imagePath);

            // Subscribe to the event handlers
            egg.EggMoveEvent   += eCtrl.NotifyMoved;
            egg.EggStateChange += eCtrl.NotifyState;
            egg.EggHatched     += eCtrl.NotifyHatch;
            egg.EggDestroyed   += eCtrl.NotifyDestroy;

            Canvas.SetTop(eCtrl, egg.coords.y);
            Canvas.SetLeft(eCtrl, egg.coords.x);
            Canvas canvas = Parent as Canvas;

            canvas.Children.Add(eCtrl);
            Task.Run(() => {
                PlaySounds.Instance.Play_Drop();
            });
        }
Exemple #2
0
        /// <summary>
        /// Runs when the BuzzardDropEgg fires. It creates an Egg object
        /// and sends it in the direction the Buzzard was going. The graphic
        /// is changed to just the Buzzard as it flies to the left of the screen
        /// and disappears.
        /// </summary>
        public void NotifyDrop(object sender, EventArgs e)
        {
            Buzzard buzzard = sender as Buzzard;
            // Create a new Egg
            Egg egg = new Egg();

            egg.coords = buzzard.coords;

            // Set to a downwards angle
            if (buzzard.angle > 180)
            {
                egg.angle = buzzard.angle;
            }
            else
            {
                egg.angle = buzzard.angle + 180;
            }
            egg.speed = buzzard.speed;
            egg.state = new EnemyFallingState()
            {
                Angle = buzzard.state.Angle, StateEnemy = egg
            };

            // Create a new EggControl
            EggControl eCtrl = new EggControl(egg.imagePath);

            // Subscribe to the event handlers
            egg.EggMoveEvent   += eCtrl.NotifyMoved;
            egg.EggStateChange += eCtrl.NotifyState;
            egg.EggHatched     += eCtrl.NotifyHatch;
            egg.EggDestroyed   += eCtrl.NotifyDestroy;

            Canvas.SetTop(eCtrl, egg.coords.y);
            Canvas.SetLeft(eCtrl, egg.coords.x);
            Canvas canvas = Parent as Canvas;

            canvas.Children.Add(eCtrl);
        }
Exemple #3
0
        public void WorldObjectControlFactory(WorldObject worldObject)
        {
            string woString = worldObject.ToString();
            Image  i;

            switch (woString)
            {
            case "Ostrich":
                Ostrich o = worldObject as Ostrich;
                i = new OstrichControl(o.imagePath);
                OstrichControl oC = i as OstrichControl;
                o.ostrichMoved += oC.NotifyMoved;
                break;

            case "Buzzard":
                Buzzard b = worldObject as Buzzard;
                i = new BuzzardControl(b.imagePath);
                BuzzardControl bC = i as BuzzardControl;

                // Used to update the view with model updates
                b.BuzzardMoveEvent   += bC.NotifyMoved;
                b.BuzzardStateChange += bC.NotifyState;
                b.BuzzardDropEgg     += bC.NotifyDrop;
                b.BuzzardDestroyed   += bC.NotifyDestroy;
                // Used to update all enemies in the world
                //DispatcherTimer moveTimer = new DispatcherTimer();
                //moveTimer.Interval = new TimeSpan(0, 0, 0, 0, 33);
                //moveTimer.Tick += World.Instance.UpdateAllEnemies_Position;
                //moveTimer.Start();

                /*  Comment:    Clayton Cockrell
                 *  The Random object in Buzzard would give the same random number to all the
                 *  Buzzard objects if their creation was not halted for a little bit of time.
                 */
                Thread.Sleep(20);
                break;

            case "Pterodactyl":
                PterodactylControl pCtrl = new PterodactylControl("Images/Enemy/pterodactyl.fly1");
                i = pCtrl;

                /*  Comment:    Clayton Cockrell
                 *  Pterodactyls spawn after a certain number of minutes. I currently have it set
                 *  to 1 minute. (To change, see PTERODACTYL_SPAWN_MINUTES constant in World class)
                 */
                World.Instance.SpawnPterodactyl += pCtrl.NotifySpawn;
                break;

            case "Egg":
                Egg e = worldObject as Egg;
                i = new EggControl(e.imagePath);
                EggControl eC = i as EggControl;
                break;

            case "Platform":
                Platform pl = worldObject as Platform;
                i = new PlatformControl(pl.imagePath);
                PlatformControl pC = i as PlatformControl;
                break;

            case "Respawn":
                Respawn r = worldObject as Respawn;
                i = new RespawnControl(r.imagePath);
                RespawnControl rC = i as RespawnControl;
                break;

            default:
                Base ba = worldObject as Base;
                i = new BaseControl(ba.imagePath);
                BaseControl baC = i as BaseControl;
                break;
            }
            canvas.Children.Add(i);
            Canvas.SetTop(i, worldObject.coords.y);
            Canvas.SetLeft(i, worldObject.coords.x);

            //Title_Screen(null, EventArgs.Empty);
            //Finish_HighScores(null, EventArgs.Empty);
            // called when game end conditions have been met
        }