Exemplo n.º 1
0
    private void Update()
    {
        animator.SetBool(isWalkingHash, movementFactor != Vector2.zero);

        if (hasToSearchForTarget)
        {
            //search for a potential target
            float currentTime = Time.time;
            if (currentTime > lastSearchTime + searchTargetInterval)
            {
                if (targetAgent == null)
                {
                    //search for a new target (might be null anyway, because of distance)
                    targetAgent = SearchForTarget();
                }
                else
                {
                    //check if it's too far
                    distanceFromTargetSqr = GetDistanceFromTargetSqr();
                    if (distanceFromTargetSqr > searchRadius * searchRadius)
                    {
                        //target lost
                        targetAgent = null;
                    }
                }
                lastSearchTime = currentTime;
            }
        }
    }
Exemplo n.º 2
0
    public void DealDamage(RoguelikeAgent target)
    {
        bool isTargetDead = false;

        if (!target.hasBeenHit)
        {
            reward      += 1f;
            isTargetDead = target.ReceiveDamage(attackDamage);
            if (isTargetDead &&
                !academy.isInference)
            {
                done = true;
            }
        }
    }
Exemplo n.º 3
0
    protected override RoguelikeAgent SearchForTarget()
    {
        RoguelikeAgent t = GameObject.FindObjectOfType <KnightAgent>();

        if (t != null)
        {
            if ((t.transform.position - this.transform.position).sqrMagnitude < searchRadius * searchRadius)
            {
                //near enough
                return(t);
            }
            else
            {
                return(null); //too far
            }
        }
        else
        {
            return(null); //none found
        }
    }
Exemplo n.º 4
0
    public override void InitializeAgent()
    {
        rb       = GetComponent <Rigidbody2D>();
        animator = GetComponent <Animator>();
        graphicsSpriteRenderer = transform.Find("Graphics").GetComponent <SpriteRenderer>();
        healthBar      = transform.GetComponentInChildren <HealthBar>();
        doAttackHash   = Animator.StringToHash("DoAttack");
        isWalkingHash  = Animator.StringToHash("IsWalking");
        startPosition  = transform.position;
        originalColour = graphicsSpriteRenderer.color;
        academy        = FindObjectOfType <RoguelikeAcademy>();
        if (preassignedTarget != null)
        {
            targetAgent = preassignedTarget;
        }
        else
        {
            hasToSearchForTarget = true;             // targetAgent will be looked for in the Update
        }

        AgentReset();         // will reset some key variables
    }
Exemplo n.º 5
0
 private void Awake()
 {
     rlAgent = GetComponentInParent <RoguelikeAgent>();
 }