Beispiel #1
0
        /// <summary>
        /// Runs when the EggHatched fires. It updates the graphic
        /// of the Control to a hatched Mik and creates a Buzzard to
        /// pick up the Mik.
        /// </summary>
        public void NotifyHatch(object sender, EventArgs e) {
            Egg egg = sender as Egg;

            Point p = new Point(0, egg.coords.y - 70);
            // Create a new Buzzard
            Buzzard b = new Buzzard();
            b.coords = p;
            b.angle = 0;
            b.droppedEgg = true;
            // Set state to Pickup state
            b.state = new BuzzardPickupState() { Angle = (int)b.angle, TargetEgg = egg, StateEnemy = b };
            b.state.Setup();
            // Create a new BuzzardControl
            BuzzardControl eCtrl = new BuzzardControl(b.imagePath);
            // Subscribe to event handlers
            b.BuzzardMoveEvent += eCtrl.NotifyMoved;
            b.BuzzardStateChange += eCtrl.NotifyState;
            b.BuzzardDropEgg += eCtrl.NotifyDrop;
            b.BuzzardDestroyed += eCtrl.NotifyDestroy;

            Canvas.SetTop(eCtrl, b.coords.y);
            Canvas.SetLeft(eCtrl, b.coords.x);
            Canvas canvas = Parent as Canvas;
            canvas.Children.Add(eCtrl);
        }
Beispiel #2
0
        /// <summary>
        /// Runs when the EggHatched fires. It updates the graphic
        /// of the Control to a hatched Mik and creates a Buzzard to
        /// pick up the Mik.
        /// </summary>
        public void NotifyHatch(object sender, EventArgs e)
        {
            Egg egg = sender as Egg;

            int spawnX = 0;
            int spawnY = 0;

            Console.WriteLine("SpawnPoints = " + World.Instance.SpawnPoints.Count); //egg crash???
            int randNum = new Random().Next(World.Instance.SpawnPoints.Count - 1);

            Point[] pArray = World.Instance.SpawnPoints[randNum];

            spawnX = (int)(((pArray[1].x - pArray[0].x) / 2) + (pArray[0].x - 10));
            spawnY = (int)pArray[0].y;

            Point p = new Point(spawnX, spawnY);
            // Create a new Buzzard
            Buzzard b = new Buzzard();

            b.coords     = p;
            b.angle      = 0;
            b.droppedEgg = true;
            // Set state to Pickup state
            b.stateMachine.Change("spawn");
            b.pickupEgg = egg;
            b.stateMachine.currentState.Update();
            // Create a new BuzzardControl
            BuzzardControl eCtrl = new BuzzardControl(b.imagePath);

            // Subscribe to event handlers
            b.BuzzardMoveEvent   += eCtrl.NotifyMoved;
            b.BuzzardStateChange += eCtrl.NotifyState;
            b.BuzzardDropEgg     += eCtrl.NotifyDrop;
            b.BuzzardDestroyed   += eCtrl.NotifyDestroy;

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

            canvas.Children.Add(eCtrl);
        }
Beispiel #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
        }