Example #1
0
        /// <summary>
        /// Update.
        /// </summary>
        /// <param name="dt">The delta time.</param>
        /// <param name="gi">The input item if any.</param>
        public override void Update(TimeSpan dt, GenericInput gi)
        {
            if (gi is MouseGenericInput)
            {
                MouseGenericInput mgi = (MouseGenericInput)gi;
                switch (mgi.MouseInputType)
                {
                case MouseGenericInputType.MouseMove:
                {
                    // do hit test
                    if (mgi.X > this.Location.X && mgi.X < this.Location.X + this.Size.Width &&
                        mgi.Y > this.Location.Y && mgi.Y < this.Location.Y + this.Size.Height)
                    {
                        IsHover = true;
                    }
                    else
                    {
                        IsHover = false;
                    }
                }
                break;

                case MouseGenericInputType.MouseClick:
                {
                    if (IsHover)
                    {
                        // raise the event
                        OnButtonClicked(null);
                    }
                }
                break;
                }
            }
        }
Example #2
0
 /// <summary>
 /// Update the scene.
 /// </summary>
 /// <param name="dt">A delta time since the last update.</param>
 /// <param name="gi">A GenericInput to process.</param>
 public override void Update(TimeSpan dt, GenericInput input)
 {
     foreach (GenericItem gi in objects)
     {
         gi.Update(dt, input);
     }
 }
Example #3
0
        /// <summary>
        /// Update the Attack item
        /// </summary>
        /// <param name="dt"> A delta time since the last update was called</param>
        /// <param name="input">A GenericInput to process.</param>
        public override void Update(TimeSpan dt, GenericInput input)
        {
            //on keyboard input determine the Hero's direction
            if (input is GenericKeyboardInput)
            {
                GenericKeyboardInput gki = (GenericKeyboardInput)input;
                DirectionIn = new Vector2(DirectionX, DirectionY);
                DetermineDirection(gki);
                DirectionOut = new Vector2(DirectionX, DirectionY);
                AnimateHero();
            }

            //on mouse click launch an attack
            if (input is MouseGenericInput)
            {
                MouseGenericInput mgi = (MouseGenericInput)input;

                if (mgi.MouseInputType == MouseGenericInput.MouseGenericInputType.MouseClick && (DirectionX * DirectionX + DirectionY * DirectionY) != 0)
                {
                    // create the scene switch message to switch the current scene to the top score scene
                    Message_Attack heroAttack = new Message_Attack("Arrow", this.DirectionX, this.DirectionY, Location, Message_Attack.AttackType.Hero_Arrow, ArrowRange, ArrowDamage);
                    MessageManager.AddMessageItem(heroAttack);
                }
            }
            //update hero location
            SetLocation(dt);
            HealthBar = new Windows.Foundation.Rect(Location.X - 10, Location.Y - 10, 50, 5);
        }
Example #4
0
 /// <summary>
 /// Add a GenericInput into the InputQueque.
 /// </summary>
 /// <param name="gi">A GenericInput to add to the Queque.</param>
 /// <returns>Returns true if the GenericInput has been inserted successfully, else false.</returns>
 public static bool AddInputItem(GenericInput gi)
 {
     lock (input_queue_lock)
     {
         int count_before_add = InputQueue.Count;
         InputQueue.Enqueue(gi);
         int count_after_add = InputQueue.Count;
         return(count_after_add > count_before_add);
     }
 }
Example #5
0
        public override void Update(TimeSpan dt, GenericInput input)
        {
            base.Update(dt, input);

            SpawnTimer = DateTime.Now - LastSpawn;
            if (SpawnTimer.TotalMilliseconds > TimeBetweenSpawns)
            {
                Message_SpawnMinions spawn = new Message_SpawnMinions(Level);
                MessageManager.AddMessageItem(spawn);
                LastSpawn = DateTime.Now;
            }
        }
Example #6
0
//        private static object message_queue_lock = new object();

        /// <summary>
        /// Returns the current GenericInput for processing.
        /// </summary>
        /// <returns>A GenericInput that needs to be process, null if the InputQueque is empty.</returns>
        public static GenericInput Update()
        {
            lock (input_queue_lock)
            {
                if (InputQueue.Count == 0)
                {
                    return(null);
                }
                else
                {
                    GenericInput gi = InputQueue.Dequeue();

                    if (gi is MouseGenericInput)
                    {
                        MouseGenericInput mgi = (MouseGenericInput)gi;

                        if (MouseGenericInputType.MousePressed == mgi.MouseInputType)
                        {
                            IsMouseDown = true;
                        }
                        else if (MouseGenericInputType.MouseReleased == mgi.MouseInputType)
                        {
                            if (IsMouseDown)
                            {
                                MouseGenericInput mouse_click_event = new MouseGenericInput(mgi.X, mgi.Y);
                                mouse_click_event.MouseInputType = MouseGenericInputType.MouseClick;
                                InputManager.AddInputItem(mouse_click_event);
                            }

                            IsMouseDown = false;
                        }
                    }
                    if (gi is GenericKeyboardInput)
                    {
                        GenericKeyboardInput ki = (GenericKeyboardInput)gi;
                        IsWKeyPress = ki.IsWKeyPress;
                        IsAKeyPress = ki.IsAKeyPress;
                        IsSKeyPress = ki.IsSKeyPress;
                        IsDKeyPress = ki.IsDKeyPress;
                    }

                    return(gi);
                }
            }
        }
