예제 #1
0
        /// <summary>
        /// Continuously spawn asteroids in the screen.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token that will stop the creation of asteroids.</param>
        /// <returns>The task that will create asteroids in the screen.</returns>
        async Task SpawnAsteroids(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                await UpdateContext.Delay(SpawnAsteroidsDelay, cancellationToken);

                SpawnAsteroid();
            }
        }
예제 #2
0
        public async Task <bool> FireSpecialWeapon(CancellationToken cancellation)
        {
            if (SpecialAttack == null || SpecialWeaponAmmo.IsEmpty)
            {
                return(false);
            }

            SpecialWeaponAmmo.Quantity--;
            SoundManager.PlaySound("Special03");
            await TaskEx.WhenAll(
                SpecialAttack(this),
                UpdateContext.Delay(SpecialWeaponDelay));

            return(true);
        }
예제 #3
0
        public async Task <bool> FireLaser(CancellationToken cancellation)
        {
            if (MainWeaponAmmo.IsEmpty)
            {
                return(false);
            }

            var direction = Vector2Extension.AngleToVector2(Rotation);

            var laser = new Laser(this, Momentum, Position, direction);

            laser.ApplyAcceleration(direction * laser.MaxSpeed, instantaneous: true);
            ApplyForce(-direction * laser.Mass, instantaneous: true);

            MainWeaponAmmo.Quantity--;
            SoundManager.PlaySound("Shoot01");
            Level.AddEntity(laser);

            await UpdateContext.Delay(MainWeaponDelay);

            return(true);
        }