示例#1
0
文件: Snake.cs 项目: giacomelli/Doog
        void EatFood()
        {
            var temp = tail;
            var next = tail.Next;

            tail = CreateTile(
                tail.Transform.Position.X + (tail.Transform.Position.X - next.Transform.Position.X),
                tail.Transform.Position.Y + (tail.Transform.Position.Y - next.Transform.Position.Y));

            tail.Next = temp;

            FoodsEatenCount++;

            if (FoodEaten != null)
            {
                FoodEaten(this, EventArgs.Empty);
            }

            if (speed < MaxSpeed)
            {
                speed += Acceleration;
            }

            Log.Debug("{0} foods eaten. New speed {1}", FoodsEatenCount, speed);
        }
示例#2
0
文件: Snake.cs 项目: giacomelli/Doog
        private SnakeTile CreateTile(float x, float y)
        {
            var tile = new SnakeTile(
                x,
                y,
                Context,
                EatFood,
                OnDied,
                OnDied);

            return(tile);
        }
示例#3
0
文件: Snake.cs 项目: giacomelli/Doog
        private void Deploy(float x, float y, int length)
        {
            if (length < 3)
            {
                throw new ArgumentException("length must be greater than 2", "length");
            }

            x += bounds.Left;
            y += bounds.Top;

            tail           = CreateTile(x++, y);
            tail.Next      = CreateTile(x++, y);
            Head           = CreateTile(x++, y);
            tail.Next.Next = Head;
            length        -= 3;

            for (int i = 0; i < length; i++, x++)
            {
                Head.Next = CreateTile(x, y);
                Head      = Head.Next;
            }
        }
示例#4
0
文件: Snake.cs 项目: giacomelli/Doog
        private void Move()
        {
            var hpos        = Head.Transform.Position.Round();
            var newPosition = Point.Lerp(
                hpos,
                new Point(hpos.X + movingDirectionX, hpos.Y + movingDirectionY),
                (Context.Time.SinceSceneStart - lastPositionChangeTime) * speed)
                              .Round();

            if (newPosition != hpos)
            {
                Head.Pixel = SnakeTile.BodyPixel;
                tail.Transform.Position = newPosition;
                Head.Next  = tail;
                Head       = tail;
                tail       = tail.Next;
                Head.Next  = null;
                Head.Pixel = SnakeTile.HeadPixel;

                lastPositionChangeTime = Context.Time.SinceSceneStart;
            }
        }