Esempio n. 1
0
    private void ProcessHit(damageenemyLaser damageDealer)
    {
        float aDamage;

        AudioSource.PlayClipAtPoint(bClip, Camera.main.transform.position, aVolume);
        aDamage = damageDealer.GetDamage();
        health -= aDamage;

        damageDealer.Hit();
        if (health <= 00)
        {
            Debug.Log(1.0f / Time.deltaTime);
            // Destroy(gameObject);
            // Debug.Log("destroy player!");

            //GameObject.Find("gameScore").GetComponent<keepScor>().ResetGame();
            //FindObjectOfType<gameManage>().playerShot();
            health = StartHealth;
            aKeepScore.Resetcore();
            /* this will reset score and cause us to wait a couple seconds*/
            if (agent != null)
            {
                agent.IncrementReward(-0.2f);
            }
        }
        else
        {
            if (agent != null)
            {
                // agent.IncrementReward(-aDamage / StartHealth);
                agent.IncrementReward(-0.2f);
            }
        }
    }
    public override void AgentAction(float[] vectorAction, string textAction)
    {
        movement = Mathf.FloorToInt(vectorAction[0]);
        mFire    = Mathf.FloorToInt(vectorAction[1]);
        int aFire     = 0;
        int direction = 0;

        if (movement == 1)
        {
            direction = -1;
        }
        else if (movement == 2)
        {
            direction = 1;
        }
        if (mFire == 1)
        {
            aFire = 1;
        }

        PlayerRoutine.Move(direction, 0);
        // only start firing if LaserDelay is false.
        if (aFire == 1 & !HasFired & LaserDelay == false)
        {
            StartCoroutine("sqPrint");
            // Debug.Log("Starting Firing");
            HasFired   = true;
            LaserDelay = true;
        }
        else if (aFire == 0 & HasFired & LaserDelay == false)
        {
            //Debug.Log("ending firing");
            // only end firing if LaserDelay is false.

            StopCoroutine("sqPrint");
            HasFired = false;
        }


        // Debug.Log("reward:" + GetCumulativeReward());
        FrameRate = (1.0f / Time.deltaTime);
        AddReward(xReward);

        if (Mathf.Abs(xReward) > 0.01)
        {
            LastReward = xReward;
            LaserDelay = false;
        }
        if (xReward < -0.01) /*died*/
        {
            xReward = 0f;

            endGameText      = GameObject.Find("endGameText").GetComponent <Text>();
            endGameText.text = "GAME OVER...RESTARTING..." + (1.0f / Time.deltaTime);;
            //player.SetActive(false);
            Invoke("youDead", 0.5f);
            aKeepScore.Resetcore();
            Debug.Log("reward:" + GetCumulativeReward());
            xInitializeArrays();
            Done();
        }


        xReward  = 0f; //reset reward every cycle.
        NumStep += 1;
        if (NumStep > MaxNumSteps)
        {
            NumStep = 0;
            Debug.Log("reward:" + GetCumulativeReward());
            xInitializeArrays();
            Done();
        }
    }