Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XNA蛇类游戏中的奇怪动作_C#_Xna - Fatal编程技术网

C# XNA蛇类游戏中的奇怪动作

C# XNA蛇类游戏中的奇怪动作,c#,xna,C#,Xna,我一直在尝试在XNA中制作一个蛇游戏,但我遇到了一个导致蛇变得一团糟的bug 正如你所看到的,每当我拿起一个“点”时,每一条新产生的蛇都会稍微移到原始蛇的一边 游戏开始时,蛇只由这些立方体中的一个组成 下面是生成蛇的新片段的代码 private void PointCollision() { if (snake[0].getRect().Intersects(pointRectangle)) { point.position = PointPosition();

我一直在尝试在XNA中制作一个蛇游戏,但我遇到了一个导致蛇变得一团糟的bug

正如你所看到的,每当我拿起一个“点”时,每一条新产生的蛇都会稍微移到原始蛇的一边

游戏开始时,蛇只由这些立方体中的一个组成

下面是生成蛇的新片段的代码

private void PointCollision()
{
    if (snake[0].getRect().Intersects(pointRectangle))
    {
        point.position = PointPosition();
        pointRectangle = new Rectangle(
                            (int)point.position.X, 
                            (int)point.position.Y, 
                            point.texture.Width, 
                            point.texture.Height);

        score++;

        if (xVel < 0)
            snake.Add(
                new Player(snakeTexture, 
                            new Vector2(snake[snake.Count - 1].position.X + 20, 
                            snake[snake.Count - 1].position.Y), 
                            new Vector2(xVel, yVel)));

        if (xVel > 0)
            snake.Add(new Player(snakeTexture, 
                                    new Vector2(snake[snake.Count - 1].position.X - 20, 
                                    snake[snake.Count - 1].position.Y), 
                                    new Vector2(xVel, yVel)));

        if (yVel < 0)
            snake.Add(new Player(snakeTexture, 
                                    new Vector2(snake[snake.Count - 1].position.X, 
                                    snake[snake.Count - 1].position.Y + 20), 
                                    new Vector2(xVel, yVel)));

        if (yVel > 0)
            snake.Add(new Player(snakeTexture, 
                                    new Vector2(snake[snake.Count - 1].position.X, 
                                    snake[snake.Count - 1].position.Y - 20), 
                                    new Vector2(xVel, yVel)));
    }
}
private void PointCollision()
{
if(snake[0].getRect().Intersects(pointRectangle))
{
point.position=PointPosition();
pointRectangle=新矩形(
(int)点位置X,
(int)点位置Y,
point.texture.Width,
点、纹理、高度);
分数++;
如果(xVel<0)
蛇。加上(
新玩家(蛇纹,
新矢量2(snake[snake.Count-1]。位置.X+20,
snake[snake.Count-1].位置.Y),
新矢量2(xVel,yVel));
如果(xVel>0)
添加(新玩家(蛇纹,
新矢量2(snake[snake.Count-1]),位置.X-20,
snake[snake.Count-1].位置.Y),
新矢量2(xVel,yVel));
if(yVel<0)
添加(新玩家(蛇纹,
新矢量2(snake[snake.Count-1]。位置.X,
snake[snake.Count-1].位置.Y+20),
新矢量2(xVel,yVel));
如果(yVel>0)
添加(新玩家(蛇纹,
新矢量2(snake[snake.Count-1]。位置.X,
snake[snake.Count-1].位置.Y-20),
新矢量2(xVel,yVel));
}
}

是什么导致了这种奇怪的行为?

什么是
xVel
yVel
?花车?另外,网格的尺寸是多少?是否有将纹理位置捕捉到栅格的代码?