From defca775fb42a0ff47beaf7e3b6d8d90124cf59d Mon Sep 17 00:00:00 2001 From: JWS Date: Mon, 31 Jan 2022 20:36:34 -0600 Subject: [PATCH] Levels now work in multiplayer --- Assets/Game1.unity | Bin 27124 -> 28540 bytes Assets/Game2.unity | Bin 17544 -> 19144 bytes Assets/Game3.unity | Bin 17544 -> 19140 bytes Assets/NetworkManagerRocket.cs | 48 +++++++++++++++------- Assets/RockField1.prefab | Bin 8484 -> 8484 bytes Assets/RockField2.prefab | Bin 8484 -> 8484 bytes Assets/RockSphere1.prefab | Bin 19680 -> 19680 bytes Assets/RocketSphere.cs | 40 ++++++++++++------ ProjectSettings/EditorBuildSettings.asset | Bin 4380 -> 4336 bytes ProjectSettings/GraphicsSettings.asset | Bin 5528 -> 5540 bytes ProjectSettings/ProjectSettings.asset | Bin 72980 -> 73072 bytes 11 files changed, 61 insertions(+), 27 deletions(-) diff --git a/Assets/Game1.unity b/Assets/Game1.unity index a1eb8cbcbd35fac9b7897aff0a28f271757eafc5..65ba7c3d6b2ccf6496cdcdc374c69e91a29626e4 100644 GIT binary patch delta 1487 zcma)6ZAep57=CZIx%n;bE3kwnF~aHYR&$pMrl@FXl2IgWx$WMIT6a!#f{7s2pMDq- zC#bNGMG^in(A&>G{1s75`%p@Vp!y+2L4uHyWbc{Ryp8-g@Sby?=REIw&pFTG&c0z5 zJ}@}|{tnJ)i)YI9doFAv1}=wuYn1wiubIrK15XOT+$I1m zP5NxLQqF;(3&+hECWRYBPC}fDVOBT`g7b(q7+-X84-ODRt`J8Z##e=VhFm*hJ;skE zt`9t@pu#i^L&ely93X()@@A^cvBQ)*mJZ-mHdyrbd4O_PGXZYnNHoe9$&klB(~gHH4vqaT9XN37 zNm=I+b9oD18n){KadHysRy#ifHcMEFxxt)e72X}y(3b985?XUzRsi35e38X}QseTN`+0B#dp=U*b6c%h z%WaizJ+}?E4T`Db8x~X74UM$&C80`NH!AifJMVOHp52_A<2aRH%9Q5Cnt#%N+TXTd zFq$Z!|Ee^yl`p~PQOB1i`T}y7x8Uqi0^5ZGVh|{{3v`|0rS%&LJSn)4)r;86`^0k$ XsSWDnKy#E~GRS0$mC=*=mS2AW9`J8R delta 537 zcmX|;O(+Cm9LE1Ii(Ph^vL6l`TPso6#fFkXa#5O%EwZ%owY#QmYB~A7ZBFvKIaoJG z8b`$uMWWaXZ8`YJ!9gOMJUiY@Jw5O9n`fSBn#?_Wzh)BA$Qn`Porr8WC-GhO3x#IO@OnY1!)CKI)7I99?0a z4m$Z|&@TDyUoBVGgTBOL;Gwyq^OS!CQ`*f)SFR>agcx5LGw|8TP2J5?wU&(4X2&b^ zZ!z)qh)2JpMts7Z8`EX_F)ffBb#hfOIr>-2vh=ippG2&B_gL`HsF#^|%}kR{KgYe= i`i#uX_(%U2e^q4urgUph$}HpRq=AQGE@tMdvF~3ZD~wG5 diff --git a/Assets/Game2.unity b/Assets/Game2.unity index ff9dbb0b296c67b92b7e9ced8122a6afe573c7af..17403aa97691bed2a71d67d419d9f8f938b199ce 100644 GIT binary patch delta 1057 zcmeC^WIQpIQGkKL){B9`>jVP>gD8-luu;I?nvs8Ufb|2nrvFRJfWizFYzz!Pm>3w? zf$a1B9u*+50#1Y&3)lHdkXQx}14AK@W&vVWsMrIZ$$mC!jO>$3Z6>PEnfFm=ZET{; zy7OU;=UJ6Ym_fQ20>yrsUlQ5k*YP~`v6;N%N#@P0wv*ZFd4Wb2czL zH{LHXH#097p0^YF)#x8 zXv)Fn!qf|b)%)ZpC+1A{cI2Ea<0!$6WZqY;NF-R~lOm5H>XVR;ftl%iZk7Nx(suH(U6-Y`Iq-$b| z8=LQe)EZFK7bmCYrFy0?0ArrP#M08z$k5Wna5AHrX~iKCgv7~=(zwW R2T}`;MMry`$s3$+001s!>8St! delta 91 zcmX>xm9e9fQGkKL<{JZpO9ul3gD3-ot-wYBduvAC$pO|6C1JY$Yat@Vo&4wh$MJ diff --git a/Assets/Game3.unity b/Assets/Game3.unity index f27cbfac90e432ef2caae4f693d75e784938043c..586bf7cdd6d7fb56ce38dfcac1893124a2a1f0d8 100644 GIT binary patch delta 1256 zcmeC^WIQsJQGkKL){B9`>j(n_gD8-luu)*1?B+STT&$bd$-d*?yv%4N2P6OF0PB!? zFBJoJpehCnCI*HdK+FPUSMttO1&JB3GBA_^X&}W=1r=KXg7%2AB{F2BPzmDgjkIm#APcm<2wGC#9!rs$#Oeljvj_CmAHZArf13au1T+dMAY3dM8ok3ZQ8~PcrBl00|_3m)z<2$+8t&WFhRI)mg}oy~bcDRe>lcTk8huuVSctPT|a=sbP0fvrG2 zD1t$*xuLym9e9fQGkKL<{JZpO9ul3gD3-ot-wZsd9s^#D81v~yiS&jb@MW#l^l$`lLM?n z>MMC?ssdFpSTHd#lmclMAg+RnZ2*ep0QsyyTn!adU}j(d8OsL5iIEcKK#E}nP^=J0 zgY+gr#T0-Xm^wG{1;Jo-KrsQJne0H0J4DQgVF%D86`%kI5PLusK7fjG0>wO`VjMtS z1wcO6 prefab.name == "RockField1")); - RockField2 = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "RockField2")); - NetworkServer.Spawn(RockField1); - NetworkServer.Spawn(RockField2); } public override void OnStartHost() { - RockField1 = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "RockField1")); - RockField2 = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "RockField2")); - NetworkServer.Spawn(RockField1); - NetworkServer.Spawn(RockField2); } public override void OnStopHost() { - // destroy Rockfield - if (RockField1 != null) - NetworkServer.Destroy(RockField1); - if (RockField2 != null) - NetworkServer.Destroy(RockField2); } public static int level = 1; public int lastCount = 0; + static bool preparing = false; + + void SwitchScenes() + { + RocketSphere[] players = FindObjectsOfType(); + + for (int i = 0; i < players.Length; i++) + { + // deactivate all the ships on all clients + players[i].RpcMySetActive(false, Quaternion.identity, true); + + // spawn ships, on all clients + players[i].rpcSpawnShipDelay(); + } + + // switch to the next level + ServerChangeScene("Game" + level); + + preparing = false; + } + void Update() { if (RockSphere.count != lastCount) @@ -51,9 +59,19 @@ void Update() level = 1; } - ServerChangeScene("Game" + level); + preparing = true; + + // stop the music at the end of the level + Camera.main.transform.gameObject.GetComponent().Stop(); + + // wait 10 seconds before switching to the next level + Invoke("SwitchScenes", 10); } } - } + if (Input.GetKeyDown(KeyCode.Escape)) + { + Application.Quit(); + } + } } \ No newline at end of file diff --git a/Assets/RockField1.prefab b/Assets/RockField1.prefab index 3c3d6abfe979ffde6d9c91b7eab0469f07286679..d48bef1ca59f24f8f3fe73c16c0dea46d2039c48 100644 GIT binary patch delta 14 VcmZ4Dw8Uw{1$joU%@^f^838UB1#SQU delta 14 VcmZ4Dw8Uw{1$jn>%@^f^838Ta1!MpK diff --git a/Assets/RockField2.prefab b/Assets/RockField2.prefab index 58258793ce9e97e8dddd5e8057eadb4cdc33aa8d..c2589a0519c8509481db5d571e6cb880f38a0a8e 100644 GIT binary patch delta 14 VcmZ4Dw8Uw{1$joU%@^f^838UB1#SQU delta 14 VcmZ4Dw8Uw{1$jos%@^f^838Tg1!VvL diff --git a/Assets/RockSphere1.prefab b/Assets/RockSphere1.prefab index 705b1a43522ec37d5aa3e3cbf6eeca56c2f19f2b..93e420cc614c3e04e24acac9615a6dccb71aca34 100644 GIT binary patch delta 20 ccmaDblkve!#tjj!j7*aoosBp5xQ4I;09slHt^fc4 delta 18 acmaDblkve!#tjj!lbf7PHut!Oumb>5#Rshb diff --git a/Assets/RocketSphere.cs b/Assets/RocketSphere.cs index 8b4458c..23e7c9d 100644 --- a/Assets/RocketSphere.cs +++ b/Assets/RocketSphere.cs @@ -70,13 +70,21 @@ public override void OnStartServer() RocketSphere[] players = FindObjectsOfType(); - for (int i = 0; i < players.Length; i++) + int count = 0; + for (int i = 1; i < players.Length; i++) { + count++; + if (count > 10) + { + Debug.Log("Give up finding a better color"); + break; // give up + } + // check for difference between player and chosen hue, // difference check must be small enough that we have enough colors for all players. // if max player count is increased from 4, this value should be reassessed // this could be an infinte check otherwise, might want a failsafe escape - if (Mathf.Abs(hue - players[i].hue) < 0.1f) + if ((Mathf.Abs(hue - players[i].hue) < 0.15f) && (players[i] != this)) { // generate a new hue if it is too close to this other players color hue = Random.Range(0.0f, 1.0f); @@ -86,7 +94,7 @@ public override void OnStartServer() } } - // rocket color is now set for this player until it is destroyed + // rocket color is now set for this player until it is destroyed or disconnects RocketColor = Color.HSVToRGB(hue, 1.0f, 1.0f); } @@ -150,7 +158,7 @@ private void OnLevelWasLoaded(int level) Camera.main.GetComponent().player = transform.gameObject.transform.Find("Rocket").gameObject.transform; } - void MySetActive(bool active, Quaternion rotation) + void MySetActive(bool active, Quaternion rotation, bool playhyperspace) { if (active == false) { @@ -178,21 +186,25 @@ void MySetActive(bool active, Quaternion rotation) rocket.SetActive(true); visible = true; - // play the hyperspace sound on enable + } + + if (playhyperspace == true) + { + // play the hyperspace sound hyperspaceSound.Play(); } } [ClientRpc] - void RpcMySetActive(bool active, Quaternion rotation) + public void RpcMySetActive(bool active, Quaternion rotation, bool playhyperspace) { - MySetActive(active, rotation); + MySetActive(active, rotation, playhyperspace); } [Command] - void CmdMySetActive(bool active, Quaternion rotation) + void CmdMySetActive(bool active, Quaternion rotation, bool playhyperspace) { - RpcMySetActive(active, rotation); + RpcMySetActive(active, rotation, playhyperspace); } [Client] @@ -201,14 +213,18 @@ void SpawnShip() if (!isLocalPlayer) return; // re-enable this rocket on all clients through server at the direction the user is looking at the moment - CmdMySetActive(true, Camera.main.transform.rotation); + CmdMySetActive(true, Camera.main.transform.rotation, true); + isSpawning = false; } + bool isSpawning; + [ClientRpc] - void rpcSpawnShipDelay() + public void rpcSpawnShipDelay() { if (!isLocalPlayer) return; + isSpawning = true; Invoke("SpawnShip", 5); } @@ -224,7 +240,7 @@ void OnTriggerEnter(Collider other) NetworkServer.Spawn(explosion); // deactivate the ship on all clients - RpcMySetActive(false, Quaternion.identity); + RpcMySetActive(false, Quaternion.identity, false); // spawn a new ship, do this on the local player client and it will re-enable on all clients rpcSpawnShipDelay(); diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index f6d2acf73dc1ff5c197aa101dfc033b262a5eaaa..aab02118a626c2da4adc36ef11b74da6e3fdac65 100644 GIT binary patch delta 35 rcmbQE^g)q>fq^BFfkEKIMh+borVk98%~;NHGcr$R6=o_tiKnvIcxfuY%MvXy8Y0O2zW5&!@I delta 33 pcmZ3YJwuy=fk8xrfkAY}Mvgbaj1iN+3ZG}>ntW8Gda{pb1OS`p3OxV- diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index e5233de988a3b90cb6bf7465889573d9bbd15534..261231a0514cf9f461227e93c23ff7ff7a58fbfb 100644 GIT binary patch delta 145 zcmbQTi{-;E76ArEmYEEUvIPtb45C2xhDL#{0*o;%76&ANB2d5tq8Bq~vU4vicka$V zF67ZWhZ`)&utX}yor|&DcZci$P2AIey=B_o!otYI#A*W6p}pOapYbu{^ac(_7JgH8 j;d9GR&UOH4bNIY=dLav=MhiwpmhB5U8HrWT3m2iX|awr^o!{KLp<1e8|W X4ivb|xcvwRqXi=)^Y*`-jK#tLPoNQ7