Example #7
0
        /// <summary>
        /// Update the Attack item
        /// </summary>
        /// <param name="dt"> A delta time since the last update was called</param>
        /// <param name="input">A GenericInput to process.</param>
        public override void Update(TimeSpan dt, GenericInput input)
        {
            //boss moves towards hero
            HeroDirectionVector();

            //boss attacks on a timer
            TimeSinceAttack = DateTime.Now - LastAttack;

            if (TimeSinceAttack.TotalMilliseconds > TimeBetweenAttacks)
            {
                Message_Attack VillainAttack = new Message_Attack("Villain_Attack", DirectionX, DirectionY, this.Location, Message_Attack.AttackType.Minion_Arrow, Range, Damage);
                MessageManager.AddMessageItem(VillainAttack);
                LastAttack = DateTime.Now;
            }

            //Update bosses location on call to update
            SetLocation(dt);
        }
Example #8
0
        public static GenericInput PeekAndTake(Type t)
        {
            lock (input_queue_lock)
            {
                if (InputQueue.Count <= 0)
                {
                    return(null);
                }

                GenericInput gi = InputQueue.Peek();
                if (gi.GetType() == t)
                {
                    return(Update());
                }
                else
                {
                    return(null);
                }
            }
        }
Example #9
0
 /// <summary>
 /// Update the Attack item
 /// </summary>
 /// <param name="dt"> A delta time since the last update was called</param>
 /// <param name="input">A GenericInput to process.</param>
 public override void Update(TimeSpan dt, GenericInput input)
 {
     UpdateLocation(dt);
 }
Example #10
0
 public override void Update(TimeSpan dt, GenericInput input)
 {
     base.Update(dt, input);
 }
Example #11
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;
            }
        }
Example #12
0
 /// <summary>
 /// Update.
 /// </summary>
 /// <param name="dt">The delta time.</param>
 /// <param name="gi">The input item if any.</param>
 public override void Update(TimeSpan dt, GenericInput gi)
 {
     base.Update(dt, gi);
 }
Example #13
0
        /// <summary>
        /// Update the scene based on inputs
        /// </summary>
        /// <param name="dt"> A delta time since the last update was called </param>
        /// <param name="input"> Generic input </param>
        public override void Update(TimeSpan dt, GenericInput input)
        {
            if (mp.PlaybackSession.PlaybackState != MediaPlaybackState.Playing)
            {
                mp.PlaybackSession.Position = TimeSpan.Zero;
                mp.Play();
            }

            foreach (Hero hero in heros)
            {
                //update each generic item
                hero.Update(dt, input);
            }
            foreach (Villain villain in villains)
            {
                villain.Update(dt, input);
                //reset the bosses hit image to default image after 300ms of no hits
                if (villain is Boss)
                {
                    villain.TimeSinceCollision = DateTime.Now - villain.LastCollision;
                    if (villain.TimeSinceCollision.TotalMilliseconds > 300 && villain.HurtImage)
                    {
                        villain.SetBitmapFromImageDictionary("Boss");
                    }
                }
                //update the hero's location to each villain
                foreach (Hero hero in heros)
                {
                    villain.HeroLocation = hero.Location;
                }
            }
            foreach (GenericItem gi in objects)
            {
                //update each generic item
                gi.Update(dt, input);

                //find out if any of the attacks hit the villains or hero
                if (gi is Attack)
                {
                    Attack attack = (Attack)gi;
                    switch (attack.Type)
                    {
                    case (Attack.AttackType.Hero_Arrow):
                    {
                        foreach (Villain villain in villains)
                        {
                            var villainRect = villain.BoundingRectangle;
                            villainRect.Intersect(gi.BoundingRectangle);

                            if (!villainRect.IsEmpty)
                            {
                                villain.TimeSinceCollision = DateTime.Now - villain.LastCollision;
                                if (villain.TimeSinceCollision.TotalMilliseconds > villain.iFrames)
                                {
                                    Message_Collision villain_collision = new Message_Collision("Arrow", gi, villain);
                                    MessageManager.AddMessageItem(villain_collision);
                                    villain.LastCollision = DateTime.Now;
                                    if (villain is Boss)
                                    {
                                        villain.SetBitmapFromImageDictionary("BossHurt");
                                        villain.HurtImage = true;
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case (Attack.AttackType.Boss_Arrow):
                    {
                        foreach (Hero hero in heros)
                        {
                            var heroRect = hero.BoundingRectangle;
                            heroRect.Intersect(gi.BoundingRectangle);

                            if (!heroRect.IsEmpty)
                            {
                                hero.TimeSinceCollision = DateTime.Now - hero.LastCollision;
                                if (hero.TimeSinceCollision.TotalMilliseconds > hero.iFrames)
                                {
                                    Message_Collision hero_collision = new Message_Collision("Arrow", gi, hero);
                                    MessageManager.AddMessageItem(hero_collision);
                                    hero.LastCollision = DateTime.Now;
                                }
                            }
                        }
                        break;
                    }
                    }
                }
            }
        }
Example #14
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, GenericInput input)
 {
 }