//Called when a collider enters the trigger private void OnTriggerEnter2D(Collider2D other) { //if the collider's tag is "Asteroid"... if (other.tag == "Asteroid") { AsteroidBehavior split = other.GetComponent <AsteroidBehavior>(); //...create a temporary dataType AsteroidBehavior named split and set it equal to the collider's attached AsteroidBehavior component //if split's itime is less than or equal to 0 seconds... if (split.itime <= 0.0f) { //if the level of the asteroid is equal to 3... if (split.level == 3) { score.score += 10; //...increment the score member variable of score by 10 } //if the level of the asteroid is equal to 2... else if (split.level == 2) { score.score += 50; //...increment the score member variable of score by 50 } //if the level of the asteroid is equal to 1... else if (split.level == 1) { score.score += 100; //...increment the score member variable of score by 100 } split.Explode(); //...start split's Explode() function } } }
void DivideAsteroid(GameObject gameObject, AsteroidBehavior asteroidBehavior) { for (var i = 0; i < 2; i++) { DeployAsteroid(gameObject.transform.position, gameObject.transform.position, asteroidBehavior.Level + 1, 0f); } if (_asteroidCount == 0) { _stage += 1; DeployAsteroids(); } }
public Asteroid(FixedPointVector3 _pos, FixedPoint _scale) { position = _pos; scale = _scale; speed = Extensions.Range(1, 2); health = 5; type = EntityType.Asteroid; body = new CircleBody(position, scale * (FixedPoint)0.5f, this); body.SetLayer(type); body.SetCollidesWith(EntityType.Ufo, true); body.SetCollidesWith(EntityType.Asteroid, true); body.SetCollidesWith(EntityType.Blast, true); body.SetCollidesWith(EntityType.Placeholder, true); behavior = new AsteroidBehavior(this); }
// Update is called once per frame void Update() { m_chrono += Time.deltaTime; m_timeSinceBeginning += Time.deltaTime; if (m_chrono > m_maxTime) { ScoreScript.scoreValue += 100; GameObject firstAsteroid = Instantiate(m_objectToCreate, Vector3.zero, Quaternion.identity); GameObject secondAsteroid = Instantiate(m_objectToCreate2, Vector3.zero, Quaternion.identity); m_chrono = 0f; AsteroidBehavior firstBehavior = firstAsteroid.GetComponent <AsteroidBehavior>(); AsteroidBehavior secondBehavior = secondAsteroid.GetComponent <AsteroidBehavior>(); if (m_timeSinceBeginning > 3) { firstBehavior.m_speed += 200f; secondBehavior.m_speed += 200f; } } }
/// <summary> /// Advance to the next level, create the next map, and readjust the size of /// the player as necessary. /// </summary> /// <param name="nextLevelType">Force set the level type of the next level /// generated</param> void NextLevel(LevelManager.LevelType nextLevelType) { // Reset level-specific stats timer = 0; levelTransitionTimer = 0 + transitionTime; levelScore = 0; openDoor = false; score += (levelManager.Level * 100); // Remove all active asteroids and bullets for (int i = 0; i < asteroidObjects.Count; i++) { RemoveAsteroid(i); i--; } for (int b = 0; b < bullets.Count; b++) { RemoveBullet(b); b--; } // Advance to the level and create the next map levelManager.AdvanceLevel( nextLevelType, Mathf.Clamp( ((levelManager.Level + 1) / 3) + 7, 7, 20)); // Set stats for map dependent on level and level type if (nextLevelType == LevelManager.LevelType.Tutorial) { maxAsteroidCount = 5; minAsteroidSpawnTimer = .4f; maxAsteroidSpawnTimer = 3f; chaserSpawnChance = 0; //lifeDropChance = 0; smallKeyDropChance = .3f; levelGoal = 1; } // Increment difficulty of next level else if (levelManager.Level <= 20) { // Level stats levelGoal = 2 + ((levelManager.Level - 1) * 4); maxAsteroidCount = 10 + (int)((levelManager.Level - 1) * .8f); minAsteroidSpawnTimer = .4f - (levelManager.Level * .015f); maxAsteroidSpawnTimer = 1.3f - (levelManager.Level * .05f); // Drop and Spawn Rarities if (levelManager.Level == 3) { chaserSpawnChance = .15f; // 150% chaser spawn chance } else { if (levelManager.Level == 2) { chaserSpawnChance = 0; } else { // 01.00% -> 4.00% chaser spawn chance chaserSpawnChance = .01f * (1f + (levelManager.Level * .15f)); } // 80.00% -> 40.00% chaser key drop chance chaserKeyDropChance = .01f * (80f - (levelManager.Level * 2f)); // 40.00% -> 01.00% small key drop chance smallKeyDropChance = .01f * (40f - (levelManager.Level * 1.95f)); // 01.00% -> 00.50% life drop chance //lifeDropChance = .01f * (1f - (levelManager.Level * .025f)); } } // Maximum difficulty for everything except minimum number of asteroids // needed to enable key drop else { levelGoal = (int)((levelManager.Level - 1) * 1.3f) + 52; // These should be the permanent final values for the following: maxAsteroidCount = 30; minAsteroidSpawnTimer = .1f; maxAsteroidSpawnTimer = .3f; chaserSpawnChance = .04f; // 4.00% chaser spawn chance chaserKeyDropChance = .4f; // 40.00% chaser key drop chance smallKeyDropChance = .01f; // 01.00% small key drop chance //lifeDropChance = .005f; // 00.50% life drop chance } // Three seconds before first asteroid spawns asteroidTime = 3f; player.ResetBulletCooldown(); // Scale key keyScale = LevelManager.GetScaleSpriteToTileSize( doorKey.GetComponent <SpriteInfo>(), levelManager.UnitsPerSquare * .75f); doorKey.GetComponent <SpriteInfo>().Radius = levelManager.UnitsPerSquare * .75f; #region Scale Player // Resize the player & their bounds based upon the new size of the map if (player.SpriteInfo != null && levelManager.LeveHeight > 4) { playerToTileScale = levelManager.GetScaleSpriteToTileSize(player.SpriteInfo); playerToTileScale.x *= PlayerToTileSizeRatio; playerToTileScale.y *= PlayerToTileSizeRatio; if (player.SpriteInfo.Shape == SpriteInfo.BoundingShape.Box) { player.SpriteInfo.Radius = levelManager.UnitsPerSquare * ((playerToTileScale.x + playerToTileScale.y / 2) / 2); } else { player.SpriteInfo.Radius = levelManager.UnitsPerSquare * PlayerToTileSizeRatio; } player.transform.localScale = playerToTileScale; player.transform.position = levelManager.GetRandomSpawnLocation(); player.ForceAngle(Random.Range(0, 4) * 90); } #endregion #region Scale Bullet // Resize the bullets shot by the player if (player.bullet != null && player.bullet.GetComponent <SpriteInfo>() != null && levelManager.LeveHeight > 4) { playerToTileScale = levelManager.GetScaleSpriteToTileSize( player.bullet.GetComponent <SpriteInfo>()); playerToTileScale.x *= PlayerToTileSizeRatio * .35f; playerToTileScale.y *= PlayerToTileSizeRatio * .35f; player.BulletScale = playerToTileScale; player.bullet.GetComponent <SpriteInfo>().Radius = levelManager.UnitsPerSquare * PlayerToTileSizeRatio * .35f; } #endregion // Rescale the asteroids and their radii with the new map size AsteroidBehavior.RescaleAsteroids(levelManager.UnitsPerSquare); }
void ReturnAsteroid(GameObject gameObject, AsteroidBehavior asteroidBehavior) { gameObject.SetActive(false); _asteroidCount -= 1; }
void StruckAsteroid(GameObject gameObject, AsteroidBehavior asteroidBehavior) { OnAsteroidStruck.Invoke(gameObject); }