Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (PlayerManager.Gamestate == gamestate.sea_levels_rose)
        {
            return;
        }

        if (humans)
        {
            bool p1Back = RCI.GetButton(XboxCtrlrInput.XboxButton.Back, player_data.controllers[(int)player.A]);
            bool p2Back = RCI.GetButton(XboxCtrlrInput.XboxButton.Back, player_data.controllers[(int)player.B]);
            controls_display.SetActive(p1Back || p2Back);
        }
        else
        {
            if (MultiDisplayScript.singleDisplay)
            {
                bool p1Back = RCI.GetButton(XboxCtrlrInput.XboxButton.Back, player_data.controllers[(int)player.A]);
                bool p2Back = RCI.GetButton(XboxCtrlrInput.XboxButton.Back, player_data.controllers[(int)player.B]);
                if (!(p1Back || p2Back))
                {
                    controls_display.SetActive(RCI.GetButton(XboxCtrlrInput.XboxButton.Back, player_data.controllers[(int)player.Earth]));
                }
            }
            else
            {
                controls_display.SetActive(RCI.GetButton(XboxCtrlrInput.XboxButton.Back, player_data.controllers[(int)player.Earth]));
            }
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (PlayerManager.Gamestate == gamestate.sea_levels_rose)
        {
            return;
        }

        // Take in player input for switching policies
        for (int i = 0; i < 2; i++)
        {
            int    Player        = (i == 0) ? (int)player.A : (int)player.B;
            int    currentPolicy = (int)policies[Player];
            policy newPolicy     = (policy)currentPolicy;

            XboxController controller = player_data.controllers[Player];
            if (RCI.GetButtonDown(XboxButton.DPadDown, controller))
            {
                newPolicy = (policy)Mathf.Clamp(currentPolicy - 1, 1, policiesCount - 1);
            }
            else if (RCI.GetButtonDown(XboxButton.DPadUp, controller))
            {
                newPolicy = (policy)Mathf.Clamp(currentPolicy + 1, 1, policiesCount - 1);
            }

            ChangePolicyBonusDisplay(i, currentPolicy, newPolicy);

            if (newPolicy != policies[Player])
            {
                policies[Player] = newPolicy;
                //city.updatePoliciesAll(Player, (policy)newPolicy);
                // Play corresponding sound effect
                if (newPolicy == policy.industry)
                {
                    mixer.playSFX("ind policy");
                }
                else if (newPolicy == policy.neutral)
                {
                    mixer.playSFX("population growth");
                }
                else if (newPolicy == policy.eco)
                {
                    mixer.playSFX("eco policy");
                }
            }
        }

        // Update policy displays
        for (int pol = 0; pol < policiesCount; pol++)
        {
            if (p1PolicyDisplays[pol] != null)
            {
                setPolicySR(p1PolicyDisplays[pol], policies[1] == (policy)pol);
            }
            if (p2PolicyDisplays[pol] != null)
            {
                setPolicySR(p2PolicyDisplays[pol], policies[2] == (policy)pol);
            }
        }
    }
