Exemplo n.º 1
0
    void Awake()
    {
        // Gets the length for the first clock period
        NewPeriod();

        // We need all traffic lights with the same period!
        if (fitnessBasedPeriod < 0.01f)
        {
            fitnessBasedPeriod = (Random.value * 6f) + 35f;
            Debug.Log("Period: " + fitnessBasedPeriod);
        }

        // Gets a reference to the actual lights!
        redLight    = transform.FindChild("LightRed").gameObject;
        orangeLight = transform.FindChild("LightOrange").gameObject;
        greenLight  = transform.FindChild("LightGreen").gameObject;

        // Starts the traffic light to either orange or green
        float myRandom = Random.value;

        if (myRandom < 0.5f)
        {
            currentLight = lightState.Orange;
            // For fitness-based evolution
            period = fitnessBasedPeriod * 0.5f;
        }
        else
        {
            currentLight = lightState.Green;
            // For fitness-based evolution
            period = fitnessBasedPeriod;
        }

        LigthChange();
    }
    // Use this for initialization
    void Start()
    {
        state = lightState.off;

        sprRenderer    = GetComponent <SpriteRenderer>();
        parentAnimator = transform.parent.gameObject.GetComponent <Animator>();

        GM = GameObject.FindGameObjectWithTag("GameManager").GetComponent <gameManager>();
    }
Exemplo n.º 3
0
    public void RunQ8() //交通信号灯
    {
        switch (currentStatelight)
        {
        case lightState.lightState_red:
        {
            currentTime += Time.deltaTime;
            if (currentTime > 5.0f)
            {
                currentStatelight       = lightState.lightState_yellow;
                lightImage_red.color    = Color.grey;
                lightImage_yellow.color = Color.yellow;
                currentTime             = 0.0f;
                Debug.Log("red to yellow");
            }
        }
        break;

        case lightState.lightState_yellow:
        {
            currentTime += Time.deltaTime;
            if (currentTime > 2.0f)
            {
                currentStatelight       = lightState.lightState_green;
                lightImage_yellow.color = Color.grey;
                lightImage_green.color  = Color.green;
                Debug.Log("yellow to green");
                currentTime = 0.0f;
            }
        }
        break;

        case lightState.lightState_green:
        {
            currentTime += Time.deltaTime;
            if (currentTime > 10.0f)
            {
                currentStatelight      = lightState.lightState_red;
                lightImage_green.color = Color.grey;
                lightImage_red.color   = Color.red;
                Debug.Log("green to red");
                currentTime = 0.0f;
            }
        }
        break;
        }
    }
Exemplo n.º 4
0
    void OnGUI()
    {
        uint buttonWidth  = 80;
        uint buttonHeight = 30;
        uint spacing      = 20;
        Rect ButtonRect   = new Rect(Screen.width - buttonWidth - spacing, Screen.height - buttonHeight - spacing, buttonWidth, buttonHeight);

        if (GUI.Button(ButtonRect, "Light:" + state.ToString()))
        {
            state = ~state;
        }
        if (state == lightState.Man)
        {
            Rect ExplRect = new Rect(Screen.width - buttonWidth - spacing + 7, Screen.height - buttonHeight - 13 - buttonHeight, buttonWidth, buttonHeight);
            GUI.Label(ExplRect, "Use Q & E");
        }
        else
        {
        }
    }
Exemplo n.º 5
0
    private void handleOther()
    {
        if (Input.GetKeyDown(lightOn))
        {
            //  for the new raycast lights

            MeshRenderer MR;
            MR = GetComponentInChildren <MeshRenderer>();



            if (lState == lightState.lit)
            {
                MR.enabled = false;
                lState     = lightState.dark;
            }
            else
            {
                MR.enabled = true;
                lState     = lightState.lit;
            }
        }

        if (Input.GetKey(dig) == true && aState == actionState.idle && lState == lightState.lit)
        {
            aState  = actionState.digging;
            PassDig = true;
            StartCoroutine(CheckCompletedDig(rb.position));
        }


        if (Input.GetKeyDown(attackKey))
        {
            aState = actionState.attacking;
            animator.SetInteger("aState", (int)aState);
            Debug.Log("ATTACK PRESSED");
            Attack();
        }
    }
    //Switch state of light
    public void switchLight()
    {
        //Cycle through states using int values of lightState enum, much more compact than having to deal with switch or if statements
        state = (lightState)(((int)state + 1) % 3);


        //Change sprite based on current state
        switch (state)
        {
        case lightState.half:
            sprRenderer.sprite = halfSprite;
            break;

        case lightState.on:
            sprRenderer.sprite = onSprite;
            break;

        default:
            sprRenderer.sprite = offSprite;
            break;
        }
    }
Exemplo n.º 7
0
    /// <summary>
    /// Fixed period values used only for fitness-based evolution.
    /// </summary>
    private void NextLight()
    {
        switch (currentLight)
        {
        case lightState.Red:
            currentLight = lightState.Green;

            // For fitness-based evolution
            period = fitnessBasedPeriod;

            break;

        case lightState.Orange:
            currentLight = lightState.Red;

            // For fitness-based evolution
            period = fitnessBasedPeriod * 0.5f;

            break;

        case lightState.Green:
            currentLight = lightState.Orange;
            // Orange always has a fixed short period:
            period = minPeriod;

            // For fitness-based evolution
            period = fitnessBasedPeriod * 0.5f;

            break;

        default:
            break;
        }

        LigthChange();
    }