Пример #1
0
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            var top  = Canvas.GetTop(this);
            var left = Canvas.GetLeft(this);

            switch (_direction)
            {
            case Direction.Down:
                Canvas.SetTop(SpriteSheet, 0);
                Canvas.SetTop(this, top + _movementSpeed);
                break;

            case Direction.Left:
                Canvas.SetTop(SpriteSheet, -48);
                Canvas.SetLeft(this, left - _movementSpeed);
                break;

            case Direction.Right:
                Canvas.SetTop(SpriteSheet, -96);
                Canvas.SetLeft(this, left + _movementSpeed);
                break;

            case Direction.Up:
                Canvas.SetTop(SpriteSheet, -144);
                Canvas.SetTop(this, top - _movementSpeed);
                break;
            }
            Canvas.SetLeft(SpriteSheet, DirectionControl.NextFrame());
        }
Пример #2
0
 public void Move(Key k)
 {
     currentKey = k;
     _direction = DirectionControl.GetDirection(k);
     DirectionControl.SetKeyDown(_direction);
     _timer.Start();
 }
Пример #3
0
        internal void Stop(Key k)
        {
            var key = DirectionControl.GetDirection(k);

            DirectionControl.StopKeyPress(key);

            if (DirectionControl.AllKeysLifted())
            {
                _timer.Stop();
            }
        }