Esempio n. 1
0
 /// <summary>
 /// Create animated sprite from sprite map
 /// </summary>
 /// <param name="mapPath">Path to sprite map</param>
 /// <param name="framePosition">X,Y coordinates of first frame</param>
 /// <param name="framesAnimation">Array with indexes of frames animation order</param>
 /// <param name="frameSizePix">Size of frameIndex in pix.</param>
 /// <param name="speed">Animation speed</param>
 /// <param name="isHorizDir">Is animation order is horizontal on sprite map</param>
 /// <param name="repeat">If false, animation have one cycle</param>
 public Sprite(Uri mapPath, DirPoint framePosition, int[] framesAnimation, Size frameSizePix, int speed, bool isHorizDir, bool repeat)
 {
     _index           = 0;
     _spritemapPath   = mapPath;
     _framePosition   = framePosition;
     _framesAnimation = framesAnimation;
     _frameSizePix    = frameSizePix;
     _speed           = speed;
     _isHorizDir      = isHorizDir;
     _repeat          = repeat;
 }
Esempio n. 2
0
        public void AddBodyPointToEnd()
        {
            // Copy last point
            var newPoint = new DirPoint();

            newPoint.X         = _body.Last <DirPoint>().X;
            newPoint.Y         = _body.Last <DirPoint>().Y;
            newPoint.Direction = _body.Last <DirPoint>().Direction;
            // And add to the end
            _body.Add(newPoint);
        }
Esempio n. 3
0
        public DrawableSnake(DirPoint head, DirPoint tail, List <DirPoint> body,
                             Sprite headSprite, Sprite bodySprite, Sprite bodyRotateSprite, Sprite tailSprite)
        {
            Image img = new Image();

            //_snake = snake;
            Head       = head;
            Tail       = tail;
            BodyPoints = body;
            // Head
            _spriteHead = headSprite;
            // Body
            _spriteBody       = bodySprite;
            _spriteBodyRotate = bodyRotateSprite;
            // Tail
            _spriteTail = tailSprite;
        }
Esempio n. 4
0
        public DrawableSnake(DirPoint head, DirPoint tail, Uri spriteMapUrl,
                             int animationSpeed = 1)
        {
            Image img = new Image();

            //_snake = snake;
            Head       = head;
            Tail       = tail;
            BodyPoints = new List <DirPoint>();
            // Head
            _spriteHead = new Sprite(spriteMapUrl,
                                     new DirPoint(1, 35),         // Top left coords
                                     new int[] { 0, 1, 2, 1, 0 }, // Animation
                                     new Size(16, 16),            // Frame size
                                     animationSpeed,              // Speed
                                     true,                        // Horizontal animation
                                     true);                       // Repeat
            // Body
            _spriteBody = new Sprite(spriteMapUrl,
                                     new DirPoint(1, 1),          // Top left coords
                                     new int[] { 0, 1, 2, 1, 0 }, // Animation
                                     new Size(16, 16),            // Frame size
                                     animationSpeed,              // Speed
                                     true,                        // Horizontal animation
                                     true);                       // Repeat
            _spriteBodyRotate = new Sprite(spriteMapUrl,
                                           new DirPoint(1, 18),   // Top left coords
                                           new int[] { 0 },       // Animation
                                           new Size(16, 16),      // Frame size
                                           animationSpeed,        // Speed
                                           true,                  // Horizontal animation
                                           true);                 // Repeat
            // Tail
            _spriteTail = new Sprite(spriteMapUrl,
                                     new DirPoint(1, 52),         // Top left coords
                                     new int[] { 0, 1, 2, 1, 0 }, // Animation
                                     new Size(16, 16),            // Frame size
                                     animationSpeed,              // Speed
                                     true,                        // Horizontal animation
                                     true);                       // Repeat
        }
