Skip to content

Commit

Permalink
Shorted ending music a bit, fix music overlaping intro music, new ran…
Browse files Browse the repository at this point in the history
…dome color system with pre-selected colors instead of completely random, cleanup, add disabled network handler to all levels for easy testing.
  • Loading branch information
plaidpants committed Feb 6, 2022
1 parent 4376ba1 commit edb3615
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 55 deletions.
Binary file modified Assets/Game2.unity
Binary file not shown.
Binary file modified Assets/Game3.unity
Binary file not shown.
Binary file modified Assets/Game4.unity
Binary file not shown.
Binary file modified Assets/Game5.unity
Binary file not shown.
Binary file modified Assets/Game6.unity
Binary file not shown.
8 changes: 7 additions & 1 deletion Assets/MusicHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ public override void OnStartClient()
musicLoops[i] = gameObject.AddComponent<AudioSource>();
//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<AudioSource>();
outroMusic.clip = outroMusicClip;
outroMusic.loop = false;
outroMusic.volume = 0.5f;

// start the intro music
introMusic = gameObject.AddComponent<AudioSource>();
introMusic.clip = introMusicClip;
introMusic.loop = false;
introMusic.volume = 0.5f;
introMusic.Play();

// queue the first loop playing and looping after the intro
Expand All @@ -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;

Expand All @@ -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");
Expand Down Expand Up @@ -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");

Expand Down
1 change: 1 addition & 0 deletions Assets/NetworkManagerRocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void NextLevel()
level = 1;
}

// get a hold of the music handler
MusicHandler mh = FindObjectOfType<MusicHandler>();

// wait for outro music + last music loop + 5 seconds before switching to the next level
Expand Down
7 changes: 4 additions & 3 deletions Assets/RockField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,7 +25,6 @@ public override void OnStartServer()
GameObject rock = Instantiate(RockSpherePrefab, pos, rot) as GameObject;

NetworkServer.Spawn(rock);
//rock.transform.SetParent(transform);
}
}

Expand All @@ -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 ()
{

}
}
6 changes: 3 additions & 3 deletions Assets/RockSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.
Expand Down
93 changes: 53 additions & 40 deletions Assets/RocketSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -52,6 +55,7 @@ public class RocketSphere : NetworkBehaviour

void OnDestroy()
{
// avoid memory leak
Destroy(cachedMaterial);
}

Expand All @@ -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<RocketSphere>();

// 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
Expand Down Expand Up @@ -291,7 +305,7 @@ void OnTriggerEnter(Collider other)

if (shot)
{
if (shot.playershooterhue == hue)
if (shot.playerShooterColorIndex == rocketColorIndex)
{
// ignore our own shots
return;
Expand Down Expand Up @@ -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<ShotSphere>().playershooterhue = hue;
shot.GetComponent<ShotSphere>().playerShooterColorIndex = rocketColorIndex;

shot.transform.rotation = transform.rotation;

Expand Down Expand Up @@ -414,7 +428,6 @@ void CmdEngineOff()
RpcEngineOff();
}

//??? this would be nice to animate between radius levels
[Client]
void Hyperspace()
{
Expand Down
Binary file modified Assets/RocketSphere.prefab
Binary file not shown.
23 changes: 15 additions & 8 deletions Assets/ShotSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -27,33 +30,32 @@ 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
// if OnTriggerEnter is called on the client
[ServerCallback]
void OnTriggerEnter(Collider other)
{
// get the collider rocket if it exists
RocketSphere rocket = other.attachedRigidbody.GetComponent<RocketSphere>();

// 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;
Expand All @@ -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
Expand Down
Binary file modified Assets/arcader_outro_150.wav
Binary file not shown.
Binary file added Assets/arcader_outro_long_150.wav
Binary file not shown.
22 changes: 22 additions & 0 deletions Assets/arcader_outro_long_150.wav.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.

0 comments on commit edb3615

Please sign in to comment.