Exemple #3
0
    // Called every frame
    private void Update()
    {
        dummy_earthquake.gameObject.SetActive(disaster.isDisasterQueued());
        if (disaster.isDisasterQueued())
        {
            // Earthquake logic
            angular_velo = 0;
            if (RCI.GetButtonDown(XboxButton.X, Reticle.controller))
            {
                disaster.causeDisaster(transform.position, disaster.earthquake_radius);
                disaster.setDisaster(false);
                dummy_earthquake.gameObject.SetActive(false);
                angular_velo = base_angular_velo;
            }
        }
        else if (!(PlayerManager.Gamestate == gamestate.sea_levels_rose))
        {
            // Rainstorm logic
            if (RCI.GetButtonDown(XboxButton.X, Reticle.controller) && Time.time > next_rainstorm)
            {
                if (Physics2D.RaycastAll(transform.position, Vector2.zero).Length >= 2)
                {
                    next_rainstorm = Time.time + rainstorm.rainstorm_time - 0.5f;
                    Instantiate(rainstorm, transform.position, Quaternion.identity);
                }
            }

            // Tree-growing logic
            if (RCI.GetButton(XboxButton.A, Reticle.controller) || Input.GetKey(KeyCode.T))
            {
                cell_controller.instance.growTrees(transform.position, tree_growth_radius, Time.deltaTime * tree_growth_rate);
                last_tree_time = Time.time;
                angular_velo  += angular_accel * Time.deltaTime;
            }
            else
            {
                angular_velo -= angular_accel * Time.deltaTime * 1.5f;
            }
            angular_velo = Mathf.Clamp(angular_velo, base_angular_velo, max_angular_velo);

            // Animal-placing (deer) logic:
            if (RCI.GetButtonDown(XboxButton.Y, Reticle.controller) && Time.time > next_deer)
            {
                if (Physics2D.RaycastAll(transform.position, Vector2.zero).Length >= 2)
                {
                    next_deer = Time.time + deer_cooldown;
                    Instantiate(Deer, transform.position, Quaternion.identity);
                    //int deer_total = FindObjectsOfType<deer>().Length;
                    //if (deer_total < 3) {
                    //}
                    last_deer_time = Time.time;
                }
            }

            if (RCI.GetButtonDown(XboxButton.B, Reticle.controller))
            {
                if (Physics2D.RaycastAll(transform.position, Vector2.zero).Length >= 2 && Time.time > next_wolf)
                {
                    next_wolf = Time.time + wolf_cooldown;
                    Instantiate(Wolf, transform.position, Quaternion.identity);
                    //int wolf_total = FindObjectsOfType<wolf>().Length;
                    //if (wolf_total < 3) {
                    //}
                }
            }
        }

        // Rotate according to angular velocity
        angular_velo = Mathf.Clamp(angular_velo, 0, max_angular_velo);
        transform.Rotate(new Vector3(0, 0, angular_velo));
    }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        // START_TO_JOIN
        if (Gamestate == gamestate.start_to_join)
        {
            // Check for players hitting start to join
            if (RCI.GetButton(XboxButton.Start, XboxController.First))
            {
                p1Reticle.SetActive(true);
                p1JoinText.SetActive(false);
            }

            if (RCI.GetButton(XboxButton.Start, XboxController.Second))
            {
                p2Reticle.SetActive(true);
                p2JoinText.SetActive(false);
            }

            // Check if for state change
            if (p1Reticle.activeSelf && p2Reticle.activeSelf)
            {
                Gamestate = gamestate.playing;
                timer_TMP.gameObject.SetActive(true);
                p1StartArea.Owner = player.A;
                p2StartArea.Owner = player.B;
                update_timer_text();
            }
            return;
        }

        // PLAYING
        if (Gamestate == gamestate.playing)
        {
            // Check for one player eliminated
            bool pA_elim = true;
            bool pB_elim = true;
            foreach (region Region in region.allRegions)
            {
                pA_elim = (pA_elim && Region.Owner != player.A);
                pB_elim = (pB_elim && Region.Owner != player.B);
                if (!pA_elim && !pB_elim)
                {
                    break;
                }
            }

            pA_elim = pA_elim && !moving_units.pA_has_units;
            pB_elim = pB_elim && !moving_units.pB_has_units;
            if (pA_elim || pB_elim)
            {
                // Pull up win-screen
                Gamestate = gamestate.winscreen;
                timer_TMP.gameObject.SetActive(false);
                winner_TMP.gameObject.SetActive(true);

                if (pA_elim ? (policy_manager.policies[(int)player.B] == policy.industry)
              : (policy_manager.policies[(int)player.A] == policy.industry))
                {
                    Winstate = winstate.ind;
                }
                else
                {
                    Winstate = winstate.eco;
                }

                string empire_won = pA_elim ? "Blue" : "Red";
                winner_TMP.text = "The " + empire_won + "  Empire  is  victorious";
                timer           = winscreen_time;
                return;
            }

            moving_units.pA_has_units = false;
            moving_units.pB_has_units = false;

            // Otherwise, iterate the timer
            timer -= Time.deltaTime;
            if (timer > 0)
            {
                update_timer_text();
            }
            else
            {
                // Pull up tie screen
                Gamestate = gamestate.winscreen;
                Winstate  = winstate.tie;
                timer_TMP.gameObject.SetActive(false);
                winner_TMP.gameObject.SetActive(true);
                winner_TMP.text = "Both empires lived on...";
                timer           = winscreen_time;
            }
            return;
        }

        // WINSCREEN
        if (Gamestate == gamestate.winscreen)
        {
            timer -= Time.deltaTime;
            if (timer > 0)
            {
                // This is fine. Waiting for delay to end
            }
            else if (status_controller.instance.airLevel < 0.1 || status_controller.instance.temperatureLevel < 0.1)
            {
                // Sea levels rose
                Gamestate = gamestate.sea_levels_rose;
                winner_TMP.gameObject.SetActive(false);
                sea_levels_rose_TMP.gameObject.SetActive(true);
                sea_level_timer = human_playtime;
                // Set TMP text based on if it's a tie, or one empire
                if (Winstate == winstate.tie)
                {
                    sea_levels_rose_TMP.text = "But as sea levels rose, so each empire fell...";
                }
                else
                {
                    sea_levels_rose_TMP.text = "But as sea levels rose, so the empire fell...";
                }
            }
            else
            {
                // Empires fall
                Gamestate = gamestate.empires_falling;
                winner_TMP.gameObject.SetActive(false);
                empires_fall_TMP.gameObject.SetActive(true);
            }
            return;
        }

        // EMPIRES FALLING
        if (Gamestate == gamestate.empires_falling)
        {
            // Wait for all regions to be neutral.
            foreach (region Region in region.allRegions)
            {
                if (Region.Owner != player.none)
                {
                    return;
                }
            }

            // Once it's over:
            init();
            return;
        }

        // SEA LEVELS ROSE
        if (Gamestate == gamestate.sea_levels_rose)
        {
            sea_level_timer -= Time.deltaTime;
            if (sea_level_timer > 0)
            {
                // This is fine
                if (sea_level_controller.idle)
                {
                    sea_levels_rose_TMP.text = "...and there was no land left to fight for";
                }
            }
            else if (Random.Range(0, 2) == 0)
            {
                // Some chance for the sea levels to stay
                sea_level_timer = 30;
            }
            else
            {
                // When this state ends
                init();
                return;
            }
        }
    }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        // Update position based on controller input
        Vector2 velo = new Vector2(RCI.GetAxis(XboxAxis.LeftStickX, controller), RCI.GetAxis(XboxAxis.LeftStickY, controller));

        velo *= speed_mult * speed_adj;
        if (velo.sqrMagnitude > speed_cap * speed_adj)
        {
            velo.Normalize();
            velo *= speed_cap * speed_adj;
        }
        if (active_region == null)
        {
            rb.position += velo * Time.deltaTime;
        }

        // Clamp the reticle within the camera bounds
        Vector2 cam_min = Camera.main.ViewportToWorldPoint(new Vector3(0, 0));
        Vector2 cam_max = Camera.main.ViewportToWorldPoint(new Vector3(1f, 1f));
        float   new_x   = Mathf.Clamp(rb.position.x, cam_min.x, cam_max.x);
        float   new_y   = Mathf.Clamp(rb.position.y, cam_min.y, cam_max.y);

        rb.position = new Vector2(new_x, new_y);

        // The following is for human-player control, and does not apply to the Earth player
        if (Owner == player.Earth)
        {
            return;
        }

        Vector2 rightStickAim = new Vector2(RCI.GetAxis(XboxAxis.RightStickX, controller), RCI.GetAxis(XboxAxis.RightStickY, controller));

        // Update over_region using raycast, rather than trigger enter/exit
        update_over_region();
        sr.sprite = (over_region != null && over_region.Owner == Owner) ? open_cursor : closed_cursor;

        // Update active_region
        if (rightStickAim.magnitude != 0 && over_region != null && over_region.Owner == Owner)
        {
            active_region = over_region;
        }
        else if (active_region != null && active_region.Owner != Owner)
        {
            active_region = null;
        }
        else if (rightStickAim.magnitude == 0)
        {
            active_region = null;
        }

        // Update aimed_at region
        sr.enabled = (active_region == null);
        if (active_region != null)
        {
            // TODO - Highlight active region here
            //transform.position = active_region.centerpoint;
            if (rightStickAim.magnitude != 0)
            {
                aimed_at_region = raycast_to_region(active_region.raycast_centerpoint, rightStickAim, active_region.gameObject);
            }
            else
            {
                aimed_at_region = null;
            }
        }
        else
        {
            aimed_at_region = null;
        }

        // Send units
        bool sendButtonHeld = RCI.GetAxis(XboxAxis.RightTrigger, controller) >= rTrigger_thresh;
        bool sendButtonDown = sendButtonHeld && !rTrigger_down_prev;

        rTrigger_down_prev = sendButtonHeld;

        if (sendButtonDown && active_region != null && aimed_at_region != null)
        {
            if (active_region != aimed_at_region)
            {
                active_region.send_units(aimed_at_region);
            }
        }

        // Build a road
        bool buildRoadButtonDown = RCI.GetButtonDown(XboxButton.RightBumper, controller);

        if (buildRoadButtonDown && active_region != null && aimed_at_region != null)
        {
            if (active_region != aimed_at_region && aimed_at_region.Owner == Owner)
            {
                active_region.build_road(aimed_at_region);
            }
        }

        // Clear this road
        bool clearRoadButtonDown = RCI.GetButtonDown(XboxButton.LeftBumper, controller);

        if (clearRoadButtonDown && over_region != null)
        {
            if (over_region.Owner == Owner)
            {
                over_region.road_Hub.destroy_road();
            }
        }

        // Update the visual line to active region
        bool show_line = (active_region != null && aimed_at_region != null);

        line_to_active_region.enabled = show_line;
        arrow_cap.enabled             = show_line;
        if (show_line)
        {
            Vector2 line_start_pos = active_region.centerpoint;
            Vector2 line_end_pos   = aimed_at_region.centerpoint;
            Vector2 main_dir       = line_end_pos - line_start_pos;
            Vector2 perp_dir       = new Vector2(-main_dir.y, main_dir.x).normalized;
            Vector2 line_mid_pos   = (line_end_pos - line_start_pos) / 2f + line_start_pos + perp_dir * 0.05f * main_dir.magnitude;
            line_to_active_region.SetPositions(new Vector3[] { line_start_pos, line_mid_pos, line_end_pos });
            arrow_cap.transform.position = line_end_pos;
            arrow_cap.transform.right    = (Vector2)arrow_cap.transform.position - line_mid_pos;
        }
    }