Esempio n. 5
0
        public void Move(int distance, Size field, Size headSize)
        {
            var tempPoint = new DirPoint();

            tempPoint.X         = _head.X;
            tempPoint.Y         = _head.Y;
            tempPoint.Direction = _head.Direction;
            if (_body[0].Direction != _head.Direction)
            {
                switch (_body[0].Direction)
                {
                case SnakeDirection.UP_TO_RIGHT:
                case SnakeDirection.DOWN_TO_RIGHT:
                case SnakeDirection.RIGHT:
                    if (tempPoint.Direction == SnakeDirection.UP)
                    {
                        tempPoint.Direction = SnakeDirection.RIGHT_TO_UP;
                    }
                    else if (tempPoint.Direction == SnakeDirection.RIGHT)
                    {
                        tempPoint.Direction = SnakeDirection.RIGHT;
                    }
                    else
                    {
                        tempPoint.Direction = SnakeDirection.RIGHT_TO_DOWN;
                    }
                    break;

                case SnakeDirection.LEFT_TO_DOWN:
                case SnakeDirection.RIGHT_TO_DOWN:
                case SnakeDirection.DOWN:
                    if (tempPoint.Direction == SnakeDirection.LEFT)
                    {
                        tempPoint.Direction = SnakeDirection.DOWN_TO_LEFT;
                    }
                    else if (tempPoint.Direction == SnakeDirection.DOWN)
                    {
                        tempPoint.Direction = SnakeDirection.DOWN;
                    }
                    else
                    {
                        tempPoint.Direction = SnakeDirection.DOWN_TO_RIGHT;
                    }
                    break;

                case SnakeDirection.UP_TO_LEFT:
                case SnakeDirection.DOWN_TO_LEFT:
                case SnakeDirection.LEFT:
                    if (tempPoint.Direction == SnakeDirection.UP)
                    {
                        tempPoint.Direction = SnakeDirection.LEFT_TO_UP;
                    }
                    else if (tempPoint.Direction == SnakeDirection.LEFT)
                    {
                        tempPoint.Direction = SnakeDirection.LEFT;
                    }
                    else
                    {
                        tempPoint.Direction = SnakeDirection.LEFT_TO_DOWN;
                    }
                    break;

                case SnakeDirection.LEFT_TO_UP:
                case SnakeDirection.RIGHT_TO_UP:
                case SnakeDirection.UP:
                    if (tempPoint.Direction == SnakeDirection.LEFT)
                    {
                        tempPoint.Direction = SnakeDirection.UP_TO_LEFT;
                    }
                    else if (tempPoint.Direction == SnakeDirection.UP)
                    {
                        tempPoint.Direction = SnakeDirection.UP;
                    }
                    else
                    {
                        tempPoint.Direction = SnakeDirection.UP_TO_RIGHT;
                    }
                    break;

                default:
                    break;
                }
            }
            _tail = _body.Last <DirPoint>(); // Tail = last body point
            switch (_tail.Direction)
            {
            case SnakeDirection.UP_TO_LEFT:
            case SnakeDirection.DOWN_TO_LEFT:
                _tail.Direction = SnakeDirection.LEFT;                      // Pre-last point direction
                break;

            case SnakeDirection.UP_TO_RIGHT:
            case SnakeDirection.DOWN_TO_RIGHT:
                _tail.Direction = SnakeDirection.RIGHT;                      // Pre-last point direction
                break;

            case SnakeDirection.RIGHT_TO_UP:
            case SnakeDirection.LEFT_TO_UP:
                _tail.Direction = SnakeDirection.UP;
                break;

            case SnakeDirection.LEFT_TO_DOWN:
            case SnakeDirection.RIGHT_TO_DOWN:
                _tail.Direction = SnakeDirection.DOWN;
                break;

            default:
                /*
                 * if (_body.Count < 2)
                 * {
                 *  _tail.Direction = _head.Direction;                  // Pre-last point direction
                 * }
                 * else
                 * {
                 *  _tail.Direction = _body[_body.Count - 2].Direction; // Pre-last point direction
                 * }
                 */
                break;
            }
            _body.RemoveAt(_body.Count - 1);            // Remove last
            _body.Insert(0, tempPoint);                 // Old head position = first body point
            // Make new head
            switch (_head.Direction)
            {
            case SnakeDirection.UP:
                _head.Y -= distance;
                if (_head.Y < 0)
                {
                    _head.Y = field.Height;
                }
                break;

            case SnakeDirection.RIGHT:
                _head.X += distance;
                if (_head.X > field.Width)
                {
                    _head.X = 0;
                }
                break;

            case SnakeDirection.DOWN:
                _head.Y += distance;
                if (_head.Y > field.Height)
                {
                    _head.Y = 0;
                }
                break;

            case SnakeDirection.LEFT:
                _head.X -= distance;
                if (_head.X < 0)
                {
                    _head.X = field.Width;
                }
                break;

            default:
                break;
            }
        }
Esempio n. 6
0
 public Snake(DirPoint head, DirPoint tail)
 {
     _head = head;
     _tail = tail;
     _body = new List <DirPoint>();
 }
Esempio n. 7
0
 public Snake(DirPoint head, DirPoint tail, List <DirPoint> body)
 {
     _head = head;
     _tail = tail;
     _body = body;
 }
Esempio n. 8
0
 public Snake()
 {
     _head = new DirPoint(0, 0);
     _tail = new DirPoint(-1, 0);
     _body = new List <DirPoint>();
 }