Example #1
0
        public override void Update(GameTime time)
        {
            // Update gameobjects
            base.Update(time);

            if (isPlayerFocused)
            {
                // key listeners
                foreach (var listener in keyListeners)
                {
                    listener.Update(time);
                }

                // physics
                phys.ApplyPhysics(player.Props, player, time);

                foreach (var p in GameObjects.OfType <Projectile>())
                {
                    phys.ApplyPhysics(p.Props, p, time);
                }
            }

            if (!startGameTimer.Completed)
            {
                startGameTimer.Update(time.ElapsedGameTime.Milliseconds);
            }

            if (!isPlayerFocused && startGameTimer.Completed)
            {
                isPlayerFocused = true;
                Camera.SetFocus(player, immediateFocus: false);
            }
        }
Example #2
0
        public void Update(GameTime time)
        {
            //capture keyboard state
            kbstate_current = Keyboard.GetState();

            //this stalls the listener slightly at the beginning
            //to combat picking up keydowns that are still being
            //pressed from previous game screens
            if (initialCooldown.Completed == false)
            {
                initialCooldown.Update(time.ElapsedGameTime.Milliseconds);
                return;
            }

            //repeatedly fire while key down
            //(zero cooldown specified)
            if (rapidFire)
            {
                //fire away
                if (kbstate_current.IsKeyDown(Key))
                {
                    signal();
                }

                //no need to continue method
                return;
            }

            //no cooldown and no rapid file
            //signal does not re-fire until keyup
            if (singlePress)
            {
                if (kbstate_current.IsKeyDown(Key) && singlePress_keyBeingPressed == false)
                {
                    singlePress_keyBeingPressed = true;
                    signal();
                }
                else if (kbstate_current.IsKeyUp(Key) && singlePress_keyBeingPressed == true)
                {
                    singlePress_keyBeingPressed = false;
                }

                //no need to continue method
                return;
            }

            //if cooled down check keydown
            if (coolDownTimer.Completed)
            {
                if (kbstate_current.IsKeyDown(Key))
                {
                    coolDownTimer.Reset();
                    signal();

                    //no need to continue method
                    return;
                }
            }
            else
            {
                coolDownTimer.Update(time.ElapsedGameTime.Milliseconds);
            }
        }