// 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); } } }
// 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)); }
// 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; } }