コード例 #1
0
        public override void Draw(GameTime gameTime)
        {
            _elapsedSinceLastAnimationChange += gameTime.ElapsedGameTime;
            if (_elapsedSinceLastAnimationChange > (_inAttackAnimation ? AttackAnimationStepTime : _animationStepTime))
            {
                _elapsedSinceLastAnimationChange = TimeSpan.Zero;
                _currentAnimationStepIndex++;
                if (_currentAnimationStepIndex == _animationStepCount)
                {
                    _currentAnimationStepIndex = 0;
                    if (_inAttackAnimation)
                    {
                        DealDamage?.Invoke(this);
                    }
                    _inAttackAnimation = false;
                }
            }

            var source = new Rectangle(_currentAnimationStepIndex * _spriteWidth,
                                       (_animationIndex + (_inAttackAnimation ? 4 : 0)) * _spriteHeight,
                                       _spriteWidth, _spriteHeight);

            ((Game1)Game).SpriteBatch.Draw(_sprite, Position - new Vector2(_spriteWidth / 2f, _spriteHeight / 2f),
                                           source, _color);

            base.Draw(gameTime);
        }
コード例 #2
0
ファイル: Enemy.cs プロジェクト: carnwyr/Tower-Defense
 private IEnumerator Attack()
 {
     while (true)
     {
         DealDamage?.Invoke(_damage);
         yield return new WaitForSeconds(_attackCooldown);
     }
 }
コード例 #3
0
 public void OnTick(int tick)
 {
     DealDamage?.Invoke(Description, SpellCastIndex, DPS);
 }