Ejemplo n.º 1
0
        public void MoveSL()
        {
            if (NewDirection == SnakeUtils.Directions.Stop)
            {
                return;
            }

            if (_isNewTurn == true)
            {
                base.ChangeDirection();
                //if (!directionChanged && _keyBuffer.Count > 0)
                //    _keyBuffer.Clear();
                _UpdateKeyBuffer();
                _isNewTurn = false;

                ImminentCollision = base.CollisionImminent();
            }


            if (ImminentCollision != SnakeUtils.Collision.Wall && ImminentCollision != SnakeUtils.Collision.Object && ImminentCollision != SnakeUtils.Collision.Tail)
            {
                SnakeUtils.MoveSLPosition(OldDirection, ref _pos, 1.0);
                foreach (SLTail tail in TailList)
                {
                    tail.SLMoveTail(TailList);
                }
            }


            _tileCount++;

            if (_tileCount >= CurLevel.TileSize)
            {
                base.Move();
                SnakeUtils.SetZIndex(CurLevel, this, TailList);

                _isNewTurn = true;
                _tileCount = 0;
            }

            if (Animated)
            {
                int frameNo   = (_tileCount / CurLevel.Animation.AnimationDelay) % CurLevel.Animation.AnimationFrames;
                int frameColl = (_tileCount / CurLevel.Animation.CollisionDelay) % CurLevel.Animation.CollisionFrames;
                SnakeImage.Visibility = Visibility.Collapsed;
                if (ImminentCollision != SnakeUtils.Collision.Wall && ImminentCollision != SnakeUtils.Collision.Object && ImminentCollision != SnakeUtils.Collision.Tail)
                {
                    if (!CurLevel.IsControlInversed)
                    {
                        SnakeImage = BufferedImage[frameNo, ((int)this.OldDirection - 1)];
                    }
                    else
                    {
                        switch (this.OldDirection)
                        {
                        case SnakeUtils.Directions.Up: SnakeImage = BufferedImage[frameNo, 2]; break;

                        case SnakeUtils.Directions.Right: SnakeImage = BufferedImage[frameNo, 3]; break;

                        case SnakeUtils.Directions.Down: SnakeImage = BufferedImage[frameNo, 0]; break;

                        case SnakeUtils.Directions.Left: SnakeImage = BufferedImage[frameNo, 1]; break;
                        }
                    }


                    foreach (SLTail tail in TailList)
                    {
                        tail.Animate(_tileCount);
                    }
                }
                else
                {
                    //Add here Collision Animation, e.g. when hitting an object
                    SnakeImage = BufferedCollisionImage[frameColl, ((int)this.OldDirection - 1)];
                }
                SnakeImage.Visibility = Visibility.Visible;
            }
            else
            {
                if (ImminentCollision == SnakeUtils.Collision.Wall || ImminentCollision == SnakeUtils.Collision.Object || ImminentCollision == SnakeUtils.Collision.Tail)
                {
                    SnakeImage.Visibility = Visibility.Collapsed;
                    SnakeImage            = SnakeUtils.LoadImage("NutsTheme/collision_3_1");
                    CurLevel.LevelCanvas.Children.Add(SnakeImage);
                    SnakeImage.Visibility = Visibility.Visible;
                }
            }
        }
Ejemplo n.º 2
0
 public void SLMoveTail(LinkedList <Tail> tailList)
 {
     SnakeUtils.MoveSLPosition(_oldDirection, ref _pos, 1.0);
 }