/// <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(); } }
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); }
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); }