Ejemplo n.º 1
0
    /// <summary>
    /// Handles starting and stopping (triggering) the slingshot input.
    /// </summary>
    private void HandleSlingshotInput()
    {
        // Press to start slingshotting, release to stop
        if (!m_isSlingshotDown && Input.GetButtonDown("Fire1"))
        {
            m_isSlingshotDown             = true;
            m_usingControllerForSlingshot = false; // Will be set to true in GetPressPos if using controller
            m_slingshotStartPos           = GetPressPos();

            slingshotPullSound.Play();
            slingshotReleaseSound.Stop();

            // Only show the directional input element on touch/mouse setups as
            // they make it harder to tell where the input will take the player.
            if (!m_usingControllerForSlingshot)
            {
                m_slingshotDirectionIndicator.StartSlingshotInput(m_slingshotStartPos);
            }
        }
        else if (m_isSlingshotDown && Input.GetButtonUp("Fire1"))
        {
            m_isSlingshotDown = false;
            Vector2 launchDir = GetSlingshotDirection();
            m_playerPhysics.LaunchPlayer(launchDir);
            m_playerRotation.UpdatePlayerRotation(DirectionHelpers.RotationAngleForVector(launchDir) * Mathf.Rad2Deg, false);

            slingshotReleaseSound.Play();
            slingshotPullSound.Stop();

            if (!m_usingControllerForSlingshot)
            {
                m_slingshotDirectionIndicator.StopSlingshotInput();
            }
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Bounces the player off the collision if the collision direction is relevant.
    /// </summary>
    /// <param name="collision">Collision information.</param>
    private void CollisionBounce(Collision2D collision)
    {
        // Work out whether the contact is horizontal
        DirectionHelpers.Direction collisionDirection =
            DirectionHelpers.GetCollisionDirection(m_transform.position, collision.contacts);

        if (collisionDirection == DirectionHelpers.Direction.LEFT ||
            collisionDirection == DirectionHelpers.Direction.RIGHT)
        {
            // Reflect X component of collision velocity
            m_rigidbody.velocity = new Vector2(-m_rigidbodyVelocity.x, m_rigidbodyVelocity.y);

            // Apply bounce velocity slowdown or boost to new velocity vector
            m_rigidbody.velocity = m_rigidbody.velocity.normalized * (m_rigidbody.velocity.magnitude * wallSpeedBouncePercent);

            // Make the player face the new bounced velocity direction
            m_playerRotation.UpdatePlayerRotation(DirectionHelpers.RotationAngleForVector(m_rigidbody.velocity), false);

            // Play bounce animation
            m_playerAnimation.TriggerBounceAnim();

            bounceSound.Play();
        }

        // Landing/hitting a platform from above/below
        if (collisionDirection == DirectionHelpers.Direction.DOWN ||
            collisionDirection == DirectionHelpers.Direction.UP)
        {
            landSound.Play();
        }
    }
Ejemplo n.º 3
0
    private void PlayerRotateTick()
    {
        if (m_playerInput.isSlingshotDown)
        {
            // Lerp the rotate to keep it smooth but lerp faster so that the player's facing better reflects their input
            Vector2 launchDir = m_playerInput.GetSlingshotDirection();
            UpdatePlayerRotation(DirectionHelpers.RotationAngleForVector(launchDir) * Mathf.Rad2Deg, true, 4.0f);
        }
        else
        {
            // Lerp rotate to face velocity
            Vector2 playerVelocity   = m_rigidbody.velocity;
            float   rotationAngleDeg = 0.0f; // Lerp to face up if no velocity present
            if (playerVelocity.sqrMagnitude > 0.1f)
            {
                rotationAngleDeg = DirectionHelpers.RotationAngleForVector(playerVelocity.normalized) * Mathf.Rad2Deg;

                if (!movementSound.isPlaying)
                {
                    movementSound.Play();
                }
            }
            else
            {
                if (movementSound.isPlaying)
                {
                    movementSound.Stop();
                }
            }
            UpdatePlayerRotation(rotationAngleDeg, true);
        }
    }
Ejemplo n.º 4
0
 /// <summary>
 /// Makes the slingshot direction indicator face along the input direction vector.
 /// </summary>
 private void RotateSlingshotDirectionIndicator()
 {
     if (m_playerInput.isSlingshotDown)
     {
         // Rotate to face input
         Vector2 slingshotVector = m_playerInput.GetSlingshotDirection();
         float   rotationAngle   = DirectionHelpers.RotationAngleForVector(slingshotVector);
         m_transform.rotation = Quaternion.Euler(0.0f, 0.0f, rotationAngle * Mathf.Rad2Deg);
     }
 }
Ejemplo n.º 5
0
        private static int GetPart2(string[] lines)
        {
            var map = LoadDictionary(lines);

            PrintMap(map, 9);

            int burstInfection = 0;

            var currentDirection = Direction.Up;
            var currentPoint     = new Point(0, 0);

            for (int i = 0; i < 10000000; i++)
            {
                if (!map.ContainsKey(currentPoint))
                {
                    map[currentPoint] = '.';
                }

                var c = map[currentPoint];
                if (c == '.')
                {
                    map[currentPoint] = 'W';
                    currentDirection  = DirectionHelpers.TurnLeft(currentDirection);
                }
                else if (c == '#')
                {
                    map[currentPoint] = 'F';
                    currentDirection  = DirectionHelpers.TurnRight(currentDirection);
                }
                else if (c == 'W')
                {
                    map[currentPoint] = '#';
                    burstInfection++;
                }
                else if (c == 'F')
                {
                    map[currentPoint] = '.';
                    currentDirection  = DirectionHelpers.GetOppositeDirection(currentDirection);
                }

                currentPoint = DirectionHelpers.GetNextPoint(currentDirection, currentPoint);
            }

            PrintMap(map, 9);
            return(burstInfection);
        }