/// <summary>
        /// Attempt to fire a bullet
        /// </summary>
        protected void Shoot()
        {
            // Check that enough time has passed for another shot
            if (_timer.ElapsedMilliseconds > _fireDelay)
            {
                // Restart shot timer
                _timer.Restart();

                // Create new bullet
                Bullet bullet = Instantiate(
                    new Bullet(
                        GlobalPosition,
                        RotationAngle, (1, 1), ActorID.ENEMY_BULLET)) as Bullet;
                bullet.Speed = 200;

                // Set the bullet's collider
                if (bullet._colliders.Count > 0)
                {
                    if (bullet._colliders[0] is CircleCollider)
                    {
                        CircleCollider collider = bullet._colliders[0] as CircleCollider;
                        collider.Radius = 10;
                    }
                }
            }
        }
Beispiel #2
0
        // Checks collision against another collider
        public override bool IsCollided(Collider collidedActor)
        {
            // Check if other collider is also a circle
            if (collidedActor is CircleCollider)
            {
                // Cast to CircleCollider
                CircleCollider other = collidedActor as CircleCollider;

                // If the two colliders are intersecting, return true
                if ((other.GlobalPosition - GlobalPosition).Magnitude <= other.Radius + Radius)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                // Throw error if another collider type is used, as it has not been implemented
                throw new NotImplementedException();
            }
        }