private void Move() { int x; int y; if (CustomInput.BoolHeld(CustomInput.UserInput.Up)) { y = 1; } else if (CustomInput.BoolHeld(CustomInput.UserInput.Down)) { y = -1; } else { y = 0; } if (CustomInput.BoolHeld(CustomInput.UserInput.Left)) { x = -1; } else if (CustomInput.BoolHeld(CustomInput.UserInput.Right)) { x = 1; } else { x = 0; } Vector2 dir = new Vector2(x, y); this.rgdb.velocity = (this.transform.right * dir.x + this.transform.forward * dir.y) * this.moveSpeed; }
private void Shoot() { if (shotTimer <= 0) { if (CustomInput.BoolHeld(CustomInput.UserInput.Shoot2)) { GameObject b = BulletPool.Instance.GetBullet(BulletPool.BulletTypes.Basic); if (b != null) { fireGun.Play(); b.transform.position = this.barrel.position; b.transform.rotation = Quaternion.Euler(0, 0, Vector2.SignedAngle(Vector2.right, this.aimDir)); this.shotTimer = this.shotTime; } } else if (CustomInput.BoolHeld(CustomInput.UserInput.Shoot1)) { if (this.prevBullet == null || !this.prevBullet.gameObject.activeSelf) { GameObject b = BulletPool.Instance.GetBullet(BulletPool.BulletTypes.Space); if (b != null) { fireSpaceGun.Play(); b.transform.position = this.barrel.position; b.transform.rotation = Quaternion.Euler(0, 0, Vector2.SignedAngle(Vector2.right, this.aimDir)); this.prevBullet = b.GetComponent <SpaceBullet>(); this.shotTimer = this.spaceTime; } } } } }
private void Update() { if (Managers.GameState.Instance.IsPaused) { return; } this.Up = CustomInput.BoolHeld(CustomInput.UserInput.Up); this.Down = CustomInput.BoolHeld(CustomInput.UserInput.Down); this.Left = CustomInput.BoolHeld(CustomInput.UserInput.Left); this.Right = CustomInput.BoolHeld(CustomInput.UserInput.Right); this.anim.SetBool(this.upHash, this.Up); this.anim.SetBool(this.downHash, this.Down); this.anim.SetBool(this.leftHash, this.Left); this.anim.SetBool(this.rigthHash, this.Right); this.anim.SetBool(this.moveHash, this.Up || this.Down || this.Left || this.Right); if (behavior.CurrentState == Enums.HeroState.Attack && CustomInput.BoolFreshPress(CustomInput.UserInput.Attack)) { this.behavior.AttackQueued = true; } this.anim.SetBool(this.attackHash, CustomInput.BoolFreshPress(CustomInput.UserInput.Attack)); if (CustomInput.BoolFreshPress(CustomInput.UserInput.NextWeapon)) { this.behavior.GoToNextWeapon(); } if (CustomInput.BoolFreshPress(CustomInput.UserInput.PrevWeapon)) { this.behavior.GoToPreviousWeapon(); } }
/// <summary> Controls player movement. </summary> /// <param name="inAir"> Boolean for if the player is currently in the air. </param> private void Move(ref bool inAir) { if (CustomInput.BoolHeld(CustomInput.UserInput.Left)) { xVel = -moveSpeed; GetComponent <Animator>().SetBool("Walking", true); } else if (CustomInput.BoolHeld(CustomInput.UserInput.Right)) { xVel = moveSpeed; GetComponent <Animator>().SetBool("Walking", true); } else { xVel = 0; GetComponent <Animator>().SetBool("Walking", false); } if (!inAir && CustomInput.BoolFreshPress(CustomInput.UserInput.Jump)) { yVel = jumpSpeed; inAir = true; } if (Mathf.Abs(xVel) > maxRunSpeed) { if (xVel > 0) { xVel = maxRunSpeed; } else { xVel = -maxRunSpeed; } } transform.Translate(new Vector3(xVel * Time.deltaTime, yVel * Time.deltaTime, 0)); if (inAir) { if (yVel < maxFallSpeed) { yVel = maxFallSpeed; } else if (yVel > maxJumpSpeed) { yVel = maxJumpSpeed; } else { yVel -= gravity; } } else { yVel = 0; } }
private void Update() { if (Managers.GameManager.Instance.IsPaused) { return; } if (this.player.IsDead) { this.anim.SetBool(this.aimHash, false); this.anim.SetBool(this.shootHash, false); return; } bool shouldAim = ShouldAim(); if (shouldAim) { this.aimDir = GetAimDir(); CalculateClipSet(Vector2.SignedAngle(Vector2.right, this.aimDir)); } bool shouldShoot = false; if (this.shotTimer > 0) { this.shotTimer -= Time.deltaTime; } if (CustomInput.BoolHeld(CustomInput.UserInput.Shoot1) || CustomInput.BoolHeld(CustomInput.UserInput.Shoot2)) { shouldShoot = true; } if (CustomInput.BoolFreshPress(CustomInput.UserInput.Shoot1)) { if (this.prevBullet != null && this.prevBullet.gameObject.activeSelf) { this.prevBullet.Detonate(); this.prevBullet = null; this.shotTimer = this.spaceTime / 2f; } } this.anim.SetBool(this.aimHash, shouldAim); this.anim.SetBool(this.shootHash, shouldShoot); this.currentState = this.mapper.GetCurrentState(); switch (this.currentState) { case State.Idle: Idle(); break; case State.Aim: Aim(); break; case State.Shoot: Shoot(); break; } }
// Update is called once per frame void Update() { if (CustomInput.BoolHeld(CustomInput.UserInput.Right)) { Navigate(CustomInput.UserInput.Right); } if (CustomInput.BoolHeld(CustomInput.UserInput.Left)) { Navigate(CustomInput.UserInput.Left); } }
private void Update() { if (Managers.GameManager.Instance.IsPaused) { return; } this.anim.SetBool(this.move, (CustomInput.BoolHeld(CustomInput.UserInput.Left) || CustomInput.BoolHeld(CustomInput.UserInput.Right))); if (CustomInput.BoolFreshPress(CustomInput.UserInput.Jump)) { this.anim.SetTrigger(this.jump); jumpSound.Play(); } }
private float GetXVel() { float xVel = this.rgbdy.velocity.x; if (CustomInput.BoolHeld(CustomInput.UserInput.Left)) { xVel = -this.speed; } else if (CustomInput.BoolHeld(CustomInput.UserInput.Right)) { xVel = this.speed; } return(xVel); }
private void Update() { if (Managers.GameState.Instance.IsPaused) { return; } this.Up = CustomInput.BoolHeld(CustomInput.UserInput.Up); this.Down = CustomInput.BoolHeld(CustomInput.UserInput.Down); this.Left = CustomInput.BoolHeld(CustomInput.UserInput.Left); this.Right = CustomInput.BoolHeld(CustomInput.UserInput.Right); this.anim.SetBool(this.moveHash, this.Up || this.Down || this.Left || this.Right); this.anim.SetBool(this.attackHash, CustomInput.BoolHeld(CustomInput.UserInput.Attack)); if (CustomInput.BoolFreshPress(CustomInput.UserInput.NextWeapon)) { this.behavior.GoToNextWeapon(); } if (CustomInput.BoolFreshPress(CustomInput.UserInput.PrevWeapon)) { this.behavior.GoToPreviousWeapon(); } }
/// <summary> Gets inputted actions from the player. </summary> /// <param name="actions">A set of action keys that the player has just pressed in the current frame.</param> protected virtual void GetInput(out HashSet <CustomInput.UserInput> actions) { this.Up = CustomInput.BoolHeld(CustomInput.UserInput.Up); this.Down = CustomInput.BoolHeld(CustomInput.UserInput.Down); this.Left = CustomInput.BoolHeld(CustomInput.UserInput.Left); this.Right = CustomInput.BoolHeld(CustomInput.UserInput.Right); actions = new HashSet <CustomInput.UserInput>(); CustomInput.UserInput[] actionEnums = { CustomInput.UserInput.Attack, CustomInput.UserInput.NextWeapon, CustomInput.UserInput.PrevWeapon, CustomInput.UserInput.Target }; foreach (CustomInput.UserInput action in actionEnums) { if (CustomInput.BoolFreshPress(action)) { actions.Add(action); } } }
void Update() { // Temp, remove later if (Input.GetKeyUp(KeyCode.Escape)) { Application.Quit(); } Attack(CustomInput.BoolFreshPress(CustomInput.UserInput.Attack)); Up(CustomInput.BoolHeld(CustomInput.UserInput.Up)); //Checks if up is being held. Down(CustomInput.BoolHeld(CustomInput.UserInput.Down)); //Checks if down is being held. Jump(CustomInput.BoolFreshPress(CustomInput.UserInput.Jump)); anim.SetBool("Control", CustomInput.BoolFreshPress(CustomInput.UserInput.Control)); if (CustomInput.BoolHeld(CustomInput.UserInput.Left)) { Left(true); Right(false); Move(true); MoveSpeed(CustomInput.Raw(CustomInput.UserInput.Left)); } else if (CustomInput.BoolHeld(CustomInput.UserInput.Right)) { Left(false); Right(true); Move(true); MoveSpeed(CustomInput.Raw(CustomInput.UserInput.Right)); } else { Left(false); Right(false); Move(false); MoveSpeed(0f); } }
void Update() { if (this.state != State.waiting) { this.image.sprite = this.backgrounds[this.whichBackgroundForWhichPage[currentPage]]; this.text.text = this.currentText.ToString(); } if (this.state == State.waiting) { if (start) { GameState.Instance.State = Enums.GameState.Cutscene; this.state = State.displaying; this.pageChars = this.pageStrings[this.currentPage].ToCharArray(); this.canvas.SetActive(true); } } else if (this.state == State.displaying) { if (CustomInput.BoolFreshPressDeleteOnRead(CustomInput.UserInput.Pause)) { this.currentText = new System.Text.StringBuilder(this.pageStrings[this.currentPage]); this.state = State.paused; } else { if (this.currentLetter == 0) { this.currentText.Append(this.pageChars[(int)currentLetter]); } int a = (int)(currentLetter); float temp = this.textSpeed; if (CustomInput.BoolHeld(CustomInput.UserInput.Accept) || CustomInput.BoolHeld(CustomInput.UserInput.Attack)) { temp *= 2; } this.currentLetter += temp * Time.deltaTime; if (a < (int)this.currentLetter && this.currentLetter < this.pageChars.Length) { this.currentText.Append(this.pageChars[(int)this.currentLetter]); this.sound.PlaySong(0); } if (this.currentLetter >= this.pageChars.Length) { //currentText = new System.Text.StringBuilder(pageStrings[currentPage]); this.state = State.paused; } } } else { if (CustomInput.BoolFreshPressDeleteOnRead(CustomInput.UserInput.Accept) || CustomInput.BoolFreshPressDeleteOnRead(CustomInput.UserInput.Attack) || CustomInput.BoolFreshPressDeleteOnRead(CustomInput.UserInput.Pause)) { this.currentLetter = 0; this.currentPage++; if (this.currentPage >= this.pages.Length) { this.text.text = ""; GameState.Instance.State = Enums.GameState.Playing; this.canvas.SetActive(false); Destroy(this.gameObject); } else { this.pageChars = this.pageStrings[this.currentPage].ToCharArray(); this.currentText = new System.Text.StringBuilder(); this.state = State.displaying; } } } }
void Update() { if (!start) { if (GameState.Instance.IsPaused && GameState.Instance.State != Enums.GameState.Cutscene) { return; } else if (!this.doOnce) { GameState.Instance.State = Enums.GameState.Cutscene; DungeonManager.GetHero().SetActive(false); for (int i = 0; i < this.actors.Length; i++) { if (this.actorEntrancePage[i] == 0) { this.actors[i].StartTranslate(true); } } this.doOnce = true; } } if (this.waitingToExit) { bool allDone = true; foreach (Effects.Translate actor in this.actors) { if (!actor.Finished) { allDone = false; } } if (allDone) { GameState.Instance.State = Enums.GameState.Playing; DungeonManager.GetHero().SetActive(true); DungeonManager.TransitionMaps(); } } if (this.state != State.waiting && !this.waitingToExit) { this.image.sprite = this.backgrounds[this.whichBackgroundForWhichPage[currentPage]]; this.text.text = this.currentText.ToString(); } if (this.state == State.waiting) { if (start) { this.state = State.displaying; this.pageChars = this.pageStrings[this.currentPage].ToCharArray(); this.canvas.SetActive(true); } else { bool allDone = true; foreach (Effects.Translate actor in this.actors) { if (!actor.Finished) { allDone = false; } } if (allDone) { start = true; } } } else if (this.state == State.displaying) { if (CustomInput.BoolFreshPress(CustomInput.UserInput.Pause)) { this.currentText = new System.Text.StringBuilder(this.pageStrings[this.currentPage]); this.state = State.paused; } else { if (this.currentLetter == 0) { this.currentText.Append(this.pageChars[(int)currentLetter]); } int a = (int)(currentLetter); float temp = this.textSpeed; if (CustomInput.BoolHeld(CustomInput.UserInput.Accept) || CustomInput.BoolHeld(CustomInput.UserInput.Attack)) { temp *= 2; } this.currentLetter += temp * Time.deltaTime; if (a < (int)this.currentLetter && this.currentLetter < this.pageChars.Length) { this.currentText.Append(this.pageChars[(int)this.currentLetter]); this.sound.PlaySong(0); } if (this.currentLetter >= this.pageChars.Length) { //currentText = new System.Text.StringBuilder(pageStrings[currentPage]); this.state = State.paused; } } } else { if (CustomInput.BoolFreshPress(CustomInput.UserInput.Accept) || CustomInput.BoolFreshPress(CustomInput.UserInput.Attack) || CustomInput.BoolFreshPress(CustomInput.UserInput.Pause)) { this.currentLetter = 0; this.currentPage++; for (int i = 0; i < this.actors.Length; i++) { if (this.actorEntrancePage[i] == this.currentPage) { this.actors[i].StartTranslate(true); } } for (int i = 0; i < this.actors.Length; i++) { if (this.actorExitPage[i] == this.currentPage) { this.actors[i].transform.localScale = new Vector3( -this.actors[i].transform.localScale.x, this.actors[i].transform.localScale.y, this.actors[i].transform.localScale.z); this.actors[i].StartTranslate(false); } } if (this.currentPage >= this.pages.Length) { this.text.text = ""; this.canvas.SetActive(false); this.waitingToExit = true; this.start = false; this.state = State.waiting; } else { this.pageChars = this.pageStrings[this.currentPage].ToCharArray(); this.currentText = new System.Text.StringBuilder(); this.state = State.displaying; } } } }