} // End Unity method Awake private void OnCollisionEnter2D(Collision2D coll) { int otherLayer = coll.gameObject.layer; if (otherLayer == (int)Game.Layers.UFO) { Commentator.raiseEvent(CommentEvent.BallHitsPlayer); killMe(); } else if (otherLayer == (int)Game.Layers.Planets && coll.gameObject.name != "Sun") { Commentator.raiseEvent(CommentEvent.BallHitsPlanet); if (!bounceSound.isPlaying) { bounceSound.volume = Game.getSoundVolume(); bounceSound.Play(); } } else if (otherLayer == (int)Game.Layers.Hole) { int numStrokes = parentShip.getNumStrokes(); EventHandler.raiseEvent(GameEvent.LevelWon, numStrokes); if (numStrokes == 1) { Commentator.raiseEvent(CommentEvent.HoleInOne); } else { Commentator.raiseEvent(CommentEvent.LevelWon); } killMe(); } } // End Unity method OnCollisionEnter2D
} // End Unity method OnTriggerExit2D private void Update() { lifetime += Time.deltaTime; if (spaceshipCollisionsDisabled && lifetime > LAUNCH_COLLIDER_TIMEOUT) { enableSpaceshipCollisions(); } if (body2D.velocity.sqrMagnitude <= MIN_SQR_MAGNITUDE) { timeStopped += Time.deltaTime; if (timeStopped >= MAX_TIME_STOPPED) { Commentator.raiseEvent(CommentEvent.BallStops); killMe(); } } else { timeStopped = 0.0f; } if (lifetime >= MAX_LIFETIME) { Commentator.raiseEvent(CommentEvent.BallTimeout); killMe(); } } // End Unity method Update
} // End Unity method OnMouseUpAsButton // Additional methods private void destroyMe() { effectsPool.playEffect(EffectsPool.Effect.PlanetDestroyed, transform.position, transform.localScale); gameObject.SetActive(false); EventHandler.raiseEvent(GameEvent.PlanetDestroyed); Commentator.raiseEvent(CommentEvent.PlanetDestroyed); } // End private method destroyMe
} // End private Unity method OnMouseUp // Additional Methods private void fire(Vector2 shotVector) { GolfBall myBall = nextInPool(); if (myBall == null) { return; } incrementStrokes(); if (shotVector.sqrMagnitude > 0.99f) { ++consecutiveStrokesAtFullPower; if (consecutiveStrokesAtFullPower >= Commentator.FULL_POWER_STROKES_THRESHOLD) { Commentator.raiseEvent(CommentEvent.AlwaysFullPower); } } else { consecutiveStrokesAtFullPower = 0; } playLaunchClip(); myBall.launch(transform.position, shotVector * LAUNCH_POWER, this); Game.setState(Game.State.WaitingOnBall); } // End private method fire
} // End public method hideFirstRunScreen public void pauseGame() { Time.timeScale = 0.0f; pauseMenu.SetActive(true); Game.setState(Game.State.Paused); Commentator.raiseEvent(CommentEvent.GamePaused); } // End public method pauseGame
} // End private method getShotVector public void incrementStrokes(int numToIncrement = 1) { numStrokes += numToIncrement; EventHandler.raiseEvent(GameEvent.StrokeTaken, numStrokes); if (numStrokes >= Commentator.MANY_STROKES_THRESHOLD) { Commentator.raiseEvent(CommentEvent.ManyStrokes); } } // End public method incrementStrokes
} // End private Unity method OnDrawGizmos private void OnMouseDown() { if (Game.getState() == Game.State.Running && !liningUpShot) { liningUpShot = true; Vector2 shotVector = getShotVector(); targetingReticule.gameObject.SetActive(true); setTargetingReticule(shotVector); Commentator.raiseEvent(CommentEvent.LiningUpShot); } // End if we are able to select a target } // End private Unity method OnMouseDown
} // End private method setTargetingReticule private IEnumerator warpCoroutine(Vector2 newPos) { yield return(new WaitForSeconds(WARP_DELAY)); if (Vector2.Distance(newPos, (Vector2)transform.position) < Commentator.SHORT_WARP_DISTANCE_THRESHOLD) { Commentator.raiseEvent(CommentEvent.ShortWarp); } warpEffect.SetActive(true); playWarpClip(); yield return(new WaitForSeconds(WARP_DELAY)); transform.position = (Vector3)newPos; } // End private coroutine method warpCoroutine
} // End public method beginCommentVolume public void endCommentVolume() { float currentCommentVolume = commentVolumeSlider.value; if (currentCommentVolume > prevCommentVolume) { Commentator.raiseEvent(CommentEvent.CommentsTurnedUp); } else if (currentCommentVolume < prevCommentVolume) { Commentator.raiseEvent(CommentEvent.CommentsTurnedDown); } prevCommentVolume = currentCommentVolume; endVolumeChange(); } // End public method endCommentVolume
} // End public method inScreenBounds public void killMe() { effectsPool.playEffect(EffectsPool.Effect.BallExplosion, transform.position); if (inScreenBounds()) { Vector2 closestPosition = calcNearestWarp(); parentShip.warpToPosition(closestPosition); } else { EventHandler.raiseEvent(GameEvent.BallOutOfBounds); Commentator.raiseEvent(CommentEvent.BallOutOfBounds); } Game.setState(Game.State.Running); gameObject.SetActive(false); } // End public method killMe