//Resets some variables and statuses the a certain player is made a CPU void resetControlsCPU() { if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.Joy1) { m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned; l.is_joy1_taken = false; } else if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.Joy2) { m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned; l.is_joy2_taken = false; } else if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.ArrowKeys) { m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned; l.is_arrowKeys_taken = false; } else if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.WSDA) { m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned; l.is_wsda_taken = false; } Control_Type.text = "Not Assigned"; carImage.sprite = default_Empty; playerCoin.transform.position = m.playerPosition; if (Car1.ThisCarSelected == true && CoinController.CoinID == Car1.ID) { Car1.CheckPlayerActivation(); } else if (Car2.ThisCarSelected == true && CoinController.CoinID == Car2.ID) { Car2.CheckPlayerActivation(); } else if (Car3.ThisCarSelected == true && CoinController.CoinID == Car3.ID) { Car3.CheckPlayerActivation(); } else if (Car4.ThisCarSelected == true && CoinController.CoinID == Car4.ID) { Car4.CheckPlayerActivation(); } CPU_Controls = 0; m.Hand.SetAsLastSibling(); CoinController.is_car_selected = false; if (m.playerID == 1) { buttonController.SetOverlay(false); controlController.SetOverlay(false); } }
//This funciton is called when the activation button on the panel is pressed (changes the player status to active, non active or cpu) public void PanelManager() { if (m.playerID != 1) //Player 1 will have a slightly different behaviour { if (!CoinController.is_grabbed) { //A new player can be activated only if it's the one right next to the highest currently activated player. e.g. if only player 1 is active you can activate player 2 but not player 3 if (l.num_players == m.playerID || l.num_players == m.playerID - 1) { switch_case++; switch (switch_case) { case 1: //Makes it an active player if (l.num_players == m.playerID - 1 && !m.is_this_active) { Token.sprite = Player_Token; HandObject.SetActive(true); playerCoin.SetActive(true); cpuText.text = ""; t.text = nameplayer; Hand.sprite = hand_closed; m.Hand.SetAsLastSibling(); if (m.playerID == 1) { m.GetComponent <Collider2D>().enabled = false; } if (l.num_players < m.playerID) { l.num_players++; } if (m.playerID == 1) { l.is_p1_active = true; } else if (m.playerID == 2) { l.is_p2_active = true; } else if (m.playerID == 3) { l.is_p3_active = true; } else if (m.playerID == 4) { l.is_p4_active = true; } m.is_this_active = true; CPU_Controls = 1; is_CPU = false; carImage.sprite = default_Empty; } break; case 2: //Makes it a CPU if (l.num_players == m.playerID - 1 && !m.is_this_active) { playerCoin.SetActive(true); m.is_this_active = true; l.num_players++; if (m.playerID == 1) { l.is_p1_active = true; } else if (m.playerID == 2) { l.is_p2_active = true; } else if (m.playerID == 3) { l.is_p3_active = true; } else if (m.playerID == 4) { l.is_p4_active = true; } } if (m.is_this_active) { cpuText.text = ""; t.text = "CPU"; is_CPU = true; CPU_Controls = 2; carImage.sprite = default_Empty; Controls = 4; HandObject.SetActive(false); Token.sprite = CPU_Token; l.num_CPU_Players++; resetControlsCPU(); ControlManager(); } break; default: //Deactivates it and resets all its variables if (l.num_players == m.playerID && m.is_this_active) { print("deleting player"); playerCoin.SetActive(false); if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.Joy1) { m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned; l.is_joy1_taken = false; } else if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.Joy2) { m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned; l.is_joy2_taken = false; } else if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.ArrowKeys) { m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned; l.is_arrowKeys_taken = false; } else if (m.ThisPlayerControl == MoveSelector.ControlTypesHere.WSDA) { m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned; l.is_wsda_taken = false; } if (m.playerID == 1) { l.is_p1_active = false; } else if (m.playerID == 2) { l.is_p2_active = false; } else if (m.playerID == 3) { l.is_p3_active = false; } else if (m.playerID == 4) { l.is_p4_active = false; } l.num_players--; l.num_CPU_Players--; m.is_this_active = false; is_CPU = false; CoinController.is_car_selected = false; } switch_case = 0; playerCoin.transform.position = m.playerPosition; carImage.sprite = default_notActive; if (Car1.ThisCarSelected == true && CoinController.CoinID == Car1.ID) { Car1.CheckPlayerActivation(); } else if (Car2.ThisCarSelected == true && CoinController.CoinID == Car2.ID) { Car2.CheckPlayerActivation(); } else if (Car3.ThisCarSelected == true && CoinController.CoinID == Car3.ID) { Car3.CheckPlayerActivation(); } else if (Car4.ThisCarSelected == true && CoinController.CoinID == Car4.ID) { Car4.CheckPlayerActivation(); } CPU_Controls = 0; t.text = "N/A"; cpuText.text = ""; if (m.playerID == 1) { buttonController.SetOverlay(false); controlController.SetOverlay(false); } Controls = 4; ControlManager(); break; } } //If this is a middle player (e.g. player 2 when 3 players are active) only switches between CPU and active status. Player cannot be disabled else if (m.is_this_active) { CPU_Controls++; switch (CPU_Controls) { case 1: is_CPU = false; resetControlsCPU(); Controls = 4; ControlManager(); Hand.sprite = hand_closed; cpuText.text = ""; t.text = nameplayer; switch_case = 1; Token.sprite = Player_Token; HandObject.SetActive(true); CPU_Controls = 1; l.num_CPU_Players--; break; case 2: cpuText.text = ""; t.text = "CPU"; is_CPU = true; CPU_Controls = 0; switch_case = 2; resetControlsCPU(); Controls = 4; ControlManager(); l.num_CPU_Players++; HandObject.SetActive(false); Token.sprite = CPU_Token; m.ThisPlayerControl = MoveSelector.ControlTypesHere.NotAssigned; break; default: switch_case = 0; CPU_Controls = 0; Controls = 4; is_CPU = false; break; } } } } //Player 1 can also not be deactivated as it controls other players' statuses and activation else { CPU_Controls++; switch (CPU_Controls) { case 1: cpuText.text = ""; t.text = nameplayer; is_CPU = false; switch_case = 1; Token.sprite = Player_Token; break; case 2: cpuText.text = ""; t.text = "CPU"; is_CPU = true; CPU_Controls = 0; Token.sprite = CPU_Token; switch_case = 2; break; default: switch_case = 0; CPU_Controls = 0; is_CPU = false; break; } } }