public void Start() { _lifetimeCounter = SFX_DURATION_SECONDS; _animationBlocker = new TimeLimitedAnimationBlocker(); _animationBlockerService.AddBlocker(_animationBlocker); }
private void FinishHitAnimation() { if (_hitAnimationBlocker != null) { _hitAnimationBlocker.Release(); _hitAnimationBlocker = null; } }
public virtual void ProcessHit(Vector3 targetPosition) { if (_hitAnimationBlocker is null) { _hitAnimationBlocker = new TimeLimitedAnimationBlocker(); _animationBlockerService.AddBlocker(_hitAnimationBlocker); } PlayHit(); RotateTo(targetPosition); }
public ActorCommonActionMoveEngine(SpriteContainer rootContainer, IAnimationBlockerService animationBlockerService, SoundEffectInstance?soundEffect) { _rootContainer = rootContainer; _soundEffect = soundEffect; _startPosition = rootContainer.Position; _targetPosition = _startPosition + (Vector2.UnitY * -10); _animationBlocker = new AnimationCommonBlocker(); animationBlockerService.AddBlocker(_animationBlocker); }
public ActorMeleeAttackEngine(SpriteContainer rootContainer, Vector2 targetPosition, IAnimationBlockerService animationBlockerService, SoundEffectInstance?meleeAttackSoundEffect) { _rootContainer = rootContainer; _animationBlockerService = animationBlockerService; _meleeAttackSoundEffect = meleeAttackSoundEffect; _startPosition = rootContainer.Position; _targetPosition = Vector2.Lerp(_startPosition, targetPosition, 0.6f); _animationBlocker = new AnimationCommonBlocker(); _animationBlockerService.AddBlocker(_animationBlocker); _rootContainer.FlipX = (_startPosition - _targetPosition).X < 0; }
/// <inheritdoc /> public void AddBlocker(ICommandBlocker commandBlocker) { _semaphore.Wait(SEMAPHORE_WAIT_TIMEOUT_MILLISECONDS); commandBlocker.Released += CommandBlocker_Release; _commandBlockers.TryAdd(commandBlocker, 0); if (_tcs is null) { // Use TaskCreationOptions.RunContinuationsAsynchronously to prevent deadlocks. // This is best practice if there are no strong reason to avoid it option. // https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md#always-create-taskcompletionsourcet-with-taskcreationoptionsruncontinuationsasynchronously _tcs = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); } _semaphore.Release(); }
public ActorDamagedEngine(IActorGraphics actorGraphics, SpriteContainer rootSprite, Vector2 attackerPosition, IAnimationBlockerService animationBlockerService, SoundEffectInstance?soundEffectInstance) { _actorGraphics = actorGraphics; _rootSprite = rootSprite; _soundEffectInstance = soundEffectInstance; var positionDifference = attackerPosition - actorGraphics.RootSprite.Position; var hitDirection = positionDifference; hitDirection.Normalize(); _rootSprite.FlipX = hitDirection.X > 0; _startPosition = rootSprite.Position; var oppositeDirection = hitDirection * -1; _hitPosition = (oppositeDirection * HIT_DISTANCE) + _startPosition; _moveBlocker = new AnimationCommonBlocker(); animationBlockerService.AddBlocker(_moveBlocker); }
public ActorSectorTransitionMoveEngine(SpriteContainer rootContainer, IAnimationBlockerService animationBlockerService, SoundEffectInstance?transitionSoundEffect) { _rootContainer = rootContainer; _soundEffect = transitionSoundEffect; _startPosition = rootContainer.Position; _targetPosition = _startPosition + (Vector2.UnitY * -10); if (transitionSoundEffect != null) { _animationBlocker = new SoundAnimationBlocker(transitionSoundEffect); } else { _animationBlocker = new AnimationCommonBlocker(); } animationBlockerService.AddBlocker(_animationBlocker); }
public ActorPushEngine(SpriteContainer rootSprite, SpriteContainer graphicsRoot, Sprite shadowSprite, Vector2 targetPosition, IAnimationBlockerService animationBlockerService, SoundEffectInstance?soundEffectInstance) { _rootSprite = rootSprite; _graphicsRoot = graphicsRoot; _shadowSprite = shadowSprite; _startPosition = rootSprite.Position; _targetPosition = targetPosition; _animationBlockerService = animationBlockerService; _soundEffectInstance = soundEffectInstance; if (soundEffectInstance != null) { _moveBlocker = new SoundAnimationBlocker(soundEffectInstance); } else { _moveBlocker = new AnimationCommonBlocker(); } _animationBlockerService.AddBlocker(_moveBlocker); }