diff --git a/Assets/Prefabs/King/Goo.prefab b/Assets/Prefabs/King/Goo.prefab index 9114a18..a430c00 100644 --- a/Assets/Prefabs/King/Goo.prefab +++ b/Assets/Prefabs/King/Goo.prefab @@ -29,7 +29,7 @@ Transform: m_GameObject: {fileID: 9109488354154531999} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: -29.02, y: 0.165, z: -21.09} - m_LocalScale: {x: 2, y: 1, z: 1} + m_LocalScale: {x: 1.5, y: 1, z: 1.5} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 diff --git a/Assets/Scripts/KingScripts/Goo.cs b/Assets/Scripts/KingScripts/Goo.cs index 62a292e..11666ef 100644 --- a/Assets/Scripts/KingScripts/Goo.cs +++ b/Assets/Scripts/KingScripts/Goo.cs @@ -8,7 +8,7 @@ public class Goo : MonoBehaviour void FixedUpdate() { Lifetime++; - if(Lifetime == 950) { + if(Lifetime == 850) { Destruction(); } } diff --git a/Assets/Scripts/KingScripts/HailArea.cs b/Assets/Scripts/KingScripts/HailArea.cs index f06a4aa..927c776 100644 --- a/Assets/Scripts/KingScripts/HailArea.cs +++ b/Assets/Scripts/KingScripts/HailArea.cs @@ -11,6 +11,8 @@ public class HailArea : MonoBehaviour private float Zmax = -85f; private float Zmin = -115f; + int Lifetime = 0; + public GameObject Hail; int timer = 0; @@ -38,6 +40,11 @@ public class HailArea : MonoBehaviour SpawnHail(diameter, position); } timer++; + + Lifetime++; + if (Lifetime == 3000) { + Destruction(); + } } // Spawns a singular Hail piece @@ -56,4 +63,8 @@ public class HailArea : MonoBehaviour Zmax = TopBound; Zmin = BottomBound; } + + void Destruction() { + Destroy(gameObject); + } } diff --git a/Assets/Scripts/KingScripts/KingMove.cs b/Assets/Scripts/KingScripts/KingMove.cs index 2f05bb1..6dc1f40 100644 --- a/Assets/Scripts/KingScripts/KingMove.cs +++ b/Assets/Scripts/KingScripts/KingMove.cs @@ -46,13 +46,13 @@ public class KingMove : MonoBehaviour else if (transform.position.x < -4500) {//Once they rech a certain point they begin to cirlce around the mountain (radius of 1050, (x+4500)^2+(z-510)^2=620^2) float z = transform.position.z; z -= translation; //Moves the player's X forward slightly - if (z >= -110) { //Stops this from breaking the circle's formula + if (z > -110 && z <= 1130) { //Stops this from breaking the circle's formula float x = -Mathf.Sqrt((620 * 620) - ((z - 510) * (z - 510))) - 4500; //Snaps the player onto a circle that is around the mountain, so the player orbits it smoothly - newPos = new Vector3(x, 620, z); //make a Vector3 out of the new X and Z + newPos = new Vector3(x, 625, z); //make a Vector3 out of the new X and Z transform.position = newPos;//Sets the player's new position on the cirlce transform.LookAt(MountCent);//Rotates the player as they move along the circumfurance } - else if (z > 1130) {//Snaps the player back onto the horizontal track + if (z > 1130) {//Snaps the player back onto the horizontal track transform.position = new Vector3(-4500, 625, 1130); } } diff --git a/Assets/Scripts/KingScripts/KingPlace.cs b/Assets/Scripts/KingScripts/KingPlace.cs index 836e716..49fe594 100644 --- a/Assets/Scripts/KingScripts/KingPlace.cs +++ b/Assets/Scripts/KingScripts/KingPlace.cs @@ -7,25 +7,43 @@ using UnityEngine; public class KingPlace : NetworkBehaviour { + private bool BoxAvaliable = true; + private int BoxCool = 3; + private bool HailAvaliable = true; + private int HailCool = 3; + private bool SlimeAvaliable = true; + private int SlimeCool = 3; + private bool ThundAvaliable = true; + private int ThundCool = 3; + //Is called when the King clicks on the Block button public void OnBlockClicked() { - PlaceObject(0); + if (BoxAvaliable) { + PlaceObject(0); + } } //Is called when the King clicks on the Hail button public void OnHailClicked() { - PlaceObject(1); + if (HailAvaliable) { + PlaceObject(1); + } } //Is called when the King clicks on the Slime button public void OnSlimeClicked() { - PlaceObject(2); + if (SlimeAvaliable) { + PlaceObject(2); + } } public GameObject Thunderstorm; //Is called when the King clicks on the Thunderstorm button public void OnThunderClicked() { - //TODO Spawn thunderstorms on the players + if (ThundAvaliable) { + //TODO thunderstorm + Cooldown(3); + } } @@ -45,6 +63,8 @@ public class KingPlace : NetworkBehaviour private bool SlimePlacing = false; private int BoxSize = 20; + private int Energy = 100; + private GameObject boxPlaced; void Awake() @@ -95,6 +115,7 @@ public class KingPlace : NetworkBehaviour } if (Input.GetMouseButtonUp(0)) {//Reads the player releasing the left mouse button CreateHail(); + Cooldown(1); } } if (SlimePlacing == true) { @@ -102,10 +123,15 @@ public class KingPlace : NetworkBehaviour if (Input.GetMouseButtonUp(0)) {//Reads the player releasing the left mouse button PlaceTemp.GetComponent().GooStart(SlimeDir); SlimePlacing = false; + Cooldown(2); } } } + private void FixedUpdate() { + CooldownTimer(); + } + private GameObject Row; private void FindGridBox() { float i = ((PlaceTemp.transform.position.x) - 101) / -BoxSize; //Finds the Row the cursor is in @@ -126,32 +152,45 @@ public class KingPlace : NetworkBehaviour PlaceTemp.transform.position = spawnLoc; - if (Place == BlockWithoutNetwork) { + if (Place == BlockWithoutNetwork) + { // Have the server spawn the box SpawnBoxServerRPC(spawnLoc); - + // Remove the reference to PlaceTemp Destroy(PlaceTemp); + Cooldown(0); } - } - if (Place == Slime) {//If Object is Hail or Slime set the respective Placing value to true so it can launch into the secondary placing function - SlimePlacing = true; - } - else if (Place == HailSprite) { - Grid.GetComponent().GridSwitch(true); - HailPlacing = true; - HailCorner = Instantiate(Place); + if (Place == Slime) + {//If Object is Hail or Slime set the respective Placing value to true so it can launch into the secondary placing function + SlimePlacing = true; + } + else if (Place == HailSprite) + { + Grid.GetComponent().GridSwitch(true); + HailPlacing = true; + HailCorner = Instantiate(Place); + } } } - private void GridCheck(int Row, int Box, ref bool Placing) {//TODO change to Try Catch + private void GridCheck(int Row, int Box, ref bool Placing) {//Makes it so items can only be placed in valid positions GameObject RowTrue; GameObject BoxTrue; - RowTrue = Grid.transform.Find("Row" + Row).gameObject; - if(RowTrue != null) { - BoxTrue = RowTrue.transform.Find("GridChunk" + Box).gameObject; - if(BoxTrue != null) { + try { + RowTrue = Grid.transform.Find("Row" + Row).gameObject; + } catch { + RowTrue = null; + } + + if (RowTrue != null) { + try { + BoxTrue = RowTrue.transform.Find("GridChunk" + Box).gameObject; + } catch { + BoxTrue = null; + } + if (BoxTrue != null) { Grid.GetComponent().GridSwitch(false); //Switch off the grid Placing = false;//Stop placing } @@ -176,8 +215,96 @@ public class KingPlace : NetworkBehaviour } private int DrawArrow() { - //TODO convert mouse position to arrow direction. then return the int of what direction it is - return 2; + Vector3 MosPos = new Vector3(0, 0, 0); + Ray Ray = KingCam.ScreenPointToRay(Input.mousePosition);//Raycast to find the point where the mouse cursor is + if (Physics.Raycast(Ray, out RaycastHit RayCastHit, float.MaxValue, LayerMask)) { + MosPos = RayCastHit.point; + } + //TODO Draw arrow + if (MosPos.x > PlaceTemp.transform.position.x && MosPos.z < PlaceTemp.transform.position.z) {//Temp function to change Slime's dir //TODO convert mouse position to arrow direction. then return the int of what direction it is + return 0;//Up + } + else if (MosPos.x < PlaceTemp.transform.position.x && MosPos.z < PlaceTemp.transform.position.z) { + return 1;//Right + } + else if (MosPos.x < PlaceTemp.transform.position.x && MosPos.z > PlaceTemp.transform.position.z) { + return 2;//Down + } + else if (MosPos.x > PlaceTemp.transform.position.x && MosPos.z > PlaceTemp.transform.position.z) { + return 3;//Left + } + else { + return 2;//Defaults to down, just in case + } + } + + private void Cooldown(int ID) { + switch (ID) {//Parses in the button clicked into the right object that the King is placing + case 0: + BoxAvaliable = false;//Block Cooldown + break; + case 1: + HailAvaliable = false;//Hail Cooldown + break; + case 2: + SlimeAvaliable = false;//Slime Cooldown + break; + case 3: + ThundAvaliable = false;//Thunderstorm Cooldown + break; + } + } + + private int BSC = 0; + private int HSC = 0; + private int SSC = 0; + private int TSC = 0; + + private void CooldownTimer() {// Function for tracking the individual cooldowns of the items. It's done in a two-teired system to allow the cooldowns to be eaisly converted as seconds + if(BoxAvaliable == false) { + BSC++; + if (BSC == 50) { + BSC = 0; + BoxCool--; + if (BoxCool == 0) { + BoxCool = 3; + BoxAvaliable = true; + } + } + } + if (HailAvaliable == false) { + HSC++; + if (HSC == 50) { + HSC = 0; + HailCool--; + if (HailCool == 0) { + HailCool = 3; + HailAvaliable = true; + } + } + } + if (SlimeAvaliable == false) { + SSC++; + if (SSC == 50) { + SSC = 0; + SlimeCool--; + if (SlimeCool == 0) { + SlimeCool = 3; + SlimeAvaliable = true; + } + } + } + if (ThundAvaliable == false) { + TSC++; + if (TSC == 50) { + TSC = 0; + ThundCool--; + if (ThundCool == 0) { + ThundCool = 3; + ThundAvaliable = true; + } + } + } } [ServerRpc(RequireOwnership = false)] diff --git a/Assets/Scripts/KingScripts/Slime.cs b/Assets/Scripts/KingScripts/Slime.cs index 7fda1fa..39b2f06 100644 --- a/Assets/Scripts/KingScripts/Slime.cs +++ b/Assets/Scripts/KingScripts/Slime.cs @@ -6,8 +6,10 @@ public class Slime : MonoBehaviour { float MoveSpd; int GooTimer = 0; + int Lifetime = 0; bool GooGo = false; - Vector3 offset = new Vector3(0.0f, -0.1f, 0.0f); + Vector3 GooOffset = new Vector3(0.0f, -0.1f, 0.0f); + Vector3 RayOffset = new Vector3(0.0f, -0.5f, 0.0f); Vector3 MoveDir = new Vector3(0, 0, 1); RaycastHit hit; public GameObject Goo; @@ -26,16 +28,22 @@ public class Slime : MonoBehaviour //create goo underneath them slime if (GooTimer == 6) { GameObject GooTrail = null; - GooTrail = Instantiate(Goo, transform.position - offset, transform.rotation); + GooTrail = Instantiate(Goo, transform.position - GooOffset, transform.rotation); GooTrail.transform.parent = Folder.transform; GooTimer = 0; } //attempt to move forward(Raycast infront for objects, and also raycast down, to make sure there's still ground underneath it) - if (Physics.Raycast(transform.position, transform.TransformDirection(MoveDir), out hit, 1.5f, LayerMask) || Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out hit, 50f, LayerMask)) {//turns it around when it hits something or is going to go over a pit//TODO hit more than terrain + if (Physics.Raycast(transform.position, transform.TransformDirection(MoveDir), out hit, 2f, LayerMask) || Physics.Raycast(transform.position + RayOffset, transform.TransformDirection(Vector3.down), out hit, 50f, LayerMask)) {//turns it around when it hits something or is going to go over a pit//TODO hit more than terrain MoveDir = -MoveDir; } transform.Translate(MoveSpd*MoveDir);//moving forward GooTimer++; + + Lifetime++; + if (Lifetime == 3000) + { + Destruction(); + } } } @@ -67,4 +75,8 @@ public class Slime : MonoBehaviour } } + void Destruction() + { + Destroy(gameObject); + } }