/// <summary>
    /// Checks actor's inventory for projectile, then shoots it from actor's position
    /// </summary>
    /// <param name="actor">Actor</param>
    private void Shoot(Actor actor)
    {
        GameController.Log("Executing ShootCommand on " + actor.name, GameController.LogCommands);

        // Retrieve projectile from actor inventory
        projectile = GetProjectile(actor);

        if (projectile != null)
        {
            // Set bullet on player
            projectile.transform.position = actor.transform.position;

            // Get direction actor is facing (TODO: consider handling this for actors that don't rotate)
            BaseConstants.Direction direction = actor.GetComponent <MoveComponent>().currentDirection;
            GameController.Log("Projectile direction: " + direction.ToString(), GameController.LogCommands);

            // Send projectile in that direction
            Vector2 trajectory = DirectionHelper.DirectionToVector(direction);
            projectile.Shoot(trajectory, actor);
        }
        else
        {
            GameController.LogWarning("Primary Shoot Command: could not find projectile in actor " + actor.name + "'s inventory", GameController.LogCommands);
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// Returns true if player can move in given direction at this intersection, false otherwise
 /// </summary>
 /// <param name="direction">The direction.</param>
 /// <param name="intersection">The intersection.</param>
 protected bool CanMove(BaseConstants.Direction direction)
 {
     if (intersection != null)
     {
         return(intersection.validDirections.Contains(direction));
     }
     return(false);
 }
Exemplo n.º 3
0
    /// <summary>
    /// Animates movement based on horizontal/vertical input
    /// </summary>
    /// <param name="input">Player input</param>
    protected void AnimateWalk(Vector2 input)
    {
        // Get current direction
        currentDirection = (BaseConstants.Direction)animator.GetInteger("Direction");

        // Calculate and set new direction
        BaseConstants.Direction newDirection = FaceDirection(input);
        animator.SetInteger("Direction", (int)newDirection);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Moves player in specified direction.
    /// </summary>
    /// <param name="direction">The direction.</param>
    protected void Move(BaseConstants.Direction direction)
    {
        // Move actor in direction of input
        Vector2 movement = DirectionHelper.DirectionToVector(direction) * moveSpeed;

        rbody.velocity = movement;

        // Save direction to use next frame
        currentDirection = direction;
    }
Exemplo n.º 5
0
    public void ManageMovement()
    {
        Vector2 input = GetInput();

        BaseConstants.Direction direction = DirectionHelper.VectorToDirection(input);

        if (direction != BaseConstants.Direction.None)
        {
            Move(direction);

            // Animate walking if receiving input
            if (!currentDirection.Equals(BaseConstants.Direction.None))
            {
                AnimateMovement();
            }
        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// Converts Direction to Vector2
    /// </summary>
    /// <param name="direction">Direction</param>
    public static Vector2 DirectionToVector(BaseConstants.Direction direction)
    {
        switch (direction)
        {
        case BaseConstants.Direction.Up:
            return(Vector2.up);

        case BaseConstants.Direction.Down:
            return(Vector2.down);

        case BaseConstants.Direction.Left:
            return(Vector2.left);

        case BaseConstants.Direction.Right:
            return(Vector2.right);

        default:
            return(Vector2.zero);
        }
    }
Exemplo n.º 7
0
 /// <summary>
 /// Returns true if direction is vertical
 /// </summary>
 /// <param name="direction">Direction</param>
 public static bool IsVertical(BaseConstants.Direction direction)
 {
     return(direction == BaseConstants.Direction.Up || direction == BaseConstants.Direction.Down);
 }
Exemplo n.º 8
0
 public static float?DirectionToRotation(BaseConstants.Direction direction)
 {
     return(directionRotationMapping[direction]);
 }