//TODO: In an asteroid-asteroid collision, this function is being called from both asteroids, and should just be the one getting hit. private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.GetComponent <Asteroid>() is Asteroid) { Asteroid asteroidHit = collision.gameObject.GetComponent <Asteroid>(); asteroidHit.impactVelocity = impactVelocity; color = asteroidHit.color; asteroidHit.OnHit(); } else if (collision.gameObject.GetComponent <PShip>() is PShip) // TODO: These should take advantage of ShipBase polymorphism. { Debug.LogError("PLAYER COLLISION"); PShip _player = collision.gameObject.GetComponent <PShip>(); state = AsteroidState.Enemy; color = _player.renderer.material.color; rend.material.SetColor("_Color", color); } else if (collision.gameObject.GetComponent <EShip>() is EShip) { EShip _enemy = collision.gameObject.GetComponent <EShip>(); state = AsteroidState.Enemy; color = _enemy.renderer.material.color; rend.material.SetColor("_Color", color); } }
IEnumerator Cooldown() { state = AsteroidState.CoolingDown; OnChangedState (); yield return new WaitForSeconds(asteroidCooldownTime); state = AsteroidState.Friendly; OnChangedState (); }
//Makes the rock shape by making its polypath public Asteroids(PointF pos, AsteroidState _as, double sizechange = 0) : base(pos) { //Gives a random number of sides from 6 - 12, and a 25% radius variance _splitratio = (sizechange * 10.0) / 100.0; _modelGraphicsPath = MakePolyPath(_cfRadius * _splitratio, _random.Next(6, 13), 0.25); _dXSpeed = (float)(_random.NextDouble() * 3 - 1.5); _dYSpeed = (float)(_random.NextDouble() * 3 - 1.5); asteroidrockstate = _as; }
// Use this for initialization void Start() { sprite = GetComponentInChildren<SpriteRenderer> ();//GetComponent<SpriteRenderer> (); sprite.color = startColor; state = AsteroidState.Asteroid; animator = GetComponent<Animator> (); audioSrc = GetComponent<AudioSource> (); }