private float GetAxis(OuyaSDK.KeyEnum keyCode, OuyaSDK.OuyaPlayer player) { // Check if we want the *new* SDK input or the example common if (m_useSDKForInput) { // Get the Unity Axis Name for the Unity API string axisName = OuyaSDK.GetUnityAxisName(keyCode, player); // Check if the axis name is valid if (!string.IsNullOrEmpty(axisName)) { //use the Unity API to get the axis value, raw or otherwise float axisValue = Input.GetAxisRaw(axisName); //check if the axis should be inverted if (OuyaSDK.GetAxisInverted(keyCode, player)) { return(-axisValue); } else { return(axisValue); } } } // moving the common code into the sdk via above else { return(OuyaExampleCommon.GetAxis(keyCode, player)); } return(0f); }
public void Update() { if (null == m_texture) { return; } OuyaExampleCommon.UpdateJoysticks(); UpdateTexture(); if (m_timerTexture < DateTime.Now) { m_timerTexture = DateTime.Now + TimeSpan.FromMilliseconds(100); m_texture.SetPixels32(m_pixels); m_texture.Apply(); } if (m_timerText < DateTime.Now) { m_timerText = DateTime.Now + TimeSpan.FromMilliseconds(1000); if (m_label) { UpdateCounts(); m_label.text = string.Format("c={0} | u={1} | {2:F2}%", m_pixelCount, m_updatePixelCount, m_pixelRatio * 100); } } }
protected override float ProcessAxis(Key key, float deadZone) { if (key.map == InputKeyMap.None) { return(base.ProcessAxis(key, deadZone)); } OuyaSDK.OuyaPlayer player = GetPlayer(key); switch (key.axis) { case ButtonAxis.Minus: return(OuyaExampleCommon.GetButton((OuyaSDK.KeyEnum)key.map, player) ? -1.0f : 0.0f); break; case ButtonAxis.Plus: return(OuyaExampleCommon.GetButton((OuyaSDK.KeyEnum)key.map, player) ? 1.0f : 0.0f); break; case ButtonAxis.Both: float val = OuyaExampleCommon.GetAxis((OuyaSDK.KeyEnum)key.map, player); return(Mathf.Abs(val) > deadZone ? val : 0.0f); } return(0.0f); }
void FixedUpdate() { UpdateController(); UpdateLabels(); OuyaExampleCommon.UpdateJoysticks(); }
private void FixedUpdate() { OuyaExampleCommon.UpdateJoysticks(); if (RendererLabel) { RendererLabel.text = m_items.Count.ToString(); } if (PolysLabel) { int count = 0; foreach (MeshFilter mf in m_items) { if (mf.mesh) { count += mf.mesh.vertexCount; } } PolysLabel.text = count.ToString(); } if (m_timerChange < DateTime.Now) { m_timerChange = DateTime.Now + TimeSpan.FromMilliseconds(200); if (OuyaExampleCommon.GetButton(OuyaSDK.OuyaPlayer.player1, OuyaSDK.KeyEnum.BUTTON_DPAD_LEFT)) { DecreaseGeometry(1f); } if (OuyaExampleCommon.GetButton(OuyaSDK.OuyaPlayer.player1, OuyaSDK.KeyEnum.BUTTON_DPAD_RIGHT)) { IncreaseGeometry(1f); } if (OuyaExampleCommon.GetButton(OuyaSDK.OuyaPlayer.player1, OuyaSDK.KeyEnum.BUTTON_DPAD_UP)) { CombineGeometry(); } if (OuyaExampleCommon.GetButton(OuyaSDK.OuyaPlayer.player1, OuyaSDK.KeyEnum.BUTTON_O)) { IncreaseGeometry(0.1f); } if (OuyaExampleCommon.GetButton(OuyaSDK.OuyaPlayer.player1, OuyaSDK.KeyEnum.BUTTON_A)) { DecreaseGeometry(0.1f); } } float x = OuyaExampleCommon.GetAxis("LY", OuyaSDK.OuyaPlayer.player1); float y = OuyaExampleCommon.GetAxis("LX", OuyaSDK.OuyaPlayer.player1); Camera.main.transform.RotateAround(new Vector3(0, 0, 3), Camera.main.transform.rotation * Vector3.right, x * 45 * Time.fixedDeltaTime); Camera.main.transform.RotateAround(new Vector3(0, 0, 3), Camera.main.transform.rotation * Vector3.up, y * 45 * Time.fixedDeltaTime); }
public static float GetAxis(string inputName, OuyaSDK.OuyaPlayer player) { switch (Moga) { case true: switch (inputName) { case "TurnRight": return(MogaInput.GetAxis("R2")); //MogaController.KEYCODE_BUTTON_R2;//R2 case "TurnLeft": return(MogaInput.GetAxis("L2")); //MogaController.KEYCODE_BUTTON_L2;//L2 case "Roll": return(MogaInput.GetAxis("Horizontal")); //MogaController.AXIS_X;//X case "Vertical": return(MogaInput.GetAxis("Vertical")); //MogaController.AXIS_Y;//Y case "Pitch": return(MogaInput.GetAxis("LookVertical")); //MogaController.AXIS_RZ;//RZ case "Yaw": return(MogaInput.GetAxis("LookHorizontal")); //MogaController.AXIS_Z;//Z default: return(0); } case false: switch (inputName) { case "TurnRight": return(OuyaExampleCommon.GetAxis("RT", player)); case "TurnLeft": return(OuyaExampleCommon.GetAxis("LT", player)); case "Roll": return(OuyaExampleCommon.GetAxis("LX", player)); case "Vertical": return(OuyaExampleCommon.GetAxis("LY", player)); case "Pitch": return(OuyaExampleCommon.GetAxis("RY", player)); case "Yaw": return(OuyaExampleCommon.GetAxis("RX", player)); default: return(0); } } return(0); }
void OnGUI() { if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_O, OuyaSDK.OuyaPlayer.player1)) { ++m_threadCount; RespawnThreads(); } if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_A, OuyaSDK.OuyaPlayer.player1)) { m_threadCount = Mathf.Max(0, m_threadCount - 1); RespawnThreads(); } }
protected override bool ProcessButtonDown(Key key) { if (key.map == InputKeyMap.None) { return(base.ProcessButtonDown(key)); } if (key.map == InputKeyMap.HACK1) { return(OuyaExampleCommon.GetButton(2, GetPlayer(key))); } return(OuyaExampleCommon.GetButton((OuyaSDK.KeyEnum)key.map, GetPlayer(key))); }
void Update() { //selectPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_O, Index); selectPressed = (Input.GetKeyDown("space") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index)); //back shortcut if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index) || Input.GetKeyDown(KeyCode.Backspace)) { saveAndGoBack(); } //what to do if a choice is selected if (selectPressed) { saveAndGoBack(); } }
private bool GetButton(OuyaSDK.KeyEnum keyCode, OuyaSDK.OuyaPlayer player) { // Check if we want the *new* SDK input or the example common if (m_useSDKForInput) { // Get the Unity KeyCode for the Unity API KeyCode unityKeyCode = OuyaSDK.GetUnityKeyCode(keyCode, player); // Check if the KeyCode is valid if (unityKeyCode != (KeyCode)(-1)) { //use the Unity API to get the button value bool buttonState = Input.GetKey(unityKeyCode); return(buttonState); } } // moving the common code into the sdk via aboveUs else { return(OuyaExampleCommon.GetButton(keyCode, player)); } return(false); }
void UpdateTexture() { // range -1 to 1 float axisX = OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.AXIS_LSTICK_X, Player); float axisY = OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Player); // put in 0 to TextureSize range int x = (int)((axisX + 1) * 0.5f * (TextureSize - 1)); int y = (int)((-axisY + 1) * 0.5f * (TextureSize - 1)); int index = x + y * TextureSize; if (x != m_lastX || y != m_lastY) { m_lastX = x; m_lastY = y; if (index >= 0 && index < m_pixels.Length) { if (m_pixelVs[index] < 0f) { m_pixelVs[index] = 0f; } else { m_pixelVs[index] = m_pixelVs[index] + m_increment; } Vector3 c = Vector3.Lerp(new Vector3(0, 1, 0), new Vector3(1, 1, 1), m_pixelVs[index]); m_pixels[index].r = (byte)(int)(c.x * 255); m_pixels[index].g = (byte)(int)(c.y * 255); m_pixels[index].b = (byte)(int)(c.z * 255); m_pixels[index].a = 255; } } }
void FixedUpdate() { if (Active) { if (MasterAlpha < 0.999f && triggeredForward) { triggeredBack = false; MasterAlpha += 0.01f; if (MasterVolume < 1) { MasterVolume += 0.05f; audio.volume = MasterVolume; } } else if (doNotFadeLastImage && currentPage + 1 == SplashPages.Length) { Active = false; isSplashPage = false; LoadScene(); } else if (MasterAlpha > 0.001f && triggeredBack) { triggeredForward = false; MasterAlpha -= 0.01f; } else if (triggeredForward && MasterAlpha > 0.999f) { triggeredForward = false; triggeredBack = true; } else if (triggeredBack && MasterAlpha < 0.001f) { StartCoroutine(PauseTime()); } if (currentPage < SplashPages.Length) { Color color = SplashPages[currentPage].color; color.a = MasterAlpha; SplashPages[currentPage].color = color; } else { Active = false; isSplashPage = false; StartCoroutine(LoadScene()); } } DetectControllers(); if (MogaInput.GetControllerState() == MogaController.ACTION_CONNECTED) { if ((MogaInput.GetControllerSupportedVersion() == MogaController.ACTION_VERSION_MOGAPRO) && (!InputManager.Moga)) { InputManager.Moga = true; MogaPro = true; //ControllerCount = 1; //Controllers = ["MogaPro Controller"]; } else if ((MogaInput.GetControllerSupportedVersion() == MogaController.ACTION_VERSION_MOGA) && (!InputManager.Moga)) { InputManager.Moga = true; MogaPro = false; //ControllerCount = 1; //Controllers = ["Moga Controller"]; } } else { InputManager.Moga = false; // if(Controllers[0] == "MogaPro Controller" || Controllers[0] == "Moga Controller") // { // //Controllers = null; // //ControllerCount =0; // } } OuyaExampleCommon.UpdateJoysticks(); //Debug.Log(SystemInfo.deviceModel); if (SwappingSound) { if (audio.clip != audioToSwapTo && MusicVolumeFloat > 0) { MusicVolumeFloat -= 0.05f; audio.volume = MusicVolumeFloat; //Debug.Log("music volume " + MusicVolumeFloat); } else if (MusicVolumeFloat <= 0 && audio.clip != audioToSwapTo) { audio.clip = audioToSwapTo; if (!audio.isPlaying) { audio.Play(); } // Debug.Log("swapped audio clip"); } else if (MusicVolumeFloat < 1 && audio.clip == audioToSwapTo) { MusicVolumeFloat += 0.05f; audio.volume = MusicVolumeFloat; if (!audio.isPlaying) { audio.Play(); } //Debug.Log("swapping " + MusicVolumeFloat); } else if (MusicVolumeFloat >= 1 && audio.clip == audioToSwapTo && audio.isPlaying) { SwappingSound = false; // Debug.Log("swapping OFF"); } } if (CountDownTimer <= TimeTrial && WW3DIsUnlocked && !gameIsUnlocked) { CountDownTimer += Time.deltaTime; TimeRemaining = TimeTrial - CountDownTimer; interval += Time.deltaTime; // Debug.Log("time remianing "+TimeRemaining + " " + TimeTrial + " - " + CountDownTimer); if (interval > 10) { PlayerPrefs.SetFloat("CountDownTime", CountDownTimer); PlayerPrefs.Save(); interval = 0; } } else if (WW3DIsUnlocked && !gameIsUnlocked) { WW3DIsUnlocked = false; PlayerPrefs.SetFloat("CountDownTime", CountDownTimer); PlayerPrefs.Save(); } }
void Update() { //new button press detection //upPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index); upPressed = (Input.GetKey("up") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index)); if (!lastUpPressed && upPressed) { //if it wasnt pressed last time but it is now lastUpPressed = true; //log that it is pressed now for the next cycle upPressed = true; //signal new button press } else { lastUpPressed = upPressed; //log the current state for next cycle upPressed = false; //signal no new button press } //downPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index); downPressed = (Input.GetKey("down") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index)); if (!lastDownPressed && downPressed) { //if it wasnt pressed last time but it is now lastDownPressed = true; //log that it is pressed now for the next cycle downPressed = true; //signal new button press } else { lastDownPressed = downPressed; //log the current state for next cycle downPressed = false; //signal no new button press } //new joystick tilt detection //get the raw tilts to bools if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Index) < -L_STICK_DEADZONE) { lJoyUp = true; } else { lJoyUp = false; } if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Index) > L_STICK_DEADZONE) { lJoyDown = true; } else { lJoyDown = false; } //evaluate new tilts if (!lastLJoyUp && lJoyUp) { //if it wasnt up last time but it is now lastLJoyUp = true; //log that it is up now for the next cycle lJoyUp = true; //signal new up tilt } else { lastLJoyUp = lJoyUp; //log the current state for next cycle lJoyUp = false; //signal no new joystick tilt } if (!lastLJoyDown && lJoyDown) { //if it wasnt up last time but it is now lastLJoyDown = true; //log that it is up now for the next cycle lJoyDown = true; //signal new joystick tilt } else { lastLJoyDown = lJoyDown; //log the current state for next cycle lJoyDown = false; //signal no new joystick tilt } //select button //selectPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_O, Index); selectPressed = (Input.GetKeyDown("space") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index)); //back shortcut if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index)) { saveAndGoBack(); } //what to do if a choice is selected if (selectPressed) { switch (selectedChoice) { case 0: toggles[0] = flipInt(toggles[0]); break; case 1: toggles[1] = flipInt(toggles[1]); break; case 2: toggles[2] = flipInt(toggles[2]); break; case 3: saveAndGoBack(); break; default: break; } } //handling choice movement if ((upPressed || lJoyUp) && (selectedChoice > 0)) { selectedChoice -= 1; } if ((downPressed || lJoyDown) && (selectedChoice < (choices.Length - 1))) { selectedChoice += 1; } }
private void UpdateController() { #region Axis Code UpdateHighlight(RendererAxisLeft, Mathf.Abs(OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.AXIS_LSTICK_X, OuyaExampleCommon.Player)) > 0.25f || Mathf.Abs(OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, OuyaExampleCommon.Player)) > 0.25f); RendererAxisLeft.transform.localRotation = Quaternion.Euler(OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, OuyaExampleCommon.Player) * 15, 0, OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.AXIS_LSTICK_X, OuyaExampleCommon.Player) * 15); UpdateHighlight(RendererAxisRight, Mathf.Abs(OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.AXIS_RSTICK_X, OuyaExampleCommon.Player)) > 0.25f || Mathf.Abs(OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.AXIS_RSTICK_Y, OuyaExampleCommon.Player)) > 0.25f); RendererAxisRight.transform.localRotation = Quaternion.Euler(OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.AXIS_RSTICK_Y, OuyaExampleCommon.Player) * 15, 0, OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.AXIS_RSTICK_X, OuyaExampleCommon.Player) * 15); RendererLT.transform.localRotation = Quaternion.Euler(OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.BUTTON_LT, OuyaExampleCommon.Player) * -15, 0, 0); RendererRT.transform.localRotation = Quaternion.Euler(OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.BUTTON_RT, OuyaExampleCommon.Player) * -15, 0, 0); if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_L3, OuyaExampleCommon.Player)) { RendererAxisLeft.transform.localPosition = Vector3.Lerp(RendererAxisLeft.transform.localPosition, new Vector3(5.503977f, 0.75f, -3.344945f), Time.fixedDeltaTime); } else { RendererAxisLeft.transform.localPosition = Vector3.Lerp(RendererAxisLeft.transform.localPosition, new Vector3(5.503977f, 1.127527f, -3.344945f), Time.fixedDeltaTime); } if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_R3, OuyaExampleCommon.Player)) { RendererAxisRight.transform.localPosition = Vector3.Lerp(RendererAxisRight.transform.localPosition, new Vector3(-2.707688f, 0.75f, -1.354063f), Time.fixedDeltaTime); } else { RendererAxisRight.transform.localPosition = Vector3.Lerp(RendererAxisRight.transform.localPosition, new Vector3(-2.707688f, 1.11295f, -1.354063f), Time.fixedDeltaTime); } #endregion #region Button Code #region BUTTONS O - A //Check O button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_O, OuyaExampleCommon.Player)) { UpdateHighlight(RendererButtonO, true, true); } else { UpdateHighlight(RendererButtonO, false, true); } //Check U button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_U, OuyaExampleCommon.Player)) { UpdateHighlight(RendererButtonU, true, true); } else { UpdateHighlight(RendererButtonU, false, true); } //Check Y button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_Y, OuyaExampleCommon.Player)) { UpdateHighlight(RendererButtonY, true, true); } else { UpdateHighlight(RendererButtonY, false, true); } //Check A button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_A, OuyaExampleCommon.Player)) { UpdateHighlight(RendererButtonA, true, true); } else { UpdateHighlight(RendererButtonA, false, true); } //Check L3 button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_L3, OuyaExampleCommon.Player)) { UpdateHighlight(RendererAxisLeft, true, true); } else { UpdateHighlight(RendererAxisLeft, false, true); } //Check R3 button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_R3, OuyaExampleCommon.Player)) { UpdateHighlight(RendererAxisRight, true, true); } else { UpdateHighlight(RendererAxisRight, false, true); } #endregion #region Bumpers //Check LB button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_LB, OuyaExampleCommon.Player)) { UpdateHighlight(RendererLB, true, true); } else { UpdateHighlight(RendererLB, false, true); } //Check RB button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_RB, OuyaExampleCommon.Player)) { UpdateHighlight(RendererRB, true, true); } else { UpdateHighlight(RendererRB, false, true); } #endregion #region triggers //Check LT button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_LT, OuyaExampleCommon.Player)) { UpdateHighlight(RendererLT, true, true); } else { UpdateHighlight(RendererLT, false, true); } //Check RT button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_RT, OuyaExampleCommon.Player)) { UpdateHighlight(RendererRT, true, true); } else { UpdateHighlight(RendererRT, false, true); } #endregion #region DPAD //Check DPAD UP button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_DPAD_UP, OuyaExampleCommon.Player)) { UpdateHighlight(RendererDpadUp, true, true); } else { UpdateHighlight(RendererDpadUp, false, true); } //Check DPAD DOWN button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, OuyaExampleCommon.Player)) { UpdateHighlight(RendererDpadDown, true, true); } else { UpdateHighlight(RendererDpadDown, false, true); } //Check DPAD LEFT button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_DPAD_LEFT, OuyaExampleCommon.Player)) { UpdateHighlight(RendererDpadLeft, true, true); } else { UpdateHighlight(RendererDpadLeft, false, true); } //Check DPAD RIGHT button for down state if (OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_DPAD_RIGHT, OuyaExampleCommon.Player)) { UpdateHighlight(RendererDpadRight, true, true); } else { UpdateHighlight(RendererDpadRight, false, true); } #endregion #endregion }
private void UpdateLabels() { try { OuyaNGUIHandler nguiHandler = GameObject.Find("_NGUIHandler").GetComponent <OuyaNGUIHandler>(); if (nguiHandler != null && null != OuyaSDK.Joysticks) { for (int i = 0; i < OuyaSDK.Joysticks.Length || i < 8; i++) { string joyName = "N/A"; if (i < OuyaSDK.Joysticks.Length) { joyName = OuyaSDK.Joysticks[i]; } switch (i) { case 0: nguiHandler.controller1.text = OuyaExampleCommon.Player == OuyaSDK.OuyaPlayer.player1 ? string.Format("*{0}", joyName) : joyName; break; case 1: nguiHandler.controller2.text = OuyaExampleCommon.Player == OuyaSDK.OuyaPlayer.player2 ? string.Format("*{0}", joyName) : joyName; break; case 2: nguiHandler.controller3.text = OuyaExampleCommon.Player == OuyaSDK.OuyaPlayer.player3 ? string.Format("*{0}", joyName) : joyName; break; case 3: nguiHandler.controller4.text = OuyaExampleCommon.Player == OuyaSDK.OuyaPlayer.player4 ? string.Format("*{0}", joyName) : joyName; break; case 4: nguiHandler.controller5.text = OuyaExampleCommon.Player == OuyaSDK.OuyaPlayer.player5 ? string.Format("*{0}", joyName) : joyName; break; case 5: nguiHandler.controller6.text = OuyaExampleCommon.Player == OuyaSDK.OuyaPlayer.player6 ? string.Format("*{0}", joyName) : joyName; break; case 6: nguiHandler.controller7.text = OuyaExampleCommon.Player == OuyaSDK.OuyaPlayer.player7 ? string.Format("*{0}", joyName) : joyName; break; case 7: nguiHandler.controller8.text = OuyaExampleCommon.Player == OuyaSDK.OuyaPlayer.player8 ? string.Format("*{0}", joyName) : joyName; break; } } nguiHandler.button1.text = OuyaExampleCommon.GetButton(0, OuyaExampleCommon.Player).ToString(); nguiHandler.button2.text = OuyaExampleCommon.GetButton(1, OuyaExampleCommon.Player).ToString(); nguiHandler.button3.text = OuyaExampleCommon.GetButton(2, OuyaExampleCommon.Player).ToString(); nguiHandler.button4.text = OuyaExampleCommon.GetButton(3, OuyaExampleCommon.Player).ToString(); nguiHandler.button5.text = OuyaExampleCommon.GetButton(4, OuyaExampleCommon.Player).ToString(); nguiHandler.button6.text = OuyaExampleCommon.GetButton(5, OuyaExampleCommon.Player).ToString(); nguiHandler.button7.text = OuyaExampleCommon.GetButton(6, OuyaExampleCommon.Player).ToString(); nguiHandler.button8.text = OuyaExampleCommon.GetButton(7, OuyaExampleCommon.Player).ToString(); nguiHandler.button9.text = OuyaExampleCommon.GetButton(8, OuyaExampleCommon.Player).ToString(); nguiHandler.button10.text = OuyaExampleCommon.GetButton(9, OuyaExampleCommon.Player).ToString(); nguiHandler.button11.text = OuyaExampleCommon.GetButton(10, OuyaExampleCommon.Player).ToString(); nguiHandler.button12.text = OuyaExampleCommon.GetButton(11, OuyaExampleCommon.Player).ToString(); nguiHandler.button13.text = OuyaExampleCommon.GetButton(12, OuyaExampleCommon.Player).ToString(); nguiHandler.button14.text = OuyaExampleCommon.GetButton(13, OuyaExampleCommon.Player).ToString(); nguiHandler.button15.text = OuyaExampleCommon.GetButton(14, OuyaExampleCommon.Player).ToString(); nguiHandler.button16.text = OuyaExampleCommon.GetButton(15, OuyaExampleCommon.Player).ToString(); nguiHandler.button17.text = OuyaExampleCommon.GetButton(16, OuyaExampleCommon.Player).ToString(); nguiHandler.button18.text = OuyaExampleCommon.GetButton(17, OuyaExampleCommon.Player).ToString(); nguiHandler.button19.text = OuyaExampleCommon.GetButton(18, OuyaExampleCommon.Player).ToString(); nguiHandler.button20.text = OuyaExampleCommon.GetButton(19, OuyaExampleCommon.Player).ToString(); //nguiHandler.rawOut.text = OuyaGameObject.InputData; nguiHandler.device.text = SystemInfo.deviceModel; } } catch (System.Exception) { } }
// Update is called once per frame void Update() { newPipeTimer += Time.deltaTime; //add deltatime to pipe counter if (everyBodyDead) { everyBodyDeadTimer += Time.deltaTime; } //bird input switch if (controllerShareOn) { //yes controllerShare input switch switch (numberOfPlayers) { case 4: if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LB, Index2) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LT, Index2)) { bird4.SendMessage("Jump"); } goto case 3; case 3: if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index2) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RT, Index2) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RB, Index2)) { bird3.SendMessage("Jump"); } goto case 2; case 2: if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LB, Index) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LT, Index)) { bird2.SendMessage("Jump"); } goto case 1; case 1: if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RT, Index) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RB, Index)) { bird1.SendMessage("Jump"); } break; } } else { //no controller share input switch switch (numberOfPlayers) { case 4: if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index4)) { bird4.SendMessage("Jump"); } goto case 3; case 3: if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index3)) { bird3.SendMessage("Jump"); } goto case 2; case 2: if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index2)) { bird2.SendMessage("Jump"); } goto case 1; case 1: if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index)) { bird1.SendMessage("Jump"); } break; } } //if it's time to make a new pipe make one if (newPipeTimer >= newPipeFrequency && !everyBodyDead) { //generate a new pipe //doubleGapPipe if (doublePipeSetsEnabled && //are double pipes even on? (numberOfPlayers > 1) && //is this a multiplayer match (Random.value < (1f / newPipeDoubleOdds))) //random falls within 1/newPipeDoubleOdds and zero //make doubleGapPipeSet { float randomY = Random.Range(newDoublePipeMinY, newDoublePipeMaxY); randomY = Mathf.Round(randomY); Instantiate(doubleGapPipeSet, new Vector3(gameObject.transform.position.x + newPipeOffSet, randomY, 0f), Quaternion.identity); newPipeTimer = 0f; //reset newPipeTimer counter } else { //make singleGapPipeSet float randomY = Random.Range(newPipeMinY, newPipeMaxY); randomY = Mathf.Round(randomY); Instantiate(singleGapPipeSet, new Vector3(gameObject.transform.position.x + newPipeOffSet, randomY, 0f), Quaternion.identity); newPipeTimer = 0f; //reset newPipeTimer counter } } //set what bird to follow if all dead just stop moving float birdToFollowOffSet = 0; if (bird1 != null && bird1.getAlive()) { birdToFollow = bird1; } else if (bird2 != null && bird2.getAlive()) { birdToFollow = bird2; birdToFollowOffSet = 2; } else if (bird3 != null && bird3.getAlive()) { birdToFollow = bird3; birdToFollowOffSet = 4; } else if (bird4 != null && bird4.getAlive()) { birdToFollow = bird4; birdToFollowOffSet = 6; } else { everyBodyDead = true; } //if everyones dead sit still, otherwise follow first living one if (!everyBodyDead) { //camera follow part playerPos = birdToFollow.transform.position; gameObject.transform.position = new Vector3(playerPos.x + playerXOffset + birdToFollowOffSet, gameObject.transform.position.y, gameObject.transform.position.z); } if (everyBodyDead) { GameOver(); } }
void Update() { //new button press detection //upPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index); upPressed = OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index); if (!lastUpPressed && upPressed) { //if it wasnt pressed last time but it is now lastUpPressed = true; //log that it is pressed now for the next cycle upPressed = true; //signal new button press } else { lastUpPressed = upPressed; //log the current state for next cycle upPressed = false; //signal no new button press } //downPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index); downPressed = OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index); if (!lastDownPressed && downPressed) { //if it wasnt pressed last time but it is now lastDownPressed = true; //log that it is pressed now for the next cycle downPressed = true; //signal new button press } else { lastDownPressed = downPressed; //log the current state for next cycle downPressed = false; //signal no new button press } //new joystick tilt detection //get the raw tilts to bools if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Index) < -L_STICK_DEADZONE) { lJoyUp = true; } else { lJoyUp = false; } if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Index) > L_STICK_DEADZONE) { lJoyDown = true; } else { lJoyDown = false; } //evaluate new tilts if (!lastLJoyUp && lJoyUp) { //if it wasnt up last time but it is now lastLJoyUp = true; //log that it is up now for the next cycle lJoyUp = true; //signal new up tilt } else { lastLJoyUp = lJoyUp; //log the current state for next cycle lJoyUp = false; //signal no new joystick tilt } if (!lastLJoyDown && lJoyDown) { //if it wasnt up last time but it is now lastLJoyDown = true; //log that it is up now for the next cycle lJoyDown = true; //signal new joystick tilt } else { lastLJoyDown = lJoyDown; //log the current state for next cycle lJoyDown = false; //signal no new joystick tilt } //select button //selectPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_O, Index); selectPressed = OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index); //exit shortcut if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index)) { Application.LoadLevel("Main Menu"); } //what to do if a choice is selected if (selectPressed) { OuyaSDK.Purchasable toBeBought = new OuyaSDK.Purchasable(); switch (selectedChoice) { case 0: toBeBought.productId = "1"; OuyaSDK.requestPurchase(toBeBought); break; case 1: toBeBought.productId = "2"; OuyaSDK.requestPurchase(toBeBought); break; case 2: toBeBought.productId = "5"; OuyaSDK.requestPurchase(toBeBought); break; case 3: Application.LoadLevel("Main Menu"); break; default: break; } } //handling choice movement if ((upPressed || lJoyUp) && (selectedChoice > 0)) { selectedChoice -= 1; } if ((downPressed || lJoyDown) && (selectedChoice < (choices.Length - 1))) { selectedChoice += 1; } }
void Update() { //new button press detection //upPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index); upPressed = OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index); if (!lastUpPressed && upPressed) { //if it wasnt pressed last time but it is now lastUpPressed = true; //log that it is pressed now for the next cycle upPressed = true; //signal new button press } else { lastUpPressed = upPressed; //log the current state for next cycle upPressed = false; //signal no new button press } //downPressed = Input.GetKeyDown("down"); downPressed = OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index); if (!lastDownPressed && downPressed) { //if it wasnt pressed last time but it is now lastDownPressed = true; //log that it is pressed now for the next cycle downPressed = true; //signal new button press } else { lastDownPressed = downPressed; //log the current state for next cycle downPressed = false; //signal no new button press } // //new joystick tilt detection // //get the raw tilts to bools // if (OuyaExampleCommon.GetAxisRaw (OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Index) < -L_STICK_DEADZONE) { // lJoyUp = true; // } else { // lJoyUp = false; // } // if (OuyaExampleCommon.GetAxisRaw (OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Index) > L_STICK_DEADZONE) { // lJoyDown = true; // } else { // lJoyDown = false; // } // // //evaluate new tilts // if (!lastLJoyUp && lJoyUp) { // //if it wasnt up last time but it is now // lastLJoyUp = true; //log that it is up now for the next cycle // lJoyUp = true; //signal new up tilt // }else{ // lastLJoyUp = lJoyUp; //log the current state for next cycle // lJoyUp = false; //signal no new joystick tilt // } // // if (!lastLJoyDown && lJoyDown) { // //if it wasnt up last time but it is now // lastLJoyDown = true; //log that it is up now for the next cycle // lJoyDown = true; //signal new joystick tilt // }else{ // lastLJoyDown = lJoyDown; //log the current state for next cycle // lJoyDown = false; //signal no new joystick tilt // } //select button //selectPressed = Input.GetKeyDown("space"); selectPressed = OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index); //exit shortcut if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index)) { Application.Quit(); } //what to do if a choice is selected if (selectPressed) { switch (selectedChoice) { case 0: Application.LoadLevel("Player Select"); break; case 1: Application.LoadLevel("Options"); break; case 2: Application.LoadLevel("Credits"); break; case 3: Application.LoadLevel("Donate"); break; case 4: Application.Quit(); break; default: break; } } //handling choice movement if ((upPressed) && (selectedChoice > 0)) { selectedChoice -= 1; } if ((downPressed) && (selectedChoice < (choices.Length - 1))) { selectedChoice += 1; } }
void OnGUI() { //print player scores using fallthrough, case is player number switch (numberOfPlayers) { case 4: GUI.Label(new Rect(((Screen.width * 4.0f / ((float)numberOfPlayers + 1.0f)) - 50.0f), (Screen.height / 8f), 100, 40), bird4.getScore().ToString(), p4ScoreStyle); goto case 3; case 3: GUI.Label(new Rect(((Screen.width * 3.0f / ((float)numberOfPlayers + 1.0f)) - 50.0f), (Screen.height / 8f), 100, 40), bird3.getScore().ToString(), p3ScoreStyle); goto case 2; case 2: GUI.Label(new Rect(((Screen.width * 2.0f / ((float)numberOfPlayers + 1.0f)) - 50.0f), (Screen.height / 8f), 100, 40), bird2.getScore().ToString(), p2ScoreStyle); goto case 1; case 1: GUI.Label(new Rect(((Screen.width * 1.0f / ((float)numberOfPlayers + 1.0f)) - 50.0f), (Screen.height / 8f), 100, 40), bird1.getScore().ToString(), p1ScoreStyle); break; } //highscore and restart screen if (everyBodyDead) { //Game Over Title GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (3.0f / 10.0f) - 20.0f), 100, 40), "Game Over", gameOverTitleStyle); if (numberOfPlayers > 1) { //if there was a tie if (getWinningPlayerNumber() == 0.0f) { GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (5.0f / 10.0f) - 20.0f), 100, 40), "Tie - No Winner", gameOverStyle); } else { //no tie //winning player and score GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (5.0f / 10.0f) - 20.0f), 100, 40), "Player " + getWinningPlayerNumber().ToString() + " Wins with " + getWinningPlayerScore() + " Points!", gameOverStyle); } } else { GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (5.0f / 10.0f) - 20.0f), 100, 40), "You got " + getWinningPlayerScore() + " Points!", gameOverStyle); } //high score if ((getWinningPlayerScore() > PlayerPrefs.GetFloat("highScore")) || newHighScore) { //new high score! newHighScore = true; //bool to keep bringing the program through this loop after new high score is saved to playerprefs as high score //save high score to playerprefs PlayerPrefs.SetFloat("highScore", getWinningPlayerScore()); PlayerPrefs.Save(); //print Yay message for new high score GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (6.0f / 10.0f) - 20.0f), 100, 40), "New High Score! - " + PlayerPrefs.GetFloat("highScore").ToString(), gameOverStyle); } else { //show high score GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (6.0f / 10.0f) - 20.0f), 100, 40), "High Score - " + PlayerPrefs.GetFloat("highScore").ToString(), gameOverStyle); } //replay and back text GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (8.0f / 10.0f) - 20.0f), 100, 40), " Restart Back", gameOverStyle); GUI.DrawTexture(new Rect(((Screen.width / 2.0f) - 35.0f - 250.0f), ((Screen.height * (8.0f / 10.0f)) - 50.0f), 70, 80), OUYA_O); GUI.DrawTexture(new Rect(((Screen.width / 2.0f) - 35.0f + 120.0f), ((Screen.height * (8.0f / 10.0f)) - 50.0f), 70, 80), OUYA_A); if (everyBodyDeadTimer > 0.5f) { //restart if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index)) { Application.LoadLevel(Application.loadedLevel); } //back to player select if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index)) { Application.LoadLevel("Player Select"); } } } }
void Update() { //new button press detection //rightPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index); rightPressed = (Input.GetKey(KeyCode.LeftArrow) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_LEFT, Index)); if (!lastRightPressed && rightPressed) { //if it wasnt pressed last time but it is now lastRightPressed = true; //log that it is pressed now for the next cycle rightPressed = true; //signal new button press } else { lastRightPressed = rightPressed; //log the current state for next cycle rightPressed = false; //signal no new button press } //leftPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index); leftPressed = (Input.GetKey(KeyCode.RightArrow) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_RIGHT, Index)); if (!lastLeftPressed && leftPressed) { //if it wasnt pressed last time but it is now lastLeftPressed = true; //log that it is pressed now for the next cycle leftPressed = true; //signal new button press } else { lastLeftPressed = leftPressed; //log the current state for next cycle leftPressed = false; //signal no new button press } //new joystick tilt detection //get the raw tilts to bools if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_X, Index) < -L_STICK_DEADZONE) { lJoyRight = true; } else { lJoyRight = false; } if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_X, Index) > L_STICK_DEADZONE) { lJoyLeft = true; } else { lJoyLeft = false; } //evaluate new tilts if (!lastLJoyRight && lJoyRight) { //if it wasnt up last time but it is now lastLJoyRight = true; //log that it is up now for the next cycle lJoyRight = true; //signal new up tilt } else { lastLJoyRight = lJoyRight; //log the current state for next cycle lJoyRight = false; //signal no new joystick tilt } if (!lastLJoyLeft && lJoyLeft) { //if it wasnt up last time but it is now lastLJoyLeft = true; //log that it is up now for the next cycle lJoyLeft = true; //signal new joystick tilt } else { lastLJoyLeft = lJoyLeft; //log the current state for next cycle lJoyLeft = false; //signal no new joystick tilt } //select button //selectPressed = OuyaExampleCommon.GetButtonLeft (OuyaSDK.KeyEnum.BUTTON_O, Index); //controllerShare button if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_U, Index)) { controllerShareOn = !controllerShareOn; } //exit shortcut if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index) || Input.GetKeyDown(KeyCode.Backspace)) { Application.LoadLevel("Main Menu"); } //what to do if a choice is selected switch (selectedChoice) { case 3: break; case 2: break; case 1: break; default: break; } //bird renderers if (playersReady [1]) { bird2.renderer.enabled = true; } else { bird2.renderer.enabled = false; } if (playersReady [2]) { bird3.renderer.enabled = true; } else { bird3.renderer.enabled = false; } if (playersReady [3]) { bird4.renderer.enabled = true; } else { bird4.renderer.enabled = false; } numberOfPlayers = selectedChoice + 1; setPlayers(numberOfPlayers); PlayerPrefs.SetInt("numberOfPlayers", numberOfPlayers); //handling choice movement if ((rightPressed || lJoyRight) && (selectedChoice > 0)) { selectedChoice -= 1; } if ((leftPressed || lJoyLeft) && (selectedChoice < (choices.Length - 1))) { selectedChoice += 1; } //p1 O button to start game if (Input.GetKeyDown("space") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RT, Index) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RB, Index)) { print("got it"); //everybody in if (compare4Bools()) { //save controllerShare options if (controllerShareOn) { PlayerPrefs.SetInt("controllerShare", 1); } else { PlayerPrefs.SetInt("controllerShare", 0); } PlayerPrefs.SetInt("numberOfPlayers", numberOfPlayers); PlayerPrefs.Save(); Application.LoadLevel("Game Level"); } } //ready up buttons if (controllerShareOn) { //yes controller share ready up //p2 ready up if (Input.GetKeyDown("a") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LB, Index) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LT, Index)) { if (playersOn[1]) { playersReady[1] = true; } } //p3 ready up if (Input.GetKeyDown("'") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index2) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RT, Index2) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RB, Index2)) { if (playersOn[2]) { playersReady[2] = true; } } //p4 ready up if (Input.GetKeyDown("5") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LB, Index2) || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LT, Index2)) { if (playersOn[3]) { playersReady[3] = true; } } } else { //no controller share ready up //p2 ready up if (Input.GetKeyDown("a") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index2)) { if (playersOn[1]) { playersReady[1] = true; } } //p3 ready up if (Input.GetKeyDown("'") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index3)) { if (playersOn[2]) { playersReady[2] = true; } } //p4 ready up if (Input.GetKeyDown("5") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index4)) { if (playersOn[3]) { playersReady[3] = true; } } } //controllerShareState catcher if ((controllerShareOn != controllerShareLastState) && controllerShareLastState) { //if state changed and it used to be on controllerShareJustOn = true; //controllerShare was just turned off so set players to one to avoid dummy players signed in selectedChoice = 0; } else { controllerShareJustOn = false; } //auto move to 2 player when turning on controllershare if ((controllerShareOn != controllerShareLastState) && !controllerShareLastState) { //controllerShare was just turned on so set the game to two player selectedChoice = 1; } controllerShareLastState = controllerShareOn; //log current state as last } //end void Update()
public static bool GetButton(string inputName, OuyaSDK.OuyaPlayer player) { switch (Moga) { case true: switch (inputName) { case "Shoot": return(MogaInput.GetKey(KeyCode.JoystickButton0)); //a case "Orbit": return(MogaInput.GetKey(KeyCode.JoystickButton2)); //x case "Option": return(MogaInput.GetKey(KeyCode.JoystickButton3)); //y case "Exit": return(MogaInput.GetKey(KeyCode.JoystickButton1)); //b case "TurnLeft": return(MogaInput.GetKeyDown(KeyCode.JoystickButton10)); case "TurnRight": return(MogaInput.GetKeyDown(KeyCode.JoystickButton11)); case "SkipLeft": return(MogaInput.GetKeyDown(KeyCode.JoystickButton4)); case "SkipRight": return(MogaInput.GetKeyDown(KeyCode.JoystickButton5)); case "DLeft": return(MogaInput.GetKey(KeyCode.JoystickButton14)); case "DRight": return(MogaInput.GetKey(KeyCode.JoystickButton15)); case "DUp": return(MogaInput.GetKey(KeyCode.JoystickButton12)); case "DDown": return(MogaInput.GetKey(KeyCode.JoystickButton13)); case "StartBtn": return(MogaInput.GetKeyDown(KeyCode.JoystickButton7)); default: return(false); } case false: switch (inputName) { case "Shoot": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_O, player)); case "Orbit": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_U, player)); case "Option": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_Y, player)); case "Exit": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_A, player)); case "TurnLeft": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_LT, player)); case "TurnRight": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_RT, player)); case "SkipLeft": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_LB, player)); case "SkipRight": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_RB, player)); case "DLeft": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_DPAD_LEFT, player)); case "DRight": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_DPAD_RIGHT, player)); case "DUp": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_DPAD_UP, player)); case "DDown": return(OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, player)); default: return(false); } } return(false); }
void Update() { if (m_timerCreate < DateTime.Now) { m_timerCreate = DateTime.Now + TimeSpan.FromMilliseconds(NoteTimeToCreate); int index = Random.Range(0, Lanes.Count); CreateNote(Lanes[index]); } foreach (CubeLaneItem item in Lanes) { bool val = OuyaExampleCommon.GetButton(item.LaneButton); if (LastPressed.ContainsKey(item.LaneButton)) { if (!val) { LastPressed.Remove(item.LaneButton); } } else { if (val) { LastPressed[item.LaneButton] = OuyaExampleCommon.GetButton(item.LaneButton); } } } List<NoteItem> removeList = new List<NoteItem>(); foreach (NoteItem note in Notes) { if (note.EndTime < DateTime.Now) { removeList.Add(note); continue; } float elapsed = (float)(DateTime.Now - note.StartTime).TotalMilliseconds; note.Instance.transform.position = Vector3.Lerp( note.Parent.StartPosition.transform.position, note.Parent.EndPosition.transform.position, elapsed/(float) NoteTimeToLive); bool inRange = Mathf.Abs(TrackEnd.position.z - note.Instance.transform.position.z) <= 16; bool afterRange = (note.Instance.transform.position.z - 8) < TrackEnd.position.z; // use available press of the lane button if (LastPressed.ContainsKey(note.Parent.LaneButton) && LastPressed[note.Parent.LaneButton]) { if ( //check if note is across the finish line inRange ) { //use button press LastPressed[note.Parent.LaneButton] = false; //hit the note if (!note.NoteHit) { note.NoteHit = true; note.FadeTime = DateTime.Now + TimeSpan.FromMilliseconds(NoteTimeToFade); UpdateFadeDelay(note); } } } if (note.NoteHit) { } else if (inRange) { (note.Instance.renderer as MeshRenderer).material.color = Color.white; } else if (afterRange) { (note.Instance.renderer as MeshRenderer).material.color = new Color(0, 0, 0, 0.75f); if (!note.NoteHit) { note.Parent.FadeDelay = DateTime.Now; } } if (note.FadeTime != DateTime.MinValue) { if (note.FadeTime < DateTime.Now) { removeList.Add(note); continue; } elapsed = (float)(note.FadeTime - DateTime.Now).TotalMilliseconds; (note.Instance.renderer as MeshRenderer).material.color = Color.Lerp(note.Parent.LaneColor, Color.clear, 1f - elapsed / (float)NoteTimeToFade); note.Instance.transform.localScale = Vector3.Lerp(note.Instance.transform.localScale, note.Parent.StartPosition.transform.localScale * 2, elapsed / (float)NoteTimeToFade); } } foreach (NoteItem note in removeList) { Notes.Remove(note); DestroyNote(note); } }
void Update() { if (m_timerCreate < DateTime.Now) { m_timerCreate = DateTime.Now + TimeSpan.FromMilliseconds(NoteTimeToCreate); int index = Random.Range(0, Lanes.Count); CreateNote(Lanes[index]); } bool lower = OuyaExampleCommon.GetButton(OuyaSDK.KeyEnum.HARMONIX_ROCK_BAND_GUITAR_LOWER, OuyaSDK.OuyaPlayer.player1); float strum = OuyaExampleCommon.GetAxis(OuyaSDK.KeyEnum.HARMONIX_ROCK_BAND_GUITAR_STRUM, OuyaSDK.OuyaPlayer.player1); bool strumChanged = LastStrum != strum; LastStrum = strum; foreach (CubeLaneItem item in Lanes) { // cache the button state LastPressed[item.LaneButton] = OuyaExampleCommon.GetButton(item.LaneButton, OuyaSDK.OuyaPlayer.player1); } List <NoteItem> removeList = new List <NoteItem>(); foreach (NoteItem note in Notes) { if (note.EndTime < DateTime.Now) { removeList.Add(note); continue; } float elapsed = (float)(DateTime.Now - note.StartTime).TotalMilliseconds; note.Instance.transform.position = Vector3.Lerp( note.Parent.StartPosition.transform.position, note.Parent.EndPosition.transform.position, elapsed / (float)NoteTimeToLive); bool inRange = Mathf.Abs(TrackEnd.position.z - note.Instance.transform.position.z) <= 16; bool afterRange = (note.Instance.transform.position.z - 8) < TrackEnd.position.z; if (inRange) { (note.Instance.renderer as MeshRenderer).material.color = Color.white; } else if (afterRange) { (note.Instance.renderer as MeshRenderer).material.color = new Color(0, 0, 0, 0.75f); } // use available press of the lane button if (LastPressed.ContainsKey(note.Parent.LaneButton) && LastPressed[note.Parent.LaneButton]) { if ( //check if note is across the finish line inRange && //check if lower was used (!note.UseLower || lower == note.UseLower) && // check if strum was used strumChanged && strum != 0f) { //use button press LastPressed[note.Parent.LaneButton] = false; //hit the note if (note.FadeTime == DateTime.MinValue) { note.FadeTime = DateTime.Now + TimeSpan.FromMilliseconds(NoteTimeToFade); note.Parent.LaneSound.volume = 1; } } } if (note.FadeTime != DateTime.MinValue) { if (note.FadeTime < DateTime.Now) { removeList.Add(note); continue; } elapsed = (float)(note.FadeTime - DateTime.Now).TotalMilliseconds; (note.Instance.renderer as MeshRenderer).material.color = Color.Lerp(note.Parent.LaneColor, Color.clear, 1f - elapsed / (float)NoteTimeToFade); note.Instance.transform.localScale = Vector3.Lerp(note.Instance.transform.localScale, note.Parent.StartPosition.transform.localScale * 2, elapsed / (float)NoteTimeToFade); } } foreach (NoteItem note in removeList) { Notes.Remove(note); DestroyNote(note); } }