Пример #1
0
    public void FireReleased()
    {
        if (chargeTimeCurrent >= chargeTimeMax)
        {
            if (gunDatsuManager.InGunDatsu)
            {
                FireShotgun(gunDatsuManager.GetTargetPosition());
            }
            else
            {
                FireShotgun(DirectionHelper.GetDirectionVector(movementManager.forwardDirection));
            }
        }
        else
        {
            if (gunDatsuManager.InGunDatsu)
            {
                FirePistol(gunDatsuManager.GetTargetPosition());
            }
            else
            {
                FirePistol(DirectionHelper.GetDirectionVector(movementManager.forwardDirection));
            }
        }

        charging          = false;
        chargeTimeCurrent = 0;
    }
Пример #2
0
    public void AimInput(float horizontal, float vertical)
    {
        if (!InGunDatsu)
        {
            return;
        }

        castDirection = new Vector2();
        Vector3      target = new Vector3();
        RaycastHit2D hit;

        if (horizontal == 0 && vertical == 0)
        {
            castDirection = DirectionHelper.GetDirectionVector(movementManager.forwardDirection);
        }
        else
        {
            Vector2 playerPos2D = new Vector2(transform.position.x, transform.position.y);
            castDirection = (playerPos2D + new Vector2(horizontal, vertical)) - playerPos2D;
        }
        hit = Physics2D.Raycast(transform.position, castDirection, Mathf.Infinity, LayerMask.GetMask("Enemy"));
        if (hit)
        {
            target = hit.point;
        }
        else
        {
            target = castDirection * 10000;
        }

        aimLineInstance.SetPositions(new Vector3[] { transform.position, target });
    }
Пример #3
0
    private void MovementUpdate()
    {
        if (!HasMovementFreedom)
        {
            return;
        }

        if (jumpHeld)
        {
            currentJumpHoldTime += Time.deltaTime;
            if (currentJumpHoldTime > maxJumpHoldTime)
            {
                JumpReleased();
            }
        }

        if (IsDashing)
        {
            playerRigidbody.velocity = DirectionHelper.GetDirectionVector(forwardDirection) * dashSpeed;
            currentDashTime         += Time.deltaTime;
            if (currentDashTime > maxDashTime)
            {
                DashReleased();
            }
            return;
        }

        if (jumpHeld)
        {
            currentJumpHoldTime += Time.deltaTime;
            if (currentJumpHoldTime > maxJumpHoldTime)
            {
                JumpReleased();
            }
        }

        if (IsExecuting)
        {
            transform.position = initialPosition + (new Vector3(RootMotionOffset.x * DirectionHelper.GetDirectionVector(forwardDirection).x, RootMotionOffset.y));
        }

        if (!CanMove)
        {
            return;
        }

        if (MovementInput != 0)
        {
            float yVelocity = IsWallclimbing ? wallslideSpeed : playerRigidbody.velocity.y;
            playerRigidbody.velocity = new Vector2(MovementInput * regularRunSpeed, yVelocity);
        }
    }
Пример #4
0
        //public async Task MoveUnitAsync(IGameUnit unit, IGameMapMovementRoute route)
        //{
        //    await MoveUnitCoroutine(unit, route);
        //}


        /// <summary>
        ///
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="route"></param>
        /// <returns></returns>
        public IEnumerator MoveUnitCoroutine(IGameUnit unit, IGameMapMovementRoute route)
        {
            // Create a container for our move unit
            var moveUnitChangeContainer = new MoveUnitChangeContainer(unit);

            // Quick pre-calculation if we need to do walking damage
            var hasWalkingDamage = unit.GetAttribute(UnitAttribute.WalkingDamage) > 0;

            // Move the unit each step in the given route, excluding None direction steps
            foreach (var routeStep in route.Route.Where(x => x != Direction.None))
            {
                var startPosition   = unit.WorldPosition;
                var directionVector = DirectionHelper.GetDirectionVector(routeStep);
                var targetPosition  = unit.WorldPosition + directionVector;

                // Animate the unit moving this step
                var duration = 0.15f; // 0.15f seconds
                var stepTime = 0f;

                while (stepTime < duration)
                {
                    stepTime          += Time.deltaTime;
                    unit.WorldPosition = Vector3.Lerp(startPosition, targetPosition, stepTime / duration);
                    yield return(null);
                }

                // Animation complete, set the unit position to be the end location
                unit.WorldPosition = targetPosition;
                var newX = unit.MapX;
                var newY = unit.MapY;
                DirectionHelper.ApplyDirection(routeStep, ref newX, ref newY);
                unit.MapX = newX;
                unit.MapY = newY;

                // Apply walking damage to the tiles the unit now occupies
                if (hasWalkingDamage)
                {
                    ApplyWalkingDamage(unit, newX, newY, unit.TileWidth, unit.TileHeight, moveUnitChangeContainer);
                }
            }

            // Final snap the unit to their end map & unity location
            unit.MapX          = route.EndX;
            unit.MapY          = route.EndY;
            unit.WorldPosition = TranslateMapXYToUnityXY(unit.MapX, unit.MapY);
            // And tell them to consume movement for this route
            unit.AddRouteCost(route);
            // Trigger the MoveCompleted event now that we're done animating the move
            OnUnitMoveCompleted(moveUnitChangeContainer);
        }
    private IEnumerator FireProjectile()
    {
        while (Health > 0)
        {
            yield return(new WaitForSecondsRealtime(timeBetweenAttacks));

            if (!playerSensor.playerInRange)
            {
                continue;
            }
            EnemyProjectile projectile      = Instantiate(projectilePrefab, transform.position, Quaternion.identity).GetComponent <EnemyProjectile>();
            Vector2         playerDirection = DirectionHelper.GetDirectionVector((player.transform.position - transform.position).x > 0 ? EDirection.Right : EDirection.Left);
            projectile.TargetPosition = transform.position + new Vector3(playerDirection.x, playerDirection.y, 0);
        }
    }
Пример #6
0
    private void UpdateVelocity()
    {
        if (executed)
        {
            return;
        }

        if (Health > 0)
        {
            enemyRigidbody.velocity = (DirectionHelper.GetDirectionVector(moveDirection) * moveSpeed) + new Vector2(0, enemyRigidbody.velocity.y);
        }
        else
        {
            enemyRigidbody.velocity = new Vector2();
        }
    }
Пример #7
0
    public void JumpPressed()
    {
        if ((!IsGrounded || !CanMove) && !IsWallclimbing)
        {
            return;
        }

        if (IsWallclimbing)
        {
            playerRigidbody.AddForce(new Vector2(JumpPower * -2 * DirectionHelper.GetDirectionVector(forwardDirection).x, JumpPower));
        }
        else
        {
            playerRigidbody.AddForce(new Vector2(0, JumpPower));
        }
        playerRigidbody.gravityScale = jumpGravityScale;
        jumpHeld = true;
    }