void Start() { int maxBuoys = 5; //max limit available bool tooCloseToOthers = SoundBuoyScript.CloseToOthers(gameObject, 100.0f); if (!tooCloseToOthers) { tooCloseToOthers = BlackHoleScript.CloseToOthers(gameObject, 100.0f); } if (WorldBuoysList.Count >= maxBuoys || tooCloseToOthers) { DestroyImmediate(gameObject); return; } buoyAnimations[0] = "appear"; buoyAnimations[1] = "moving"; buoyAnimations[2] = "drop"; buoyAnimations[3] = "ringing"; buoyAnimations[4] = "ding"; buoyAnimations[5] = "sink"; buoyAnimations[6] = "underwater"; sprite.animationCompleteDelegate += AnimationComplete; WorldBuoysList.Add(this); fluidField = GameObject.FindGameObjectWithTag("fluidField").GetComponent <FluidFieldGenerator>(); audio.clip = ringingSounds[WorldBuoysList.IndexOf(this)]; audio.loop = true; audio.volume = 0.0f; audio.Play(); }
void Update() { levelRunTime += Time.deltaTime; if (p1 == null) { p1 = GameObject.FindGameObjectWithTag("PLAYER1"); if (p1 != null) { player1 = p1.GetComponent <PlayerScript>(); } } if (p2 == null) { p2 = GameObject.FindGameObjectWithTag("PLAYER2"); if (p2 != null) { player2 = p2.GetComponent <PlayerScript>(); } } if (p1 == null || p2 == null) { return; } PlayerScript.FingerState p1finger = player1.MouseFingerDown(); PlayerScript.FingerState p2finger = player2.MouseFingerDown(); if (p1finger == PlayerScript.FingerState.Single && p2finger == PlayerScript.FingerState.Single) { player1.SetDoLinkInk(true); player2.SetDoLinkInk(true); } else { player1.SetDoLinkInk(false); player2.SetDoLinkInk(false); } GameObject[] blackHoles = GameObject.FindGameObjectsWithTag("blackhole"); foreach (GameObject bh in blackHoles) { BlackHoleScript blackHoleScript = bh.GetComponent <BlackHoleScript>(); if (Network.isServer) { player1.UpdateAgainstBlackHole(blackHoleScript); } else if (Network.isClient) { player2.UpdateAgainstBlackHole(blackHoleScript); } } if (levelRunTime > 5.0f && blackHoles.Length == 0) { GameLogicController.instance.MoveToNextLevel(); } }
public override void UseAbility(PlayerController playerScript, GameObject playerObject) { GameObject bHObject = (GameObject)Instantiate(blackHole, new Vector2(playerObject.transform.position.x + (0.01f * playerScript.directionFacing), playerObject.transform.position.y), Quaternion.Euler(0, 0, 90)); BlackHoleScript bHScript = bHObject.GetComponent <BlackHoleScript>(); bHScript.owner = playerObject; bHScript.SetSpeed(1 * playerScript.directionFacing); }
// Use this for initialization void Start() { parentScript = GetComponentInParent<BlackHoleScript>(); collider = gameObject.GetComponent<Collider>(); active = parentScript.IsActive(); collider.enabled = active; }
// Use this for initialization void Start() { parentScript = GetComponentInParent <BlackHoleScript>(); collider = gameObject.GetComponent <Collider>(); active = parentScript.IsActive(); collider.enabled = active; }
public void UpdateAgainstBlackHole(BlackHoleScript blackHole) { if (mouseIsMovingWhileDown && blackHole != null) { Camera camcam = Camera.main; Vector3 blackHoleCenter = camcam.WorldToScreenPoint(blackHole.transform.position); float compundedMangle = 0.0f; float totalmangle = 0.0f; for (int i = 1; i < currentMousePoints.Count; ++i) { Vector2 old = (Vector2)currentMousePoints[i - 1]; Vector2 cur = (Vector2)currentMousePoints[i]; float yDistCur = cur.y - blackHoleCenter.y; float xDistCur = cur.x - blackHoleCenter.x; float yDistOld = old.y - blackHoleCenter.y; float xDistOld = old.x - blackHoleCenter.x; float maxRadius = 150; float minRadius = 20; float curLen = (float)System.Math.Sqrt((xDistCur * xDistCur) + (yDistCur * yDistCur)); //float oldLen = (float)System.Math.Sqrt((xDistOld * xDistOld) + (yDistOld * yDistOld)); if (curLen > minRadius && curLen < maxRadius) { float degsCur = ToDegrees((float)System.Math.Atan2(yDistCur, xDistCur)); float degresOld = ToDegrees((float)System.Math.Atan2(yDistOld, xDistOld)); if (System.Math.Sign(degresOld) == System.Math.Sign(degsCur)) { compundedMangle += System.Math.Abs(System.Math.Abs(degsCur) - System.Math.Abs(degresOld)); totalmangle += degsCur - degresOld; } } } int playerNm = isPlayer1 ? 1 : 2; blackHole.AddToRotationSpeed((totalmangle - previousMangle) * 0.1f, playerNm); previousMangle = totalmangle; } }
void Start() { int maxBlackHoles = 4; bool tooCloseToOthers = SoundBuoyScript.CloseToOthers(gameObject, 100.0f); if (!tooCloseToOthers) { tooCloseToOthers = BlackHoleScript.CloseToOthers(gameObject, 100.0f); } if (WorldBlackHoles.Count >= maxBlackHoles || tooCloseToOthers) { DestroyImmediate(gameObject); return; } WorldBlackHoles.Add(this); }
void Update() { if (p1 == null) { p1 = GameObject.FindGameObjectWithTag("PLAYER1"); if (p1 != null) { player1 = p1.GetComponent <PlayerScript>(); } } if (p2 == null) { p2 = GameObject.FindGameObjectWithTag("PLAYER2"); if (p2 != null) { player2 = p2.GetComponent <PlayerScript>(); } } if (p1 == null || p2 == null) { return; } GameObject[] blackHoles = GameObject.FindGameObjectsWithTag("blackhole"); foreach (GameObject bh in blackHoles) { BlackHoleScript blackHoleScript = bh.GetComponent <BlackHoleScript>(); if (Network.isServer) { player1.UpdateAgainstBlackHole(blackHoleScript); } else if (Network.isClient) { player2.UpdateAgainstBlackHole(blackHoleScript); } } if (blackHoles.Length == 0) { GameLogicController.instance.MoveToNextLevel(); } }
public void UpdateBasedOnBlackHole(BlackHoleScript bhole) { float screenWidth = camcam.GetScreenWidth() - 1; float screenHeight = camcam.GetScreenHeight() - 1; float dt = 1.0f / fluidFPS; Vector3 bholePos = bhole.transform.position; Vector3 screenPos = camcam.WorldToScreenPoint(bholePos); screenPos = camcam.ScreenToViewportPoint(screenPos); int radius = bhole.radius; float velocityPower = bhole.velocityPower; float holePower = bhole.holePower; float goalValue = bhole.inkSpit; float dx = bhole.spewingDirection.x; float dy = bhole.spewingDirection.y; UpdateBlackHole(screenPos.x, screenPos.y, dx, dy, radius, velocityPower, holePower, goalValue, dt); }
public void UpdateAgainstBlackHole(BlackHoleScript blackHole) { if(mouseIsMovingWhileDown && blackHole != null) { Camera camcam = Camera.main; Vector3 blackHoleCenter = camcam.WorldToScreenPoint(blackHole.transform.position); float compundedMangle = 0.0f; float totalmangle = 0.0f; for (int i = 1; i < currentMousePoints.Count; ++i) { Vector2 old = (Vector2)currentMousePoints[i - 1]; Vector2 cur = (Vector2)currentMousePoints[i]; float yDistCur = cur.y - blackHoleCenter.y; float xDistCur = cur.x - blackHoleCenter.x; float yDistOld = old.y - blackHoleCenter.y; float xDistOld = old.x - blackHoleCenter.x; float maxRadius = 150; float minRadius = 20; float curLen = (float)System.Math.Sqrt((xDistCur * xDistCur) + (yDistCur * yDistCur)); //float oldLen = (float)System.Math.Sqrt((xDistOld * xDistOld) + (yDistOld * yDistOld)); if (curLen > minRadius && curLen < maxRadius) { float degsCur = ToDegrees((float)System.Math.Atan2(yDistCur, xDistCur)); float degresOld = ToDegrees((float)System.Math.Atan2(yDistOld, xDistOld)); if (System.Math.Sign(degresOld) == System.Math.Sign(degsCur)) { compundedMangle += System.Math.Abs(System.Math.Abs(degsCur) - System.Math.Abs(degresOld)); totalmangle += degsCur - degresOld; } } } int playerNm = isPlayer1 ? 1 : 2; blackHole.AddToRotationSpeed((totalmangle-previousMangle) * 0.1f, playerNm); previousMangle = totalmangle; } }
public BlackHoleDataEntry(float angle, Vector2 lastPoint, BlackHoleScript targetPlanet) { Angle = angle; LastPoint = lastPoint; TargetPlanet = targetPlanet; }
public void UpdateBasedOnBlackHole(BlackHoleScript bhole) { float screenWidth = camcam.GetScreenWidth()-1; float screenHeight = camcam.GetScreenHeight()-1; float dt = 1.0f / fluidFPS; Vector3 bholePos = bhole.transform.position; Vector3 screenPos = camcam.WorldToScreenPoint(bholePos); screenPos = camcam.ScreenToViewportPoint(screenPos); int radius = bhole.radius; float velocityPower = bhole.velocityPower; float holePower = bhole.holePower; float goalValue = bhole.inkSpit; float dx = bhole.spewingDirection.x; float dy = bhole.spewingDirection.y; UpdateBlackHole(screenPos.x, screenPos.y, dx, dy, radius, velocityPower, holePower, goalValue, dt); }