Example #1
0
        void updateKeyboard()
        {
            KeyboardState state = Keyboard.GetState();

            Keys[] pressed = state.GetPressedKeys();
            if (pressed.Length > 0)
            {
                activeInput = ActiveInput.Keyboard;
            }
            Keys[] handledKeys = keys.Keys.ToArray <Keys>();
            foreach (Keys k in handledKeys)
            {
                if (pressed.Contains(k) && keys[k])
                {
                    keys[k] = false;
                }
                else if (!pressed.Contains(k))
                {
                    keys.Remove(k);
                }
            }
            foreach (Keys k in pressed)
            {
                if (!keys.Keys.Contains(k))
                {
                    keys[k] = true;
                }
            }
        }
Example #2
0
 private void pickupSetFromInput(ActiveInput input)
 {
     holdingSet = true;
     heldSet    = input.RemoveSet();
     heldSet.transform.position = ((Vector2)gameObject.transform.position + new Vector2(0, 0.5f));
     FindObjectOfType <AudioManagerController>().Play("PickUp");
     pickedUp = true;
 }
Example #3
0
 public void UpdatePlayerIsActive()
 {
     if (!this.IsActive)
     {
         if (ActiveInput.GetFire())
         {
             this.IsActive = true;
         }
     }
 }
Example #4
0
        public void UpdatePlayerPosition()
        {
            float inputX = ActiveInput.GetX();
            float inputY = ActiveInput.GetY();

            float newPosX = 0.0f;
            float newPosY = 0.0f;

            float time = (float)Settings.Instance.GameTime.ElapsedGameTime.TotalSeconds;
            float speed;
            float distanceX;
            float distanceY;

            if (ActiveInput is GamepadInput)
            {
                speed     = ((GamepadInput)ActiveInput).ScrollSpeed;
                distanceX = time * inputX * speed;
                distanceY = time * inputY * speed;
                newPosX   = this.Position.X + (distanceX);
                newPosY   = this.Position.Y - (distanceY);
            }
#if !XBOX
            else if (ActiveInput is KeyboardInput)
            {
                speed     = ((KeyboardInput)ActiveInput).ScrollSpeed;
                distanceX = time * inputX * speed;
                distanceY = time * inputY * speed;
                newPosX   = this.Position.X + (distanceX);
                newPosY   = this.Position.Y + (distanceY);
            }

            //ScreenSize.X = 1280 (basemode) even if rez is changed to 640
            //but Mouse.GetState() will change if rez changed therefore maxing at 640
            //have to relativize newPosX to inputX and screen difference
            else if (ActiveInput is MouseInput)
            {
                int baseWidth     = (int)Settings.Instance.ScreenSize.X;
                int baseHeight    = (int)Settings.Instance.ScreenSize.Y;
                int currentWidth  = Settings.Instance.Resolution.ScreenWidth;
                int currentHeight = Settings.Instance.Resolution.ScreenHeight;
                newPosX = (inputX / currentWidth) * baseWidth;
                newPosY = (inputY / currentHeight) * baseHeight;
            }
            else if (ActiveInput is WiiInput)
            {
                newPosX = inputX * (float)Settings.Instance.ScreenSize.X;
                newPosY = inputY * (float)Settings.Instance.ScreenSize.Y;
            }
#endif

            newPosX       = MathHelper.Clamp(newPosX, 0.0f, Settings.Instance.ScreenSize.X);
            newPosY       = MathHelper.Clamp(newPosY, 0.0f, Settings.Instance.ScreenSize.Y);
            this.Position = new Vector2(newPosX, newPosY);
        }
Example #5
0
 public void UpdatePauseState()
 {
     if (ActiveInput.GetPause())
     {
         if (!this.IsPaused)
         {
             this.IsPaused = true;
         }
     }
     else
     {
         this.IsPaused = false;
     }
 }
Example #6
0
    void collideRoutine(List <Collider2D> collisions)
    {
        Collider2D collision = getCollider(collisions);

        if (collision.tag == "Input")
        {
            ActiveInput input = collision.GetComponent <ActiveInput>();
            // placing a set into an input
            if (Input.GetKeyDown(KeyCode.Space) && holdingSet)
            {
                holdingSet = false;
                SetController currentSet = heldSet;
                // in case there's an old set in the input
                if (input.holdsSet())
                {
                    pickupSetFromInput(input);
                }
                input.PlaceSet(currentSet);

                // picking up a set from the input
            }
            else if (Input.GetKeyDown(KeyCode.Space) && !holdingSet)
            {
                if (input.holdsSet())
                {
                    pickupSetFromInput(input);
                }
            }
            // picking up a set
        }
        else if (collision.tag == "Set")
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                SetController nextSet = collision.GetComponent <SetController>();
                if (holdingSet)
                {
                    heldSet.transform.position = gameObject.transform.position;
                }
                heldSet = nextSet;
                heldSet.transform.position = (Vector2)gameObject.transform.position + new Vector2(0, 0.5f);
                holdingSet = true;
                pickedUp   = true;
                FindObjectOfType <AudioManagerController>().Play("PickUp");
            }
        }
    }
Example #7
0
 public void UpdateFiringState()
 {
     if (ActiveInput.GetFire())
     {
         if (CanFire)
         {
             IsFiring = true;
             CanFire  = false;
             //LastFireTime = References.Settings.Instance.GameTime.TotalGameTime.Seconds;
         }
         else
         {
             IsFiring = false;
         }
     }
     else
     {
         CanFire  = true;
         IsFiring = false;
     }
 }
Example #8
0
        void updateGamepad(int n, GamePadState state)
        {
            Dictionary <Buttons, bool> gamepad        = gamepads[n];
            List <Buttons>             handledButtons = new List <Buttons>(gamepad.Keys);

            if (!state.IsConnected) // no buttons pressed because controller isn't plugged in
            {
                foreach (Buttons b in handledButtons)
                {
                    gamepad.Remove(b);
                }
                return;
            }

            // Analog sticks
            stickPositions[n]     = state.ThumbSticks.Left;
            stickPositions[n + 1] = state.ThumbSticks.Right;

            foreach (Buttons tb in TRACKED_BUTTONS)
            {
                if (state.IsButtonDown(tb))
                {
                    activeInput = ActiveInput.Gamepad;
                    if (handledButtons.Contains(tb) && gamepad[tb])
                    {
                        gamepad[tb] = false;
                    }
                    else if (!handledButtons.Contains(tb))
                    {
                        gamepad[tb] = true;
                    }
                }
                else
                {
                    gamepad.Remove(tb);
                }
            }
        }