static JoyStick() { hasaJoyStick = true; JoystickState jss = JoystickInput.GetAsJoystickState(0); if (!jss.IsConnected) { hasaJoyStick = false; } #region ジョイスティックが無かった場合キーボードのコンフィグ設定 if (!hasaJoyStick) { oldKeyboardState = xnainput.Keyboard.GetState(); KeyboardConfig = new xnainput.Keys[(int)config.NUM_KEY]; KeyboardConfig[(int)config.A] = xnainput.Keys.Z; // □ KeyboardConfig[(int)config.B] = xnainput.Keys.X; // △ KeyboardConfig[(int)config.key3] = xnainput.Keys.C; // ○ KeyboardConfig[(int)config.X] = xnainput.Keys.A; // × KeyboardConfig[(int)config.Y] = xnainput.Keys.F; KeyboardConfig[(int)config.key6] = xnainput.Keys.V; KeyboardConfig[(int)config.MENU] = xnainput.Keys.LeftShift; KeyboardConfig[(int)config.LOCK] = xnainput.Keys.Space; //Space;//TODO:コンフィグが俺コントローラ仕様すぎるから変えないと。。 KeyboardConfig[(int)config.START] = xnainput.Keys.Enter; // 追加 } #endregion }
static void JoystickUpdate(int deviceID, double dt) { JoystickState jss = JoystickInput.GetAsJoystickState(deviceID); curButtons.Clear(); for (int i = 0; i < (int)config.NUM_KEY; i++) { if (!Key[i] && jss.buttonMap[i]) //今押された { curButtons.Add((byte)i); onKeyDown[i] = true; onKeyUp[i] = false; continue; //今押されたって事は、今離されたかどうかなんて聞くまでも無いだろって事で。 } else { onKeyDown[i] = false; } if (Key[i] && !jss.buttonMap[i]) //今離された { onKeyUp[i] = true; keyTime[i] = 0.0; } else { onKeyUp[i] = false; } } for (int i = 0; i < (int)config.NUM_KEY; i++) { if (jss.buttonMap[i]) //古い状態を捨てて新しい状態に切り替える { Key[i] = true; keyTime[i] += dt; } else { Key[i] = false; } } // デバイスIDのアナログの十字の状態、未入力で-1、上が0で時計回りに増加) //int degree = jsStates[deviceID].GetPointOfView()[0]; //if ( degree == -1 ) V.set( 0.0f , 0.0f ); //else V.set((float)Math.Cos((double)xmath.ToRadians(degree/100)),(float)Math.Sin((double)xmath.ToRadians(degree/100))); float axisx = jss.PositionX; //jsStates[deviceID].X; float axisy = jss.PositionY; //jsStates[deviceID].Y; if (jss.PositionX == 0 && jss.PositionY == 0) { if (jss.DPad.Right == xnainput.ButtonState.Pressed) { axisx = 1.0f; } else if (jss.DPad.Left == xnainput.ButtonState.Pressed) { axisx = -1.0f; } if (jss.DPad.Down == xnainput.ButtonState.Pressed) { axisy = -1.0f; } else if (jss.DPad.Up == xnainput.ButtonState.Pressed) { axisy = 1.0f; } } Vector2 oldV = V; V.X = ((Math.Abs(axisx) < PRESSED_THRESHOLD) ? 0.0f : axisx); V.Y = ((Math.Abs(axisy) < PRESSED_THRESHOLD) ? 0.0f : axisy); //普通にセットしちゃってから if (V.Length() != 0) { V.Normalize(); } //加工。TODO:アナログにちゃんと対応するならここを変えないと。 Direction oldDirection = stickDirection; if (V.Y <= -0.7071) //0.7071==√2 { stickDirection = Direction.UP; //上 } else if (V.Y >= 0.7071) { stickDirection = Direction.DOWN; //下 } else if (V.X <= -0.7071) { stickDirection = Direction.LEFT; //左 } else if (V.X >= 0.7071) { stickDirection = Direction.RIGHT; //右 } else { stickDirection = Direction.NEWTRAL; //ニュートラル } if (oldDirection == stickDirection) { stickTime += dt; onStickDirectionChanged = false; } else { stickTime = 0.0; onStickDirectionChanged = true; } }