//should probably change so that it adds the score and such on Achievements or AsteraX /// <summary> /// Handles destruction of the Asteroid when its hit /// </summary> /// <param name="collision"></param> public void AsteroidHit(Collision collision) { int childCount = transform.childCount; //getting position before destroying the bullet Vector3 collisionPosition = collision.transform.position; //updates score and destroys bullet if (collision.gameObject.GetComponent <Bullet>()) { //the score seemed to be like binary so thought I'd just calculate for any size if the player didn't die already. //added more to score while dead so fixed that. if (!AsteraX.DEAD) { playerController.AddPoints((int)Mathf.Pow(2, _asteroidInfo.size - size) * 100); Achievements.ASTEROIDS_HIT++; Achievements.AchievementCheck(); if (collision.gameObject.GetComponent <Bullet>().bulletWrapped) { Achievements.BULLET_WRAP_COUNT++; Achievements.AchievementCheck(); } } UIScript.UpdateScore(playerController.GetScore()); Destroy(collision.gameObject); } for (int i = 0; i < childCount; i++) { Transform child = transform.GetChild(0); child.SetParent(null, true); if (child.GetComponent <Asteroid>()) { Asteroid asteroidComp = child.GetComponent <Asteroid>(); asteroidComp.EnableRB(); asteroidComp.AddForceFromPoint(collisionPosition, Random.Range(_asteroidInfo.minVelocity, _asteroidInfo.maxVelocity)); asteroidComp.AddAngularVelocity(Random.insideUnitSphere * _asteroidInfo.maxAngularVelocity); } } //dont need to check for get component since this is the component its looking for. AsteraX.RemoveAsteroid(this); //starts onDestroy Event onDestroy.Invoke(); AsteraX.ExplosionEffect(transform, size); //destroys this asteroid #if MOBILE_INPUT foreach (GameObject col in compoundColliders) { Destroy(col); } #endif Destroy(gameObject); }
public void OnCollisionEnter(Collision coll) { // If this is the child of another Asteroid, pass this collision up the chain if (parentIsAsteroid) { parentAsteroid.OnCollisionEnter(coll); return; } if (immune) { return; } GameObject otherGO = coll.gameObject; if (otherGO.tag == "Bullet" || otherGO.transform.root.gameObject.tag == "Player") { if (otherGO.tag == "Bullet") { Destroy(otherGO); AsteraX.AddScore(AsteraX.AsteroidsSO.pointsForAsteroidSize[size]); AchievementManager.AchievementStep(Achievement.eStepType.hitAsteroid, 1); Bullet bul = otherGO.GetComponent <Bullet>(); if (bul != null) { if (bul.bDidWrap) { AchievementManager.AchievementStep(Achievement.eStepType.luckyShot); } } } if (size > 1) { // Detach the children Asteroids Asteroid[] children = GetComponentsInChildren <Asteroid>(); for (int i = 0; i < children.Length; i++) { children[i].immune = true; if (children[i] == this || children[i].transform.parent != transform) { continue; } children[i].transform.SetParent(null, true); children[i].InitAsteroidParent(); } } InstantiateParticleSystem(); Destroy(gameObject); } }
public void SetCurrentAsteroidCount() { string[] splitAsteroidArray = _levelProgression.Split(','); string splitAsteroid = splitAsteroidArray[AsteraX.GetLevel() - 1]; string ignoreLevel = splitAsteroidArray[AsteraX.GetLevel() - 1].Split(':')[1]; string[] childrenAndParents = ignoreLevel.Split('/'); targetAsteroidCount = int.Parse(childrenAndParents[0].ToString()); targetChildCount = int.Parse(childrenAndParents[1].ToString()); }
void Respawn() { StartCoroutine(AsteraX.FindRespawnPointCoroutine(transform.position, RespawnCallback)); OffScreenWrapper wrapper = GetComponent <OffScreenWrapper>(); if (wrapper != null) { wrapper.enabled = false; } transform.position = new Vector3(10000, 10000, 0); }
private void Awake() { if (_S == null) { _S = this; } if (onLevelComplete == null) { onLevelComplete = new UnityEvent(); } ASTEROIDS = new List <Asteroid>(); }
void Respawn() { StartCoroutine(AsteraX.PlotRespawnPointCoroutine(RespawnCallback)); // Move the player off screen, disable OffScreenWrapper until respawn OffScreenWrapper wrapper = GetComponent <OffScreenWrapper>(); if (wrapper != null) { wrapper.enabled = false; } transform.position = new Vector3(10000, 10000, 0); }
public IEnumerator TryJump() { if (_currentJumps > 0) { OnJump.Invoke(); _playerCollider.enabled = false; yield return(new WaitForSeconds(respawnTime)); Vector3 randomPosition = ScreenBounds.RANDOM_ON_SCREEN_LOC_HALF; List <Asteroid> asteroids = AsteraX.ASTEROIDS; int infLoopSave = 0; int distance = 5; for (int i = 0; i < asteroids.Count;) { infLoopSave++; if (Vector3.Distance(randomPosition, asteroids[i].transform.position) > distance) { i++; } else { //one was in the way so trying again i = 0; randomPosition = ScreenBounds.RANDOM_ON_SCREEN_LOC_HALF; } //in case it doesn't work I reduce the distance so it will spawn eventually. if (infLoopSave > asteroids.Count * 100) { distance = distance >= 1 ? distance / 2 : 0; Debug.Log("Distance set too high, reduced to: " + distance); infLoopSave = 0; } } RemoveJumps(1); UIScript.UpdateJumps(_currentJumps); transform.position = randomPosition; OnRespawn.Invoke(); _playerCollider.enabled = true; jumping = false; } else { dead = true; _playerCollider.enabled = false; SaveGameManager.CheckHighScore(_score); UIScript.SetFinalScore(_score, AsteraX.GetLevel()); CustomAnalytics.SendGameOver(); CustomAnalytics.SendFinalShipPartChoice(); OnDeath.Invoke(); } }
void Respawn() { #if DEBUG_PlayerShip_RespawnNotifications Debug.Log("PlayerShip:Respawn()"); #endif StartCoroutine(AsteraX.FindRespawnPointCoroutine(transform.position, RespawnCallback)); OffScreenWrapper wrapper = GetComponent <OffScreenWrapper>(); if (wrapper != null) { wrapper.enabled = false; } transform.position = new Vector3(10000, 10000.0); }
private bool CheckSavePosition(Vector3 position) { var asteroids = AsteraX.GetAsteroids(); foreach (var item in asteroids) { if (Vector2.Distance(position, item.transform.position) < 5) { return(false); } } return(true); }
// Setting this function to public so it can be called from the Asteroid's OnCollisionEnter function public void Jump() { JUMPS--; JUMPS_TEXT.text = "Jumps: " + JUMPS; if (JUMPS <= 0) { gameObject.SetActive(false); AsteraX.GameOver(); } else { Respawn(); } }
public void OnCollisionEnter(Collision coll) { // If this is the child of another Asteroid, pass this collision up the chain if (parentIsAsteroid) { parentAsteroid.OnCollisionEnter(coll); return; } if (immune) { return; } GameObject otherGO = coll.gameObject; if (otherGO.tag == "Bullet" || otherGO.transform.root.gameObject.tag == "Player") { if (otherGO.tag == "Bullet") { Destroy(otherGO); AsteraX.AddScore(AsteraX.AsteroidsSO.pointsForAsteroidSize [size]); } if (otherGO.tag == "Player") { PlayerShip ship = otherGO.GetComponent <PlayerShip> (); ship.Jump(); } if (size > 1) { // Detach the children Asteroids Asteroid[] children = GetComponentsInChildren <Asteroid>(); for (int i = 0; i < children.Length; i++) { children[i].immune = true; if (children[i] == this || children[i].transform.parent != transform) { continue; } children[i].transform.SetParent(null, true); children[i].InitAsteroidParent(); } } Destroy(gameObject); } }
void AsteroidHitByBullet(GameObject otherGO) { Destroy(otherGO); Destroy(gameObject); PlayerShip.S.bullets += 2; AsteraX.score += 10; try { throw new System.NullReferenceException("Parameter cannot be null"); } catch (System.NullReferenceException nre) { AsteraX.GetBacktraceClient().Send(nre); } }
public void OnCollisionEnter(Collision coll) { if (immune) { return; } GameObject otherGO = coll.gameObject; if (otherGO.tag == "Bullet") { AsteroidHitByBullet(otherGO); } else if (otherGO.tag == "Player") { Destroy(gameObject); PlayerShip.S.health -= 5; AsteraX.GetBacktraceClient()["shipHealth"] = "" + PlayerShip.S.health; if (PlayerShip.S.health <= 90) { #if (!UNITY_EDITOR) CrashOnAndroid(); // this crashes the entire game Utils.ForceCrash(ForcedCrashCategory.AccessViolation); #endif } if (PlayerShip.S.health <= 0) { Destroy(otherGO); AsteraX.backtraceClient.Breadcrumbs.Info("Player Died!", new Dictionary <string, string>() { { "application.version", AsteraX.backtraceClient["application.version"] }, }); } } else if (otherGO.tag == "Asteroid") { //Destroy(otherGO); //Destroy(gameObject); } }
void Start() { transform.SetParent(BULLET_ANCHOR, true); AsteraX.AddBullet(this); // Set Bullet to self-destruct in lifeTime seconds Invoke("DestroyMe", lifeTime); // Set the velocity of the Bullet GetComponent <Rigidbody>().velocity = transform.forward * bulletSpeed; // Attach the particle effect GameObject pe = Instantiate <GameObject>(particleEffectPrefab); pe.transform.SetParent(transform); pe.transform.localPosition = Vector3.zero; }
void Respawn() { #if DEBUG_PlayerShip_RespawnNotifications Debug.Log("PlayerShip:Respawn()"); #endif StartCoroutine(AsteraX.FindRespawnPointCoroutine(transform.position, RespawnCallback)); // Initially, I had made the gameObject inactive, but this caused the // coroutine called above to never return from yield! //gameObject.SetActive(false); // Now, instead, I turn off the OffScreenWrapper and move the GameObject // outside the play area until RespawnCallback is called. OffScreenWrapper wrapper = GetComponent <OffScreenWrapper>(); if (wrapper != null) { wrapper.enabled = false; } transform.position = new Vector3(10000, 10000, 0); }
// Use this for initialization void Start() { /* * Track the collisions with player * by tag "Asteroid" * */ this.tag = "Asteroid"; AsteraX.AddAsteroid(this); transform.localScale = Vector3.one * size * AsteraX.AsteroidsSO.asteroidScale; if (parentIsAsteroid) { InitAsteroidChild(); } else { InitAsteroidParent(); } // Spawn child Asteroids if (size > 1) { Asteroid ast; for (int i = 0; i < AsteraX.AsteroidsSO.numSmallerAsteroidsToSpawn; i++) { ast = SpawnAsteroid(); ast.size = size - 1; ast.transform.SetParent(transform); Vector3 relPos = Random.onUnitSphere / 2; ast.transform.rotation = Random.rotation; ast.transform.localPosition = relPos; ast.gameObject.name = gameObject.name + "_" + i.ToString("00"); } } }
private void OnDestroy() { AsteraX.RemoveAsteroid(this); EventBroker.GameOver -= DestroyMe; }
void SetState(eLevelAdvanceState newState) { stateStartTime = realTime; switch (newState) { case eLevelAdvanceState.idle: gameObject.SetActive(false); if (idleCallback != null) { idleCallback(); idleCallback = null; } break; case eLevelAdvanceState.fadeIn: gameObject.SetActive(true); // Set text levelText.text = "Level " + AsteraX.GAME_LEVEL; levelRT.localScale = new Vector3(1, 0, 1); AsteraX.LevelInfo lvlInfo = AsteraX.GetLevelInfo(); infoText.text = "Asteroids: " + lvlInfo.numInitialAsteroids + "\tChildren: " + lvlInfo.numSubAsteroids; infoText.color = Color.clear; // Set initial state img.color = Color.clear; levelRT.localScale = new Vector3(1, 0, 1); infoText.color = Color.clear; // Set timiing and advancement stateDuration = fadeTime * 0.2f; nextState = eLevelAdvanceState.fadeIn2; break; case eLevelAdvanceState.fadeIn2: // Set initial state img.color = Color.black; levelRT.localScale = new Vector3(1, 0, 1); infoText.color = Color.clear; // Set timiing and advancement stateDuration = fadeTime * 0.6f; nextState = eLevelAdvanceState.fadeIn3; break; case eLevelAdvanceState.fadeIn3: // Set initial state img.color = Color.black; levelRT.localScale = new Vector3(1, 1, 1); infoText.color = Color.clear; // Set timiing and advancement stateDuration = fadeTime * 0.2f; nextState = eLevelAdvanceState.display; break; case eLevelAdvanceState.display: stateDuration = displayTime; nextState = eLevelAdvanceState.fadeOut; if (displayCallback != null) { displayCallback(); displayCallback = null; } break; case eLevelAdvanceState.fadeOut: // Set initial state img.color = Color.black; levelRT.localScale = new Vector3(1, 1, 1); infoText.color = Color.white; // Set timiing and advancement stateDuration = fadeTime * 0.2f; nextState = eLevelAdvanceState.fadeOut2; break; case eLevelAdvanceState.fadeOut2: // Set initial state img.color = Color.black; levelRT.localScale = new Vector3(1, 1, 1); infoText.color = Color.clear; // Set timiing and advancement stateDuration = fadeTime * 0.6f; nextState = eLevelAdvanceState.fadeOut3; break; case eLevelAdvanceState.fadeOut3: // Set initial state img.color = Color.black; levelRT.localScale = new Vector3(1, 0, 1); infoText.color = Color.clear; // Set timiing and advancement stateDuration = fadeTime * 0.2f; nextState = eLevelAdvanceState.idle; break; } state = newState; }
private void OnDestroy() { AsteraX.RemoveAsteroid(this); }
private void RunGameOver() { ScoreManager.FinalScore(); AsteraX.GameOver(); }
static public void GyroscopeDelta() { AsteraX.GetGyroscopeDevice(); }
// Allows the Button child of this GameObject to call a static method public void StartGame() { AsteraX.StartGame(); }
private void OnDestroy() { AsteraX.RemoveBullet(this); }
//decided I'd try to only run this on an event(aka when the value changed) so after I add the value //I just call it on the script I added it from. plan on making methods later to make it simpler. /// <summary> /// make sure to call this after changing variables /// </summary> public static void AchievementCheck() { if (SaveGameManager.CheckHighScore(SCORE) && !_S._newHighScore) { _S._newHighScore = true; AchievementSettings highScoreSettings = new AchievementSettings(); highScoreSettings.title = _S.highScoreTitle; highScoreSettings.description = _S.highScoreDescription; highScoreSettings.count = SCORE; _S._settingsQueue.Enqueue(highScoreSettings); UIScript.SetGameOverText("HIGH SCORE!"); } foreach (AchievementSettings setting in _S.settings) { switch ((int)setting.achievementType) { case 0: //LuckyShot if (BULLET_WRAP_COUNT >= setting.count && !setting.complete) { setting.complete = true; _S._settingsQueue.Enqueue(setting); CustomAnalytics.SendAchievementUnlocked(setting); } break; case 1: //AsteroidHitCount if (ASTEROIDS_HIT >= setting.count && !setting.complete) { setting.complete = true; _S._settingsQueue.Enqueue(setting); CustomAnalytics.SendAchievementUnlocked(setting); } break; case 2: //BulletsFired if (BULLETS_FIRED >= setting.count && !setting.complete) { setting.complete = true; _S._settingsQueue.Enqueue(setting); CustomAnalytics.SendAchievementUnlocked(setting); } break; case 3: //Points if (SCORE >= setting.count && !setting.complete) { setting.complete = true; _S._settingsQueue.Enqueue(setting); CustomAnalytics.SendAchievementUnlocked(setting); } break; case 4: //LevelsComplete if (AsteraX.GetLevel() >= setting.count && !setting.complete) { setting.complete = true; _S._settingsQueue.Enqueue(setting); CustomAnalytics.SendAchievementUnlocked(setting); } break; default: break; } UIScript.UnlockToggleFromAchievement(setting); } SaveGameManager.Save(); }