コード例 #1
0
        public override void _Input(InputEvent inputEvent)
        {
            if (inputEvent is InputEventKey eventKey && !inputEvent.IsEcho() && eventKey.IsPressed())
            {
                // entityAnimator.SkipAnimations();

                switch (eventKey.Scancode)
                {
                case (uint)KeyList.Up:
                    entityAnimator.Move(entityAnimator.actualPosition + Vector2.Up * 100, MovementAnim.EMovementType.Walk);
                    break;

                case (uint)KeyList.Down:
                    entityAnimator.Move(entityAnimator.actualPosition + Vector2.Down * 100, MovementAnim.EMovementType.Walk);
                    break;

                case (uint)KeyList.Right:
                    entityAnimator.Move(entityAnimator.actualPosition + Vector2.Right * 100, MovementAnim.EMovementType.Walk);
                    break;

                case (uint)KeyList.Left:
                    entityAnimator.Move(entityAnimator.actualPosition + Vector2.Left * 100, MovementAnim.EMovementType.Walk);
                    break;

                case (uint)KeyList.W:
                    entityAnimator.Attack(entityAnimator.actualPosition + Vector2.Up * 100);
                    break;

                case (uint)KeyList.S:
                    entityAnimator.Attack(entityAnimator.actualPosition + Vector2.Down * 100);
                    break;

                case (uint)KeyList.D:
                    entityAnimator.Attack(entityAnimator.actualPosition + Vector2.Right * 100);
                    break;

                case (uint)KeyList.A:
                    entityAnimator.Attack(entityAnimator.actualPosition + Vector2.Left * 100);
                    break;

                case (uint)KeyList.Space:
                    entityAnimator.GetHit();
                    break;

                case (uint)KeyList.Z:
                    entityAnimator.SetTelegraph();
                    break;

                case (uint)KeyList.X:
                    entityAnimator.SetIdle();
                    break;
                }
            }
        }
コード例 #2
0
    /// <summary>
    /// Attempt attacks when we detect a rigidbody collision.
    /// </summary>
    private void OnTriggerStay(Collider other)
    {
        // EARLY OUT! //
        // If on cooldown don't attack.
        if (!this.enabled || _cooldownSeconds > 0f)
        {
            return;
        }

        // EARLY OUT! //
        // If the trigger isn't an entity, ignore it.
        if (!CombatUtils.IsEntity(other.gameObject.layer))
        {
            return;
        }

        // EARLY OUT! //
        // If the collider isn't an enemy, ignore it.
        var target = other.GetComponent <Entity>();

        if (!CombatUtils.IsEnemy(_entity.Owner, target))
        {
            return;
        }

        bool didAttack = false;

        // Only attack if the entity is a type that this unit attacks.
        if (_entity.AttacksGroundUnits || target.IsBuilding)
        {
            didAttack  = attemptDirectAttack(target);
            didAttack |= attemptAreaAttack(target);
        }

        if (didAttack)
        {
            // Reset cooldown.
            _cooldownSeconds = _entity.AttackSpeed;

            // Play attack audio if we have any.
            if (_animator != null)
            {
                _animator.Attack();
            }
        }
    }