Exemplo 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="frameSizePix">Size of frameIndex in pix.</param>
 /// <param name="isHorizDir">Is animation order is horizontal on sprite map</param>
 public Sprite(Uri mapPath, DirectionPoint framePosition, Size frameSizePix, bool isHorizDir)
 {
     _spritemapPath = mapPath;
     _framePosition = framePosition;
     _frameSizePix  = frameSizePix;
     _isHorizDir    = isHorizDir;
 }
Exemplo n.º 2
0
 public Snake(DirectionPoint tongue, DirectionPoint head, DirectionPoint tail)
 {
     _tongue = tongue;
     _head   = head;
     _tail   = tail;
     _body   = new List <DirectionPoint>();
 }
Exemplo n.º 3
0
 public Snake(DirectionPoint tongue, DirectionPoint head, DirectionPoint tail, List <DirectionPoint> body)
 {
     _tongue = tongue;
     _head   = head;
     _tail   = tail;
     _body   = body;
 }
Exemplo n.º 4
0
 public Snake()
 {
     _tongue = new DirectionPoint(1, 0);
     _head   = new DirectionPoint(0, 0);
     _tail   = new DirectionPoint(-1, 0);
     _body   = new List <DirectionPoint>();
 }
Exemplo n.º 5
0
        public Rendering(DirectionPoint tongue, DirectionPoint head, DirectionPoint tail, Uri spriteMapUrl)
        {
            Image img = new Image();

            //_snake = snake;
            Tongue     = tongue;
            Head       = head;
            Tail       = tail;
            BodyPoints = new List <DirectionPoint>();
            //Tongue
            _spriteTongue = new Sprite(spriteMapUrl,
                                       new DirectionPoint(0, 96), // Top left coords
                                       new Size(16, 16),          // Frame size
                                       true);                     // Horizontal animation
            // Head
            _spriteHead = new Sprite(spriteMapUrl,
                                     new DirectionPoint(0, 32), // Top left coords
                                     new Size(16, 16),          // Frame size
                                     true);                     // Horizontal animation
            // Body
            _spriteBody = new Sprite(spriteMapUrl,
                                     new DirectionPoint(0, 0),        // Top left coords
                                     new Size(16, 16),                // Frame size
                                     true);                           // Horizontal animation
            _spriteBodyRotate = new Sprite(spriteMapUrl,
                                           new DirectionPoint(0, 16), // Top left coords
                                           new Size(16, 16),          // Frame size
                                           true);                     // Horizontal animation
            // Tail
            _spriteTail = new Sprite(spriteMapUrl,
                                     new DirectionPoint(0, 48), // Top left coords
                                     new Size(16, 16),          // Frame size
                                     true);                     // Horizontal animation
        }
Exemplo n.º 6
0
        public void AddBodyPointToEnd()
        {
            // Copy last point
            var newPoint = new DirectionPoint();

            newPoint.X         = _body.Last <DirectionPoint>().X;
            newPoint.Y         = _body.Last <DirectionPoint>().Y;
            newPoint.Direction = _body.Last <DirectionPoint>().Direction;
            // And add to the end
            _body.Add(newPoint);
        }
Exemplo n.º 7
0
        public Rendering(DirectionPoint tongue, DirectionPoint head, DirectionPoint tail, List <DirectionPoint> body,
                         Sprite tongueSprite, Sprite headSprite, Sprite bodySprite, Sprite bodyRotateSprite, Sprite tailSprite)
        {
            Image img = new Image();

            //_snake = snake;
            Tongue     = tongue;
            Head       = head;
            Tail       = tail;
            BodyPoints = body;
            //Tongue
            _spriteTongue = tongueSprite;
            // Head
            _spriteHead = headSprite;
            // Body
            _spriteBody       = bodySprite;
            _spriteBodyRotate = bodyRotateSprite;
            // Tail
            _spriteTail = tailSprite;
        }
Exemplo n.º 8
0
        public void Move(int distance, Size field, Size headSize)
        {
            var tempPoint = new DirectionPoint();

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