Esempio n. 1
0
 /// <summary>
 /// Add a GenericMessage into the MessageQueque.
 /// </summary>
 /// <param name="gm">A GenericMessage to add to the Queque.</param>
 /// <returns>Returns true if the GenericMessage has been inserted successfully, else false.</returns>
 public static bool AddMessageItem(GenericMessage gm)
 {
     lock (Message_queue_lock)
     {
         int count_before_add = MessageQueue.Count;
         MessageQueue.Enqueue(gm);
         int count_after_add = MessageQueue.Count;
         return(count_after_add > count_before_add);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Update the StoryBoard.
        /// </summary>
        /// <param name="dt">The delta time.</param>
        /// <param name="input">The input item if any.</param>
        public static bool Update(TimeSpan dt, GenericMessage message)
        {
            // The STORYBOARD should only response to Low Level Game Events like SceneSwitch
            if (message is Message_SceneSwitch)
            {
                if (null != CurrentScene.mp)
                {
                    CurrentScene.mp.Pause();
                    CurrentScene.mp.PlaybackSession.Position = TimeSpan.Zero;
                }

                Message_SceneSwitch mss = message as Message_SceneSwitch;

                // find the scene
                if (SceneDictionary.ContainsKey(mss.TargetScene))
                {
                    // push the scene on to the history
                    SceneHistory.Push(CurrentScene);

                    // switch and kill the message
                    CurrentScene = SceneDictionary[mss.TargetScene];
                    CurrentScene.Reset();

                    if (AudioManager.AudioDictionary.TryGetValue(mss.TargetScene, out CurrentScene.mp))
                    {
                        CurrentScene.mp.Play();
                    }
                }

                return(true);
            }
            else if (message is Message_GoBack)
            {
                // check to see if the history list is empty
                if (SceneHistory.Count == 0)
                {
                    //Do nothing
                }
                else
                {
                    // Pop the scene from the history list and set it as the current scene
                    CurrentScene = SceneHistory.Pop();
                    CurrentScene.Reset();
                }

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns the current GenericMessage for processing.
        /// </summary>
        /// <returns>A GenericMessage that needs to be process, null if the MessageQueque is empty.</returns>
        public static GenericMessage Update()
        {
            lock (Message_queue_lock)
            {
                if (MessageQueue.Count == 0)
                {
                    return(null);
                }
                else
                {
                    GenericMessage gm = MessageQueue.Dequeue();

                    return(gm);
                }
            }
        }
Esempio n. 4
0
        public static GenericMessage PeekAndTake(Type t)
        {
            lock (Message_queue_lock)
            {
                if (MessageQueue.Count <= 0)
                {
                    return(null);
                }

                GenericMessage gm = MessageQueue.Peek();
                if (gm.GetType() == t)
                {
                    return(Update());
                }
                else
                {
                    return(null);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Update timer for the game, this should run 120 times a second (default).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void UpdateTimer_Tick(object sender, object e)
        {
            if (!IsUpdating)
            {
                IsUpdating = true;
                //find delta t
                TimeSpan dt = DateTime.Now - LastUpdateTime;

                //Update LastUpdateTime
                LastUpdateTime = DateTime.Now;

                //Update the total app time
                TotalAppTime += dt;

                //get the current input from the input manager
                GenericInput   gi = InputManager.Update();
                GenericMessage gm = MessageManager.Update();

                if (StoryBoard.Update(dt, gm))
                {
                }
                else
                {
                    if (null != StoryBoard.CurrentScene)
                    {
                        StoryBoard.CurrentScene.Update(dt, gi);
                        StoryBoard.CurrentScene.Update(dt, gm);
                        gi = InputManager.PeekAndTake(typeof(MouseGenericInput));
                        while (gi is MouseGenericInput)
                        {
                            StoryBoard.CurrentScene.Update(TimeSpan.Zero, gi);
                            gi = InputManager.PeekAndTake(typeof(MouseGenericInput));
                        }
                        gm = MessageManager.PeekAndTake(typeof(Message_Attack));
                        while (gm is Message_Attack)
                        {
                            StoryBoard.CurrentScene.Update(TimeSpan.Zero, gm);
                            gm = MessageManager.PeekAndTake(typeof(Message_Attack));
                        }
                        gi = InputManager.PeekAndTake(typeof(Message_Collision));
                        while (gm is Message_Collision)
                        {
                            StoryBoard.CurrentScene.Update(TimeSpan.Zero, gm);
                            gm = MessageManager.PeekAndTake(typeof(Message_Collision));
                        }
                    }
                }

                //Figure out if we need to refresh the screen
                TimeSpan dt_Draw = DateTime.Now - LastDrawTime;
                if (dt_Draw.Milliseconds > TimeBetweenDraw.Milliseconds)
                {
                    //call refresh
                    if (null != ParentCanvas)
                    {
                        ParentCanvas.Invalidate();
                        LastDrawTime = DateTime.Now;
                    }
                }

                IsUpdating = false;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Updates the scene based on incoming messages
        /// </summary>
        /// <param name="dt">Delta time since thew last update was called</param>
        /// <param name="message"> incoming message</param>
        public override void Update(TimeSpan dt, GenericMessage message)
        {
            foreach (GenericItem gi in objects)
            {
                //update each generic item
                gi.Update(dt, message);
            }
            foreach (Hero hero in heros)
            {
                //update each generic item
                hero.Update(dt, message);
            }
            foreach (Villain villain in villains)
            {
                //update each generic item
                villain.Update(dt, message);
            }

            if (message is Message_Attack)
            {
                Message_Attack mhe = (Message_Attack)message;

                switch (mhe.Type)
                {
                case (Message_Attack.AttackType.Hero_Arrow):
                {
                    //(Terry)TODO: add rotation to arrows, this might require using something other than CanvasBitmap images
                    Attack attack = new Attack(mhe.Name, mhe.DirectionX, mhe.DirectionY, mhe.Location, Attack.AttackType.Hero_Arrow, mhe.Range, mhe.Damage);
                    attack.SetBitmapFromImageDictionary("Arrow");
                    this.AddObject(attack);
                    break;
                }

                case (Message_Attack.AttackType.Minion_Arrow):
                {
                    Attack arrow = new Attack(mhe.Name, mhe.DirectionX, mhe.DirectionY, mhe.Location, Attack.AttackType.Boss_Arrow, mhe.Range, mhe.Damage);
                    arrow.SetBitmapFromImageDictionary("Arrow");
                    this.AddObject(arrow);
                    break;
                }
                }
            }

            //if two generic items on the canvas have collided find out what collided and apply aprpriate damage
            if (message is Message_Collision)
            {
                Message_Collision attackInfo = (Message_Collision)message;

                if (attackInfo.CollisionObject is Attack)
                {
                    Attack attack = (Attack)attackInfo.CollisionObject;

                    //if the boss is hit by an attack, increase score, reduce bosses health and remove the attack
                    if (attackInfo.Victim is Boss)
                    {
                        Boss boss = (Boss)attackInfo.Victim;
                        boss.CurrentHealth -= attack.Damage;
                        Score += attack.Damage;
                        _score_label.UpdateText("SCORE: " + Score);
                        objects.Remove(attackInfo.CollisionObject);

                        if (boss.CurrentHealth <= 0.0f)
                        {
                            boss.Level        += 1;
                            boss.MaxHealth    += 100;
                            boss.CurrentHealth = boss.MaxHealth;
                        }
                    }
                    // if the attack hit a minion, remove the attack and the minion
                    else if (attackInfo.Victim is Villain)
                    {
                        Villain villain = (Villain)attackInfo.Victim;
                        villains.Remove(villain);
                        objects.Remove(attackInfo.CollisionObject);
                    }
                    //if the attack hit the hero, reduce hero's health and check for game over
                    else if (attackInfo.Victim is Hero)
                    {
                        Hero hero = (Hero)attackInfo.Victim;
                        hero.CurrentHealth -= attack.Damage;
                        objects.Remove(attackInfo.CollisionObject);
                        if (hero.CurrentHealth <= 0)
                        {
                            heros.Remove(hero);
                            //add tombstone image where hero died?
                            // If all heroes (spelled correctly this time) have died it's game over
                            if (heros.Count <= 0)
                            {
                                game_over = true;
                            }
                        }
                    }
                }
            }
            // switch to game over scene
            if (game_over)
            {
                Message_SceneSwitch mss = new Message_SceneSwitch("Game Over Scene");
                MessageManager.AddMessageItem(mss);
            }

            if (message is Message_SpawnMinions)
            {
                Message_SpawnMinions spawn = (Message_SpawnMinions)message;
                Random r = new Random();
                for (int i = 0; i < spawn.NumberOfMinions; i++)
                {
                    Villain villain = new Villain("minion");
                    villain.Location = new System.Numerics.Vector2(r.Next(0, _width), r.Next(0, _height));
                    villain.SetBitmapFromImageDictionary("MinionLeft");
                    this.AddObject(villain);
                }
            }
        }
Esempio n. 7
0
 ///<summary>
 ///Update the GenericItem
 ///</summary>
 ///<param name= "dt"> A delta time since the last update was called.</param>
 public virtual void Update(TimeSpan dt, GenericMessage message)
 {
 }