Example #1
0
        /// <summary>
        /// Runs when the World.Instance.SpawnPterodactyl fires. It creates the
        /// Pterodactyls.
        /// </summary>
        public void NotifySpawn(object sender, EventArgs e)
        {
            if (!spawned)
            {
                Pterodactyl p = new Pterodactyl();
                p.coords = new Point(0, 0); // *** Set this to a respawn platform ***
                PterodactylControl pCtrl = new PterodactylControl(p.imagePath);

                // Subscribe to the event handlers
                p.PterodactylMoveEvent   += pCtrl.NotifyMoved;
                p.PterodactylStateChange += pCtrl.NotifyState;
                p.PterodactylDestroyed   += pCtrl.NotifyDestroy;

                Canvas.SetTop(pCtrl, p.coords.y);
                Canvas.SetLeft(pCtrl, p.coords.x);
                Canvas canvas = Parent as Canvas;
                canvas.Children.Add(pCtrl);
                spawned = true;
            }
        }
Example #2
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
        }