예제 #1
0
파일: Cursor.cs 프로젝트: kjin/TubeRacer
 public bool Cyclable(InputControl control)
 {
     return control.JustPressed || (control.ActiveTime > cycleDelay && (control.ActiveTime - cycleDelay) % cycleInterval == 0);
 }
예제 #2
0
        /// <summary>
        /// Constructs a new InputController.
        /// </summary>
        /// <param name="assets">The AssetManager object used in the game.</param>
        public InputController(AssetManager assets)
        {
            controllerConnected = GamePad.GetState(PlayerIndex.One).IsConnected;
            TextDictionary dict = new TextDictionary(assets.GetText("controls"));
            controls = new InputControl[controlNames.Length];
            for (int i = 0; i < controls.Length; i++)
            {
                controls[i] = new InputControl();
                if (dict.CheckObjectExists(controlNames[i]))
                {
                    if (dict.CheckPropertyExists(controlNames[i], "key"))
                    {
                        Keys key = (Keys)Enum.Parse(typeof(Keys), dict.LookupString(controlNames[i], "key"));
                        controls[i].AddKey(key);
                    }
                    else
                    {
                        int j = 0;
                        while (dict.CheckPropertyExists(controlNames[i], "key" + j))
                        {
                            Keys key = (Keys)Enum.Parse(typeof(Keys), dict.LookupString(controlNames[i], "key" + j));
                            controls[i].AddKey(key);
                            j++;
                        }
                    }
                    if (dict.CheckPropertyExists(controlNames[i], "button"))
                    {
                        Buttons button = (Buttons)Enum.Parse(typeof(Buttons), dict.LookupString(controlNames[i], "button"));
                        controls[i].AddButton(button);
                    }
                    else
                    {
                        int j = 0;
                        while (dict.CheckPropertyExists(controlNames[i], "button" + j))
                        {
                            Buttons button = (Buttons)Enum.Parse(typeof(Buttons), dict.LookupString(controlNames[i], "button" + j));
                            controls[i].AddButton(button);
                            j++;
                        }
                    }
                    if (dict.CheckPropertyExists(controlNames[i], "leftjoystick"))
                    {
                        Vector2 dir = dict.LookupVector2(controlNames[i], "leftjoystick");
                        controls[i].SetLeftJoystick(dir);
                    }
                    if (dict.CheckPropertyExists(controlNames[i], "rightjoystick"))
                    {
                        Vector2 dir = dict.LookupVector2(controlNames[i], "rightjoystick");
                        controls[i].SetRightJoystick(dir);
                    }
                    if (dict.CheckPropertyExists(controlNames[i], "lefttrigger"))
                    {
                        bool activated = dict.LookupBoolean(controlNames[i], "lefttrigger");
                        controls[i].SetLeftTrigger(activated);
                    }
                    if (dict.CheckPropertyExists(controlNames[i], "righttrigger"))
                    {
                        bool activated = dict.LookupBoolean(controlNames[i], "righttrigger");
                        controls[i].SetRightTrigger(activated);
                    }
                }
            }

            var keyNames = Enum.GetValues(typeof(Keys));
            allKeys = new InputControl();
            foreach (Keys key in keyNames)
                allKeys.AddKey(key);
            allKeys.AddButton(Buttons.A);
            allKeys.AddButton(Buttons.B);
            allKeys.AddButton(Buttons.Back);
            allKeys.AddButton(Buttons.LeftShoulder);
            allKeys.AddButton(Buttons.LeftTrigger);
            allKeys.AddButton(Buttons.RightShoulder);
            allKeys.AddButton(Buttons.RightTrigger);
            allKeys.AddButton(Buttons.Start);
            allKeys.AddButton(Buttons.X);
            allKeys.AddButton(Buttons.Y);
        }