diff --git a/Assets/Game2.unity b/Assets/Game2.unity index 377f88d..24bdcc2 100644 Binary files a/Assets/Game2.unity and b/Assets/Game2.unity differ diff --git a/Assets/Game3.unity b/Assets/Game3.unity index 96421d4..794f4a9 100644 Binary files a/Assets/Game3.unity and b/Assets/Game3.unity differ diff --git a/Assets/Game4.unity b/Assets/Game4.unity index fee0e1a..bff007b 100644 Binary files a/Assets/Game4.unity and b/Assets/Game4.unity differ diff --git a/Assets/Game5.unity b/Assets/Game5.unity index 1b833d6..eae35ad 100644 Binary files a/Assets/Game5.unity and b/Assets/Game5.unity differ diff --git a/Assets/Game6.unity b/Assets/Game6.unity index ddf84ec..20a7751 100644 Binary files a/Assets/Game6.unity and b/Assets/Game6.unity differ diff --git a/Assets/MusicHandler.cs b/Assets/MusicHandler.cs index 2f6b57b..6862d91 100644 --- a/Assets/MusicHandler.cs +++ b/Assets/MusicHandler.cs @@ -32,17 +32,21 @@ public override void OnStartClient() musicLoops[i] = gameObject.AddComponent(); //Assign the corresponding audio clip to its audio source musicLoops[i].clip = musicClipLoops[i]; + musicLoops[i].loop = false; + musicLoops[i].volume = 0.5f; } // get the outro music outroMusic = gameObject.AddComponent(); outroMusic.clip = outroMusicClip; outroMusic.loop = false; + outroMusic.volume = 0.5f; // start the intro music introMusic = gameObject.AddComponent(); introMusic.clip = introMusicClip; introMusic.loop = false; + introMusic.volume = 0.5f; introMusic.Play(); // queue the first loop playing and looping after the intro @@ -55,6 +59,7 @@ public override void OnStartClient() // Update is called once per frame void Update() { + // wait until we initialized, client start might be delayed if (!initialized) return; @@ -65,6 +70,7 @@ void Update() { Debug.Log("done destroying rocks"); + // check if we already have the outro music queue or we are still playing the intro if (!outroQueued) { Debug.Log("outro is not playing or queued"); @@ -119,7 +125,7 @@ void Update() } } // is there a progression playing and nothing queued - else if (musicLoops[musicProgression].isPlaying && !musicLoops[lastMusicProgression].isPlaying) + else if (musicLoops[musicProgression].isPlaying && !musicLoops[lastMusicProgression].isPlaying && !introMusic.isPlaying) { //Debug.Log("No music queued"); diff --git a/Assets/NetworkManagerRocket.cs b/Assets/NetworkManagerRocket.cs index 5042e72..1f95c5b 100644 --- a/Assets/NetworkManagerRocket.cs +++ b/Assets/NetworkManagerRocket.cs @@ -55,6 +55,7 @@ void NextLevel() level = 1; } + // get a hold of the music handler MusicHandler mh = FindObjectOfType(); // wait for outro music + last music loop + 5 seconds before switching to the next level diff --git a/Assets/RockField.cs b/Assets/RockField.cs index ab8570b..4e3b6a7 100644 --- a/Assets/RockField.cs +++ b/Assets/RockField.cs @@ -15,6 +15,7 @@ public override void OnStartServer() { base.OnStartServer(); + // create a bunch of rocks for (int i = 0; i < numberOfRocks; i++) { //calculate random position and rotate so it faces the center @@ -24,7 +25,6 @@ public override void OnStartServer() GameObject rock = Instantiate(RockSpherePrefab, pos, rot) as GameObject; NetworkServer.Spawn(rock); - //rock.transform.SetParent(transform); } } @@ -33,8 +33,9 @@ public override void OnStartClient() base.OnStartClient(); } - // Update is called once per frame - void Update () + // Update is called once per frame + void Update () { + } } diff --git a/Assets/RockSphere.cs b/Assets/RockSphere.cs index 4420a7b..f0fb9c8 100644 --- a/Assets/RockSphere.cs +++ b/Assets/RockSphere.cs @@ -28,7 +28,7 @@ void rpcSetRockStats(int current, int total, int destroyed) totalRocks = total; destroyedRocks = destroyed; - Debug.Log("client RPC Rocks " + current + " total " + total + " destoyed " + destroyed); +// Debug.Log("client RPC Rocks " + current + " total " + total + " destoyed " + destroyed); } [Server] @@ -72,7 +72,7 @@ public override void OnStartServer() totalRocks++; currentRocks++; - Debug.Log("OnStartServer current rocks " + currentRocks + " Rocks " + currentRocks + " total " + totalRocks + " destoyed " + destroyedRocks); + // Debug.Log("OnStartServer current rocks " + currentRocks + " Rocks " + currentRocks + " total " + totalRocks + " destoyed " + destroyedRocks); rpcSetRockStats(currentRocks, totalRocks, destroyedRocks); } @@ -100,7 +100,7 @@ void OnTriggerEnter(Collider other) destroyedRocks++; currentRocks--; - Debug.Log("OntriggerEnter Rocks " + currentRocks + " total " + totalRocks + " destoyed " + destroyedRocks); +// Debug.Log("OntriggerEnter Rocks " + currentRocks + " total " + totalRocks + " destoyed " + destroyedRocks); // let all the clients know the current rock counts for music // IMPORTANT!!!!, this must be called before the detroy or the rpc will never go out. diff --git a/Assets/RocketSphere.cs b/Assets/RocketSphere.cs index ff9d635..8b23161 100644 --- a/Assets/RocketSphere.cs +++ b/Assets/RocketSphere.cs @@ -15,6 +15,7 @@ // readjust center point if head moves too far away from center // add fade in and out of levels // shots same color as ships +// animate hyperspace between radius levels //rockets, rocks and ray-guns // stick man astronauts @@ -38,11 +39,13 @@ public class RocketSphere : NetworkBehaviour ParticleSystem engineParticleSystem; AudioSource hyperspaceSound; AudioSource engineSound; + public Color[] RocketColors; + public static bool[] colorInUse = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false } ; + [SyncVar] public int rocketColorIndex = -1; public GameObject explosionPrefab; Rigidbody rb; [SyncVar] Color RocketColor = Color.white; - public float hue = 2.0f; [SyncVar] bool visible = false; [SyncVar] Quaternion rot2Save = Quaternion.identity; @@ -52,6 +55,7 @@ public class RocketSphere : NetworkBehaviour void OnDestroy() { + // avoid memory leak Destroy(cachedMaterial); } @@ -60,73 +64,83 @@ public override void OnStartServer() // call the base function, important, odd behavior when connecting when not on same start scene base.OnStartServer(); - // create a random color for each player as they are created on the server - //RocketColor = new Color(Random.Range(0.3f, 1.0f), Random.Range(0.3f, 1.0f), Random.Range(0.3f, 1.0f)); - - // only use a colored ship if we are not the host so we can see who the host is and avoid shutdown of the host + // only use a colored ship if we are not the host so we can see who the host is and avoid shutdown of the host if (!isLocalPlayer) { - hue = Random.Range(0.0f, 1.0f); - Debug.Log("player check hue " + hue); + // pick a random bright color index + rocketColorIndex = (int)Random.Range(0.0f, RocketColors.Length - 0.01f); + Debug.Log("player check color " + rocketColorIndex); + // get all the current players RocketSphere[] players = FindObjectsOfType(); + // initialize a breakout count int count = 0; + + // check each player for (int i = 0; i < players.Length; i++) { - float otherplayerhue = players[i].hue; - - Debug.Log("Other Player " + i + " hue " + otherplayerhue); - + // don't check againts ourself if (players[i] == this) { - Debug.Log("this player " + i + " skip"); + Debug.Log("this player " + i + " skip color check"); continue; } + + Debug.Log("Other Player " + i + " color " + players[i].rocketColorIndex); + + // increment our breakout count count++; + + // breakout if we reach a limit if (count > 100) { Debug.Log("Give up finding a better color"); + + // use the first index if all else fails + rocketColorIndex = 0; + + // go through all the colors in use table + for (int j = 0; j < colorInUse.Length; j++) + { + // just chose the first color not in use + if (colorInUse[j] == false) + { + rocketColorIndex = j; + break; // done searching + } + } 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 - - Debug.Log("diffs " + - Mathf.Abs(hue - otherplayerhue) + " " + - Mathf.Abs(hue - otherplayerhue + 1.0f) + " " + - Mathf.Abs(hue - otherplayerhue - 1.0f)); - const float colorhuediffmax = 0.10f; - - if ( ((Mathf.Abs(hue - otherplayerhue) < colorhuediffmax) || - (Mathf.Abs(hue - otherplayerhue + 1.0f) < colorhuediffmax) || - (Mathf.Abs(hue - otherplayerhue - 1.0f) < colorhuediffmax)) && - (players[i] != this)) + // check for different color between player and selected color + if (players[i].rocketColorIndex == rocketColorIndex) { - Debug.Log("Player " + i + " hue " + players[i].hue + " too close to hue " + hue); + Debug.Log("Player " + i + " color " + players[i].rocketColorIndex + " matches " + players[i].rocketColorIndex); - // generate a new hue if it is too close to this other players color - hue = Random.Range(0.0f, 1.0f); + // generate a new color index if it matches other players color + rocketColorIndex = (int)Random.Range(0.0f, RocketColors.Length - 0.01f); - Debug.Log("try new hue " + hue); + Debug.Log("try new color " + rocketColorIndex); - // restart check with new hue until we find a hue that is different enough from all the other players. + // restart check index to check new color index with all the players again + // until we find a color index that is different from all the other players. i = 0; } } - // rocket color is now set for this player until it is destroyed or disconnects - RocketColor = Color.HSVToRGB(hue, 1.0f, 1.0f); - Debug.Log("player assigned hue " + hue); + // set rocket color for this player until it is destroyed or disconnects + RocketColor = RocketColors[rocketColorIndex]; + colorInUse[rocketColorIndex] = true; + Debug.Log("player assigned color " + rocketColorIndex); } - else + else // server player { // server color is always white RocketColor = Color.white; - hue = -2.0f; + + // need to set the color index so we don't overlap any of the color indexes + rocketColorIndex = -1; } // Find the rocket child object @@ -291,7 +305,7 @@ void OnTriggerEnter(Collider other) if (shot) { - if (shot.playershooterhue == hue) + if (shot.playerShooterColorIndex == rocketColorIndex) { // ignore our own shots return; @@ -322,7 +336,7 @@ void Fire() GameObject shot = Instantiate(shotPrefab, pos, rot) as GameObject; // save the hue of the shooter in the shot so we won't collide with it later - shot.GetComponent().playershooterhue = hue; + shot.GetComponent().playerShooterColorIndex = rocketColorIndex; shot.transform.rotation = transform.rotation; @@ -414,7 +428,6 @@ void CmdEngineOff() RpcEngineOff(); } - //??? this would be nice to animate between radius levels [Client] void Hyperspace() { diff --git a/Assets/RocketSphere.prefab b/Assets/RocketSphere.prefab index a2385a1..48bfe77 100644 Binary files a/Assets/RocketSphere.prefab and b/Assets/RocketSphere.prefab differ diff --git a/Assets/ShotSphere.cs b/Assets/ShotSphere.cs index a942caa..cb93670 100644 --- a/Assets/ShotSphere.cs +++ b/Assets/ShotSphere.cs @@ -9,11 +9,14 @@ public class ShotSphere : NetworkBehaviour public GameObject shotPrefab; GameObject shot; public GameObject explosionPrefab; - public float playershooterhue = -10.0f; + public int playerShooterColorIndex = -10; // used to keep track of the player who shot this shot bool destroyed = false; public override void OnStartServer() { + base.OnStartServer(); + + // this object is short lived Invoke(nameof(DestroySelf), 1.5f); } @@ -27,15 +30,10 @@ void Start() transform.position = Vector3.zero; // we use the rotation that was set by the player object - shot = transform.Find("shot").gameObject; - //shot = Instantiate(shotPrefab, Vector3.zero, Quaternion.identity) as GameObject; - //shot.transform.SetParent(transform); shot.transform.position = transform.rotation * Vector3.forward * radius; shot.transform.rotation = transform.rotation; - - //Destroy(transform.gameObject, 1.5f); } // ServerCallback because we don't want a warning @@ -43,17 +41,21 @@ void Start() [ServerCallback] void OnTriggerEnter(Collider other) { + // get the collider rocket if it exists RocketSphere rocket = other.attachedRigidbody.GetComponent(); + // have we collided with a rocket if (rocket) { - if (rocket.hue == playershooterhue) + // check if we are running into our own shots + if (rocket.rocketColorIndex == playerShooterColorIndex) { // ignore our own shots return; } } + // don't destroy ourself more than once if (destroyed == false) { destroyed = true; @@ -65,7 +67,12 @@ void OnTriggerEnter(Collider other) [Server] void DestroySelf() { - NetworkServer.Destroy(gameObject); + // don't destroy ourself more than once + if (destroyed == false) + { + destroyed = true; + NetworkServer.Destroy(gameObject); + } } // Update is called once per frame diff --git a/Assets/arcader_outro_150.wav b/Assets/arcader_outro_150.wav index 7f29828..7fff5f8 100644 Binary files a/Assets/arcader_outro_150.wav and b/Assets/arcader_outro_150.wav differ diff --git a/Assets/arcader_outro_long_150.wav b/Assets/arcader_outro_long_150.wav new file mode 100644 index 0000000..7f29828 Binary files /dev/null and b/Assets/arcader_outro_long_150.wav differ diff --git a/Assets/arcader_outro_long_150.wav.meta b/Assets/arcader_outro_long_150.wav.meta new file mode 100644 index 0000000..d97943b --- /dev/null +++ b/Assets/arcader_outro_long_150.wav.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: d17d04548dea02344836cf36c284271f +AudioImporter: + externalObjects: {} + serializedVersion: 6 + defaultSettings: + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + preloadAudioData: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 13d1f3b..cb62202 100644 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