/* * Method that will move the cursors and what current option is selected * Can only go up the menu if the curren option is not the first (0) option. * Can only go down the menu if the current option is not the last (length - 1) option. * If could go down if at length-1, get IndexOutOfBounds. */ private void moveSelect() { if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) { if (Input.GetAxisRaw(ControllerInputManager.Vertical()) > 0 && currentPauseMenuOption > 0 && !isPressed) { isPressed = true; currentPauseMenuOption--; GameMaster.SelectSFX(); optionRect = (RectTransform)pauseMenuOptions [currentPauseMenuOption].transform; /* This sets the positions of the cursors relative to the option's position and width */ leftCursor.transform.position = new Vector2(optionRect.transform.position.x - (optionRect.rect.width) - 35f, pauseMenuOptions [currentPauseMenuOption].transform.position.y); rightCursor.transform.position = new Vector2(optionRect.transform.position.x + (optionRect.rect.width) + 35f, pauseMenuOptions [currentPauseMenuOption].transform.position.y); } else if (Input.GetAxisRaw(ControllerInputManager.Vertical()) < 0 && currentPauseMenuOption < pauseMenuOptions.Length - 1 && !isPressed) { isPressed = true; currentPauseMenuOption++; GameMaster.SelectSFX(); optionRect = (RectTransform)pauseMenuOptions [currentPauseMenuOption].transform; leftCursor.transform.position = new Vector2(optionRect.transform.position.x - (optionRect.rect.width) - 35f, pauseMenuOptions [currentPauseMenuOption].transform.position.y); rightCursor.transform.position = new Vector2(optionRect.transform.position.x + (optionRect.rect.width) + 35f, pauseMenuOptions [currentPauseMenuOption].transform.position.y); } else if (Input.GetAxisRaw(ControllerInputManager.Vertical()) == 0) { isPressed = false; } } else if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor) { /*--------------------------------------------------------------------------* * MacOS has different settings for PS4 controllers. Up is < 0, down is > 0 * * This changes the controls accordingly * *--------------------------------------------------------------------------*/ if (GameMaster.UsingController()) { if (Input.GetAxisRaw(ControllerInputManager.Vertical()) < 0 && currentPauseMenuOption > 0 && !isPressed) { isPressed = true; currentPauseMenuOption--; GameMaster.SelectSFX(); //print("current: " + currentPauseMenuOption); optionRect = (RectTransform)pauseMenuOptions [currentPauseMenuOption].transform; /* This sets the positions of the cursors relative to the option's position and width */ leftCursor.transform.position = new Vector2(optionRect.transform.position.x - (optionRect.rect.width) - 10, pauseMenuOptions [currentPauseMenuOption].transform.position.y); rightCursor.transform.position = new Vector2(optionRect.transform.position.x + (optionRect.rect.width) + 10, pauseMenuOptions [currentPauseMenuOption].transform.position.y); } else if (Input.GetAxisRaw(ControllerInputManager.Vertical()) > 0 && currentPauseMenuOption < pauseMenuOptions.Length - 1 && !isPressed) { isPressed = true; currentPauseMenuOption++; GameMaster.SelectSFX(); optionRect = (RectTransform)pauseMenuOptions [currentPauseMenuOption].transform; leftCursor.transform.position = new Vector2(optionRect.transform.position.x - (optionRect.rect.width) - 10, pauseMenuOptions [currentPauseMenuOption].transform.position.y); rightCursor.transform.position = new Vector2(optionRect.transform.position.x + (optionRect.rect.width) + 10, pauseMenuOptions [currentPauseMenuOption].transform.position.y); } else if (Input.GetAxisRaw(ControllerInputManager.Vertical()) == 0) { isPressed = false; } } else { if (Input.GetAxisRaw(ControllerInputManager.Vertical()) > 0 && currentPauseMenuOption > 0 && !isPressed) { isPressed = true; currentPauseMenuOption--; GameMaster.SelectSFX(); optionRect = (RectTransform)pauseMenuOptions [currentPauseMenuOption].transform; /* This sets the positions of the cursors relative to the option's position and width */ leftCursor.transform.position = new Vector2(optionRect.transform.position.x - (optionRect.rect.width) - 10, pauseMenuOptions [currentPauseMenuOption].transform.position.y); rightCursor.transform.position = new Vector2(optionRect.transform.position.x + (optionRect.rect.width) + 10, pauseMenuOptions [currentPauseMenuOption].transform.position.y); } else if (Input.GetAxisRaw(ControllerInputManager.Vertical()) < 0 && currentPauseMenuOption < pauseMenuOptions.Length - 1 && !isPressed) { isPressed = true; currentPauseMenuOption++; GameMaster.SelectSFX(); optionRect = (RectTransform)pauseMenuOptions [currentPauseMenuOption].transform; leftCursor.transform.position = new Vector2(optionRect.transform.position.x - (optionRect.rect.width) - 10, pauseMenuOptions [currentPauseMenuOption].transform.position.y); rightCursor.transform.position = new Vector2(optionRect.transform.position.x + (optionRect.rect.width) + 10, pauseMenuOptions [currentPauseMenuOption].transform.position.y); } else if (Input.GetAxisRaw(ControllerInputManager.Vertical()) == 0) { isPressed = false; } } } }
/* * Protected method from the parent class PhysicsObject. Will calculate velocity based on player input. * This method also sets the player's animation states based on these velocity values. * Also checks player input to do other things as well. * */ protected override void ComputeVelocity() //gets called in the PhysicsObject script { move = Vector2.zero; // move.x = Input.GetAxis("PS4_DPadHorizontal"); //sets vector 2 movement to controller movement if (!GameMaster.Swinging()) { move.x = Input.GetAxisRaw(ControllerInputManager.Horizontal()); //lastMove = move.x; } else { move.x = Input.GetAxisRaw(ControllerInputManager.Horizontal()) / 1.2f; } if (GameMaster.OnLadder()) { //TODO: have 2 frames that alternate (exit time w/ event method) while climbing if ((Input.GetAxisRaw(ControllerInputManager.Vertical()) == 0 || GameMaster.Swinging()) && climbing) { velocity = Vector2.zero; // if climbing and not holding a button, don't move } else if (Input.GetAxisRaw(ControllerInputManager.Vertical()) > 0 && !GameMaster.Swinging()) { climbing = true; // checks to os so that vertical controls don't get reversed if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) { velocity = -10f * gravityModifier * Physics2D.gravity * Time.deltaTime; } else if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor) { velocity = 10f * gravityModifier * Physics2D.gravity * Time.deltaTime; } } else if (Input.GetAxisRaw(ControllerInputManager.Vertical()) < 0 && !GameMaster.Swinging()) { climbing = true; if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) { velocity = 10f * gravityModifier * Physics2D.gravity * Time.deltaTime; } else if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor) { velocity = -10f * gravityModifier * Physics2D.gravity * Time.deltaTime; } } if (grounded) { climbing = false; velocity += gravityModifier * Physics2D.gravity * Time.deltaTime; } if (Input.GetButtonDown(ControllerInputManager.Jump()) && climbing) { climbing = false; if (velocity.y >= 0) { velocity += gravityModifier * 3 * Physics2D.gravity * Time.deltaTime; animator.SetInteger("State", 3); } } if (!climbing) { if (Input.GetButtonDown(ControllerInputManager.Jump()) && grounded && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused() && !GameMaster.Swinging()) //if jump button is pressed and is grounded { GameMaster.PlayJump(); velocity.y = jumpTakeOffSpeed; //velocity becomes jump speed } else if (Input.GetButtonUp(ControllerInputManager.Jump())) //else if jump is let go { if (velocity.y > 0) //reduce y speed and set animation state to walking if applicable { velocity.y = velocity.y * 0.5f; animator.SetInteger("State", 3); } } } } else { climbing = false; if (Input.GetButtonDown(ControllerInputManager.Jump()) && grounded && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused() && !GameMaster.Swinging() && !climbing) //if jump button is pressed and is grounded { velocity.y = jumpTakeOffSpeed; //velocity becomes jump speed GameMaster.PlayJump(); } else if (Input.GetButtonUp(ControllerInputManager.Jump())) //else if jump is let go { if (velocity.y > 0) //reduce y speed and set animation state to walking if applicable { velocity.y = velocity.y * 0.5f; animator.SetInteger("State", 3); } } } if (!GameMaster.PlayerTransitionState() && !GameMaster.Swinging()) { if (move.x > 0.01f) //if has x speed, flip sprite direction when moving to move the correct way { if (spriteRenderer.flipX == false) { spriteRenderer.flipX = true; } } else if (move.x < -0.01f) { if (spriteRenderer.flipX == true) { spriteRenderer.flipX = false; } } } if (isFalling && !GameMaster.PlayerRespawnState()) { animator.SetInteger("State", 1); //if falling, set animation state to falling } if (grounded) { animator.SetInteger("State", 0); //if grounded, set animation state to 0 (go back to idle) } animator.SetBool("grounded", grounded); //set animator boolean variables depending on state gathered from PhysicsObject animator.SetFloat("velocityX", Mathf.Abs(velocity.x) / maxSpeed); //sets the animator parameter to this x velocity targetVelocity = move * maxSpeed; }
/** * Method that checks inputs to see which weapon to use */ private void UseWeapon() { switch (GameMaster.Weapon()) { case "sword": if (upgradeFireRate == 0) { if (!GameMaster.UpgradedSword()) { if (Input.GetButton(ControllerInputManager.Fire()) && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused() && !GameMaster.Swinging()) { Sword(); } } else { if (Input.GetAxisRaw(ControllerInputManager.Vertical()) > 0 && !GameMaster.Swinging()) { if (Input.GetButton(ControllerInputManager.Fire()) && Time.time > upgradeFireRate && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused()) { ShootSwordBeam(); } } else { if (Input.GetButton(ControllerInputManager.Fire()) && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused() && !GameMaster.Swinging()) { Sword(); } } } } else { if (!GameMaster.UpgradedSword()) { if (Input.GetButton(ControllerInputManager.Fire()) && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused() && !GameMaster.Swinging()) { Sword(); } } else { if (Input.GetAxisRaw(ControllerInputManager.Vertical()) > 0 && !GameMaster.Swinging()) { if (Input.GetButton(ControllerInputManager.Fire()) && Time.time > timeToFireUpgrade && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused()) { timeToFireUpgrade = Time.time + 1 / upgradeFireRate; //shoot sword beam ShootSwordBeam(); } } else { if (Input.GetButton(ControllerInputManager.Fire()) && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused() && !GameMaster.Swinging()) { Sword(); } } } } break; case "blaster": if (fireRate == 0 && upgradeFireRate == 0) { if (GameMaster.UpgradedBlaster()) { if (Input.GetAxisRaw(ControllerInputManager.Vertical()) > 0 && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused()) { if (Input.GetButtonDown(ControllerInputManager.Fire()) && Time.time > upgradeFireRate && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused()) { if (GameMaster.Ammo() > 5) { ShootUpgrade(); } else { timeToFireUpgrade = Time.time + 1 / upgradeFireRate; GameMaster.CancelSFX(); } } } else if (Input.GetButton(ControllerInputManager.Fire()) && Time.time > timeToFire && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused()) { if (GameMaster.Ammo() > 0) { Shoot(); } else { timeToFire = Time.time + 1 / fireRate; GameMaster.CancelSFX(); } } } } else { if (GameMaster.UpgradedBlaster()) { if (Input.GetAxisRaw(ControllerInputManager.Vertical()) > 0 && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused()) { if (Input.GetButtonDown(ControllerInputManager.Fire()) && Time.time > timeToFireUpgrade && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused()) { if (GameMaster.Ammo() > 5) { timeToFireUpgrade = Time.time + 1 / upgradeFireRate; ShootUpgrade(); } else { timeToFireUpgrade = Time.time + 1 / upgradeFireRate; GameMaster.CancelSFX(); } } } else if (Input.GetButton(ControllerInputManager.Fire()) && Time.time > timeToFire && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused()) { if (GameMaster.Ammo() > 0) { timeToFire = Time.time + 1 / fireRate; Shoot(); } else { timeToFire = Time.time + 1 / fireRate; GameMaster.CancelSFX(); } } } else { if (Input.GetButton(ControllerInputManager.Fire()) && Time.time > timeToFire && !GameMaster.PlayerTransitionState() && !GameMaster.IsPaused()) { if (GameMaster.Ammo() > 0) { timeToFire = Time.time + 1 / fireRate; Shoot(); } else { timeToFire = Time.time + 1 / fireRate; GameMaster.CancelSFX(); } } } } break; default: GameMaster.SetWeapon("sword"); break; } }