/// <summary> /// Обрабатывает количество шагов игрока с последнего создания сегмента-объекта для создания следующих /// </summary> private void PlayerStepsHandler() { // Увеличивает шаг stepsFromTheLastDraggableObjectCreation++; // Сообщает о новом шагу OnPlayerMoved?.Invoke(); if (stepsFromTheLastDraggableObjectCreation == 2) { if (destructionSinceTheLastCreationOfDraggableObject == 9) { GenerateNewNonDraggableSegmentObject(); stepsFromTheLastDraggableObjectCreation = 0; destructionSinceTheLastCreationOfDraggableObject = 0; } else { GenerateNewDraggableSegmentObject(); stepsFromTheLastDraggableObjectCreation = 0; } } if (GameManager.Source.BonusesAllowed) { if (stepsFromTheLastDraggableObjectCreation == 1) { GenerateNewBonus(); } } }
void Update() { var moveDirection = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized; ComponentUtils.MoveRigidbody(Rigidbody, moveDirection * Speed); ComponentUtils.LimitRigidbodySpeed(Rigidbody, Speed); if (Input.GetButtonDown(FireButtonName)) { Rigidbody.AddTorque(TorquePower, ForceMode2D.Impulse); } if (Input.GetButtonDown(BreakButtonName)) { Rigidbody.angularDrag = BreakAngularDrag; } if (Input.GetButtonDown(SelfDestructButtonName)) { Destroy(gameObject); } if (Input.GetButtonUp(BreakButtonName)) { Rigidbody.angularDrag = _defaultAngularDrag; } // Stop small rotation if ((Rigidbody.angularVelocity > -MinAngularVelocity) && (Rigidbody.angularVelocity < MinAngularVelocity)) { Rigidbody.angularVelocity = 0f; } OnPlayerMoved?.Invoke(); }
public virtual void PlayerMoved(object sender, string direction) { if (OnPlayerMoved != null) { OnPlayerMoved.Invoke(sender, direction); } }
public void TriggerRoom(Transform player) { var enemy = Instantiate(enemyDeck.GetNextCard(), new Vector2(player.position.x - offset, player.position.y + offset), Quaternion.identity); if (enemy.TryGetComponent <Combatant>(out var combatant)) { OnEnemySpawned?.Invoke(combatant); } // Move the player to the oposite corner of the room LeanTween.move(player.gameObject, new Vector2(player.position.x + offset, player.position.y - offset), timeToComplete) .setEaseOutSine() .setOnComplete(() => { OnPlayerMoved?.Invoke(); }); // Shuffle and Reset the deck; playingCardsDeck.ResetIndex(); DeckShuffler.Shuffle(playingCardsDeck.Cards); vcam.LookAt = m_transform; vcam.Follow = m_transform; spriteRenderer.sprite = null; }
public void UpdatePlayerPosition(float direction, Range playerPositionRange) { PlayerPosition += Vector3.right * direction * _playerSettings.PlayerSpeed * Time.deltaTime; PlayerPosition = new Vector3(PlayerPosition.x.Clamp(playerPositionRange), PlayerPosition.y, PlayerPosition.z); OnPlayerMoved?.Invoke(PlayerPosition); }
/// <summary> /// Map the player movement across the map using the rooms and set designated room. /// </summary> /// public void MovePlayerSouth(OnPlayerMoved callback) { var room = PlayerRoom; if (room.SouthRoom != -1) { callback(PlayerRoomIndex, room.SouthRoom); PlayerRoomIndex = room.SouthRoom; } }
/// <summary> /// Map the player movement across the map using the rooms and set designated room. /// </summary> /// public void MovePlayerWest(OnPlayerMoved callback) { var room = PlayerRoom; if (room.WestRoom != -1) { callback(PlayerRoomIndex, room.WestRoom); PlayerRoomIndex = room.WestRoom; } }
private void PlayerMovementCheck() { Vector3 movementInputRaw = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical")); if (movementInputRaw != Vector3.zero) { OnPlayerMoved?.Invoke(movementInputRaw, KeyManager.IsPressed(KeyCode.LeftShift)); _isMoving = true; } else { _isMoving = false; } }
void Update() { var oldpos = transform.localPosition; var h = Input.GetAxis("Horizontal"); var v = Input.GetAxis("Vertical"); transform.localPosition += new Vector3(h, 0, v) * _speed * Time.deltaTime; var newpos = transform.localPosition; if (oldpos != newpos) { OnPlayerMoved.Invoke(); } }
public void OnMove(InputAction.CallbackContext context) { if (moveCooldownTimer > 0) { return; } var vector = context.ReadValue <Vector2>(); if (vector == Vector2.zero) { return; } var direction = new Vector3(); if (vector.x != 0) { direction = new Vector3(Mathf.Sign(vector.x) * tileSize, 0, 0); } else if (vector.y != 0) { direction = new Vector3(0, Mathf.Sign(vector.y) * tileSize, 0); } bool canMove = true; var pushableCollider = Physics2D.OverlapCircle(transform.position + direction, 0.1f, pushableMask); if (pushableCollider) { canMove = canPush && !Physics2D.OverlapCircle(transform.position + (direction * 2), 0.1f, pushableCollisionMask); } if (canMove && !Physics2D.OverlapCircle(transform.position + direction, 0.1f, collisionMask)) { var previousPosition = transform.position; transform.position += direction; OnPlayerMoved?.Invoke(transform.position); moveCooldownTimer = moveCooldownTime; } }
private void Update() { if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0) { //UpdateRotation(); //Move(); OnPlayerMoved.Invoke(); } else { OnMovementStopped.Invoke(); } if (Input.GetKeyDown(KeyCode.Q)) { this.OnSkillPressed.Invoke(0); } if (Input.GetKeyDown(KeyCode.Space)) { this.OnSkillPressed.Invoke(2); } if (Input.GetKeyDown(KeyCode.R)) { this.OnSkillPressed.Invoke(3); } if (Input.GetMouseButtonUp(0)) { if (!IsPointerOverUIElement()) { this.OnSkillPressed.Invoke(1); } } }
private void Start() { character = GetComponent <Character>(); OnPlayerMoved.AddListener(character.HandleMoved); }
public void SetPlayerPosition(float playerHorizontalPosition, Range playerPositionRange) { PlayerPosition = new Vector3(playerHorizontalPosition.Clamp(playerPositionRange), PlayerPosition.y, PlayerPosition.z); OnPlayerMoved?.Invoke(PlayerPosition); }
public void BallChangedPosition() { OnPlayerMoved?.Invoke(); }
public void MovePlayerWest(OnPlayerMoved callback) { var room = PlayerRoom; if (room.WestRoom != -1) { callback(PlayerRoomIndex, room.WestRoom); PlayerRoomIndex = room.WestRoom; } }
public void MovePlayerSouth(OnPlayerMoved callback) { var room = PlayerRoom; if (room.SouthRoom != -1) { callback(PlayerRoomIndex, room.SouthRoom); PlayerRoomIndex = room.SouthRoom; } }
// Update is called once per frame void Update() { //Movement Logic float horizontalMovement = Input.GetAxis("Horizontal"); float verticalMovement = Input.GetAxis("Vertical"); //Debug.Log(horizontalMovement + " " + verticalMovement); //Debug.Log((Screen.height / 100f) / 2f); if (!jumped) { Vector2 targetPosition = Vector2.zero; //Vector2 fixedPosition = Vector2.zero; bool tryingToMove = false; if (horizontalMovement != 0) { targetPosition = new Vector2( transform.position.x + (horizontalMovement > 0 ? jumpDistance : -jumpDistance), transform.position.y); tryingToMove = true; } else if (verticalMovement != 0) { targetPosition = new Vector2( transform.position.x, transform.position.y + (verticalMovement > 0 ? jumpDistance : -jumpDistance)); tryingToMove = true; } //if(targetPosition!= Vector2.zero) //{ // fixedPosition = new Vector2(transform.position.x, transform.position.y + fixMove); // } Collider2D hitCollider = Physics2D.OverlapCircle(targetPosition, 0.105f); if (tryingToMove == true && (hitCollider == null || hitCollider.GetComponent <Enemy>() != null)) { transform.position = targetPosition; jumped = true; GetComponent <AudioSource>().Play(); OnPlayerMoved?.Invoke(); } } else { if (horizontalMovement == 0 && verticalMovement == 0) { jumped = false; } } //-(Screen.height / 100f) / 2f // lewy -2.88 //prawy 3.2 // góra 3.2 //Keep the frog inside bound. if (transform.position.y < -(Screen.height / 100f) / 2f) { transform.position = new Vector3(transform.position.x, transform.position.y + jumpDistance); } if (transform.position.x <= -(Screen.width / 100f) / 2f) { transform.position = new Vector2(transform.position.x + jumpDistance, transform.position.y); } if (transform.position.x > (Screen.width / 100f) / 2f) { transform.position = new Vector3(transform.position.x - jumpDistance, transform.position.y); } if (transform.position.y > (Screen.height / 100f) / 2f - 0.1f) { transform.position = startingPosition; OnPlayerEscaped?.Invoke(); } }