private void KillSelf(ZMPlayerController killer) { GameObject body; var infoArgs = new ZMPlayerInfoEventArgs(_playerInfo); _moveModState = MoveModState.RESPAWN; _controlModState = ControlModState.NEUTRAL; _controlMoveState = ControlMoveState.NEUTRAL; Notifier.SendEventNotification(OnPlayerDeath, infoArgs); Utilities.StopDelayRoutine(_endLungeCoroutine); Utilities.StopDelayRoutine(_resetControlModCoroutine); Utilities.StopDelayRoutine(_enablePlayerCoroutine); // Handle death visuals here _material.color = Color.red; _light.enabled = false; _spriteRenderer.enabled = false; // load and instantiate the body's upper half body = GameObject.Instantiate(_upperBodyTemplate) as GameObject; body.transform.position = transform.position; ZMAddForce upperBody = body.GetComponent <ZMAddForce>(); upperBody.ParticleColor = _light.color; upperBody.AddForce(new Vector2(killer.runSpeed / 12, 0)); // load and instantiate the body's lower half body = GameObject.Instantiate(_lowerBodyTemplate) as GameObject; body.transform.position = transform.position; ZMAddForce lowerBody = body.GetComponent <ZMAddForce>(); lowerBody.ParticleColor = _light.color; lowerBody.AddForce(new Vector2(killer.runSpeed / 12, 0)); // Set player states _playerInPath = false; ClearInputEvents(); _audio.PlayOneShot(_audioGore[Random.Range(0, _audioGore.Length)]); _audio.PlayOneShot(_audioHurt[Random.Range(0, _audioHurt.Length)]); _audio.PlayOneShot(_audioKill[Random.Range(0, _audioKill.Length)]); _goreEmitter.Play(); }
private void MoveLeftEvent() { if (IsAbleToReceiveInput()) { _controlMoveState = ControlMoveState.MOVING; if (_movementDirection == MovementDirectionState.FACING_RIGHT) { CheckSkidding(); } if (!IsLunging()) { SetMovementDirection(MovementDirectionState.FACING_LEFT); } } }
private void Reset() { _controlModState = ControlModState.NEUTRAL; _controlMoveState = ControlMoveState.NEUTRAL; runSpeed = 0.0f; _spriteRenderer.enabled = true; _light.enabled = true; EnablePlayer(); SetMovementDirection(transform.position.x < 0 ? MovementDirectionState.FACING_LEFT : MovementDirectionState.FACING_RIGHT); if (!MatchStateManager.IsPause() && !MatchStateManager.IsEnd()) { AcceptInputEvents(); } }
private void NoMoveEvent() { _controlMoveState = ControlMoveState.NEUTRAL; }
void Update() { // Set raycasts. These will check one tile unit to the left and right to help with things like wall jump. _checkTouchingLeft = Environment.CheckLeft(transform.position, LEFT_EDGE_OFFSET, TILE_SIZE, _controller.platformMask); _checkTouchingRight = Environment.CheckRight(transform.position, RIGHT_EDGE_OFFSET, TILE_SIZE, _controller.platformMask); // Update the velocity calculated from the controller. _velocity = _controller.velocity; // Check raycasts. if (_controller.isGrounded) { // Landing. if (_velocity.y < -1) { _audio.PlayOneShot(_audioLand[Random.Range(0, _audioLand.Length)], 0.5f); Instantiate(_effectLandObject, new Vector2(transform.position.x - 3, transform.position.y - 8), transform.rotation); } _velocity.y = 0; if (IsPlunging()) { _audio.PlayOneShot(_audioSword[Random.Range(0, _audioSword.Length)], 1.0f); Notifier.SendEventNotification(OnPlayerLandPlunge); } } // Horizontal movement. Only want to move if we aren't doing some kind of attack // or getting knocked back (recoiling). if (_controlMoveState == ControlMoveState.MOVING && !IsPlunging() && !IsRecoiling()) { if (_movementDirection == MovementDirectionState.FACING_RIGHT) { if (runSpeed < RUN_SPEED_MAX) { runSpeed += ACCELERATION; } } else if (_movementDirection == MovementDirectionState.FACING_LEFT) { if (runSpeed > -RUN_SPEED_MAX) { runSpeed -= ACCELERATION; } } if (_controller.isGrounded && Mathf.Abs(_velocity.x) > ACCELERATION) { _framesUntilStep++; if (_framesUntilStep >= FRAMES_PER_STEP) { _framesUntilStep = 0; _audio.PlayOneShot(_audioStep[Random.Range(0, _audioStep.Length)], 0.25f); } } } // Friction. if (Mathf.Abs(runSpeed) <= FRICTION) { runSpeed = 0.0f; } else { if (_controlMoveState == ControlMoveState.NEUTRAL) { runSpeed -= FRICTION * Mathf.Sign(runSpeed); } } // Jumping. if (_controlModState == ControlModState.JUMPING) { _controlModState = ControlModState.NEUTRAL; _velocity.y = JUMP_HEIGHT; _audio.PlayOneShot(_audioJump[Random.Range(0, _audioJump.Length)]); Instantiate(_effectJumpObject, new Vector2(transform.position.x - 3, transform.position.y - 8), transform.rotation); } // Update movement and ability state. if (_controlModState == ControlModState.ATTACK) { if (!IsLunging() && _canLunge) { HorizontalAttack(); } else { _audio.PlayOneShot(_audioLungeFail); } } else if (_controlModState == ControlModState.AIR_ATTACK) { if (!IsLunging() && _canLunge && _canAirLunge) { _canAirLunge = false; HorizontalAttack(); } else { _audio.PlayOneShot(_audioLungeFail); } } else if (_controlModState == ControlModState.PLUNGE) { _controlModState = ControlModState.PLUNGING; if (!IsPlunging()) { _audio.PlayOneShot(_audioPlunge[Random.Range(0, _audioPlunge.Length)]); _moveModState = MoveModState.PLUNGE; } } else if (_controlModState == ControlModState.PARRY) { var playerArgs = new ZMPlayerControllerFloatEventArgs(this, PARRY_STUN_WINDOW + PARRY_TIME); _controlModState = ControlModState.PARRYING; _moveModState = MoveModState.PARRY_FACING; _canStun = true; _canLunge = false; GameObject effect = Instantiate(_effectClashObject, new Vector2(transform.position.x, transform.position.y), transform.rotation) as GameObject; effect.transform.parent = transform; effect.transform.localScale = new Vector3(0.66f, 0.66f, 1.0f); _material = _materialFlash; _audio.PlayOneShot(_audioParry); if (_controller.isGrounded) { Utilities.ExecuteAfterDelay(EndStunBeginParry, PARRY_STUN_WINDOW); DisableInputWithCallbackDelay(PARRY_STUN_WINDOW + PARRY_TIME); Notifier.SendEventNotification(OnPlayerParry, playerArgs); } } else if (_controlModState == ControlModState.NEUTRAL) { if (_controller.isGrounded) { _canAirLunge = true; } if (IsTouchingEitherSide()) { if (!_controller.isGrounded && _moveModState == MoveModState.NEUTRAL) { _moveModState = MoveModState.WALL_SLIDE; } } } if (_moveModState == MoveModState.PLUNGE) { _moveModState = MoveModState.PLUNGING; Plunge(); } else if (_moveModState == MoveModState.PLUNGING) { if (_controller.isGrounded) { ZMPlayerController playerController; var recoilOffsetRight = new Vector2(EDGE_OFFSET, -16.0f); var recoilOffsetLeft = new Vector2(-EDGE_OFFSET, -16.0f); var recoilAOE = Environment.CheckRight(transform.position, recoilOffsetRight, AOE_RANGE, _controller.specialInteractibleMask); Instantiate(_effectPlungeObject, new Vector2(transform.position.x, transform.position.y), transform.rotation); // Check right. if (recoilAOE) { playerController = recoilAOE.collider.GetComponent <ZMPlayerController>(); if (playerController != null) { playerController._movementDirection = MovementDirectionState.FACING_LEFT; playerController._moveModState = MoveModState.RECOIL; } } // Check left: recoilAOE = Environment.CheckLeft(transform.position, recoilOffsetLeft, AOE_RANGE, _controller.specialInteractibleMask); if (recoilAOE) { playerController = recoilAOE.collider.GetComponent <ZMPlayerController>(); if (playerController != null) { playerController._movementDirection = MovementDirectionState.FACING_RIGHT; playerController._moveModState = MoveModState.RECOIL; } } _moveModState = MoveModState.PARRY_AOE; DisablePlayer(); _enablePlayerCoroutine = Utilities.ExecuteAfterDelay(EnablePlayer, PARRY_TIME_LUNGE); _resetControlModCoroutine = Utilities.ExecuteAfterDelay(ResetControlModState, PARRY_TIME_LUNGE + 0.02f); } } else if (_moveModState == MoveModState.LUNGE) { _moveModState = _controller.isGrounded ? MoveModState.LUNGING_GROUND : MoveModState.LUNGING_AIR; RaycastHit2D checkPlayer; if (_movementDirection == MovementDirectionState.FACING_RIGHT) { if (checkPlayer = Environment.CheckRight(transform.position, RIGHT_EDGE_OFFSET, 145f, _controller.specialInteractibleMask)) { if (checkPlayer.collider.CompareTag(Tags.kPlayerTag) && !_playerInPath) { _playerInPath = true; } } LungeRight(); } else if (_movementDirection == MovementDirectionState.FACING_LEFT) { if (checkPlayer = Environment.CheckLeft(transform.position, LEFT_EDGE_OFFSET, 145f, _controller.specialInteractibleMask)) { if (checkPlayer.collider.CompareTag(Tags.kPlayerTag) && !_playerInPath) { _playerInPath = true; } } LungeLeft(); } // End the lunge after a delay so we don't zoom across the map forever. Utilities.StopDelayRoutine(_endLungeCoroutine); _endLungeCoroutine = Utilities.ExecuteAfterDelay(EndLunge, LUNGE_TIME); } if (_movementDirection == MovementDirectionState.FACING_RIGHT && (_moveModState == MoveModState.LUNGING_AIR || _moveModState == MoveModState.LUNGING_GROUND)) { var hit = Environment.CheckRight(transform.position, RIGHT_EDGE_OFFSET, 4, _controller.platformMask); if (hit && !hit.collider.CompareTag("Breakable")) { _audio.PlayOneShot(_audioSword[Random.Range(0, _audioSword.Length)], 1.0f); Quaternion rotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 90.0f)); Instantiate(_effectPlungeObject, new Vector2(transform.position.x - 18, transform.position.y), rotation); EndLunge(); } } else if (_movementDirection == MovementDirectionState.FACING_LEFT && (_moveModState == MoveModState.LUNGING_AIR || _moveModState == MoveModState.LUNGING_GROUND)) { var hit = Environment.CheckLeft(transform.position, LEFT_EDGE_OFFSET, 4, _controller.platformMask); if (hit && !hit.collider.CompareTag("Breakable")) { _audio.PlayOneShot(_audioSword[Random.Range(0, _audioSword.Length)], 1.0f); Quaternion rotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 270.0f)); Instantiate(_effectPlungeObject, new Vector2(transform.position.x + 14, transform.position.y), rotation); EndLunge(); } } if (_moveModState == MoveModState.RECOIL) { var playerArgs = new ZMPlayerControllerFloatEventArgs(this, RECOIL_STUN_TIME); _audio.PlayOneShot(_audioSword[Random.Range(0, _audioSword.Length)], 1.0f); Instantiate(_effectClashObject, new Vector2(transform.position.x, transform.position.y), transform.rotation); _moveModState = MoveModState.RECOILING; Utilities.StopDelayRoutine(_endLungeCoroutine); Recoil(); DisableInputWithCallbackDelay(RECOIL_STUN_TIME); Notifier.SendEventNotification(OnPlayerRecoil, playerArgs); } else if (_moveModState == MoveModState.RECOILING) { _moveModState = MoveModState.NEUTRAL; _controlModState = ControlModState.NEUTRAL; _controlMoveState = ControlMoveState.NEUTRAL; _playerInPath = false; } else if (_moveModState == MoveModState.STUN) { var playerArgs = new ZMPlayerControllerFloatEventArgs(this, STUN_TIME); _moveModState = MoveModState.STUNNED; _controlModState = ControlModState.NEUTRAL; _controlMoveState = ControlMoveState.NEUTRAL; _audio.PlayOneShot(_audioSword[Random.Range(0, _audioSword.Length)], 1.0f); Utilities.StopDelayRoutine(_endLungeCoroutine); Recoil(); Utilities.ExecuteAfterDelay(ResetMoveModState, STUN_TIME); DisableInputWithCallbackDelay(STUN_TIME); Notifier.SendEventNotification(OnPlayerStun, playerArgs); } else if (_moveModState == MoveModState.WALL_SLIDE) { // Wall slide. if (_velocity.y < 1.0f && _controlMoveState == ControlMoveState.MOVING) { _velocity.y = -WALL_SLIDE_SPEED; if (IsTouchingRightAndMovingRight() || IsTouchingLeftAndMovingLeft()) { runSpeed = 0; } } if (_controller.isGrounded || !IsTouchingEitherSide()) { _moveModState = MoveModState.NEUTRAL; } // Wall jump. if (_controlModState == ControlModState.WALL_JUMPING) { _controlModState = ControlModState.NEUTRAL; if (IsMovingLeft() || IsMovingRight()) { if (!_controller.isGrounded) { var rotation = Quaternion.Euler(new Vector3(0.0f, (_movementDirection == MovementDirectionState.FACING_RIGHT ? 180.0f : 0.0f), 0.0f)); var skidOffset = _movementDirection == MovementDirectionState.FACING_RIGHT ? 12.0f : -12.0f; _velocity.y = JUMP_HEIGHT; _audio.PlayOneShot(_audioJump[Random.Range(0, _audioJump.Length)]); Instantiate(_effectSkidObject, new Vector2(transform.position.x + skidOffset, transform.position.y - 20), rotation); _moveModState = MoveModState.NEUTRAL; _canWallJump = false; _canAirLunge = true; Utilities.ExecuteAfterDelay(WallJumpCooldown, 0.05f); if (IsMovingLeft()) { runSpeed = WALL_JUMP_KICK_SPEED * 0.6f; } else if (IsMovingRight()) { runSpeed = -WALL_JUMP_KICK_SPEED * 0.6f; } } } } } else if (IsAttacking() || IsPlunging()) { var dist = 0.0f; var lerpPos = _posPrevious; var mult = 0.5f; if (_fadeSpawnIndex == _fadeSpawnCycleLen) { // ZVP var fadeObject = Instantiate(_fadeEffect, lerpPos, transform.rotation) as SpriteRenderer; lerpPos = Vector3.Lerp(lerpPos, transform.position, mult * Time.deltaTime); fadeObject.sprite = _spriteRenderer.sprite; dist += Vector3.Distance(transform.position, lerpPos); _fadeSpawnIndex = 0; } _fadeSpawnIndex += 1; } // Update visuals. if (!_controller.isGrounded && !_canAirLunge) { Color color = _material.color; color.a = 0.5f; _material.color = color; } else { Color color = _material.color; color.a = 1.0f; _material.color = color; } // Update and apply velocity. _velocity.x = runSpeed; _velocity.y -= GRAVITY * Time.deltaTime; // Don't want gravity to affect the player if lunging. if (IsLunging()) { _velocity.y = 0.0f; } _posPrevious = transform.position; _controller.move(_velocity * Time.deltaTime); UpdateAnimator(); }