Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.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# I';m创建重叠的地形,而它不是';我不应该_C#_Class_Random_Monogame - Fatal编程技术网

C# I';m创建重叠的地形,而它不是';我不应该

C# I';m创建重叠的地形,而它不是';我不应该,c#,class,random,monogame,C#,Class,Random,Monogame,我正在用程序生成的岛屿作为地形,在单游戏中创建一个简单的平台。我有4个重要的课程:AllIslands、Islands、Ground和GroundBlock。AllIslands是一个管理岛屿并使其按程序生成的类。Islands是使岛具有随机长度和位置的类。Ground是管理和创建接地块行的类我试图生成岛,岛与岛之间有空间,为此,我使用变量RightXOfLastIsland,该变量包含岛的最右边的X值。我看了看右边的Xoflastisland,然后在上面随机添加一个数字,以显示新岛屿的位置。我

我正在用程序生成的岛屿作为地形,在单游戏中创建一个简单的平台。我有4个重要的课程:AllIslands、Islands、Ground和GroundBlock。AllIslands是一个管理岛屿并使其按程序生成的类。Islands是使岛具有随机长度和位置的类。Ground是管理和创建接地块行的类

我试图生成岛,岛与岛之间有空间,为此,我使用变量RightXOfLastIsland,该变量包含岛的最右边的X值。我看了看右边的Xoflastisland,然后在上面随机添加一个数字,以显示新岛屿的位置。我的问题是岛屿重叠,我不知道为什么

class AllIslands
{
    public List<Island> ListOfIslands = new List<Island>(0);
    public int RightXOfLastIsland = 0;

    public AllIslands()
    {

    }

    public void CreateIsland(Ground ground)
    {
        if (ListOfIslands.Count > 0)
        {
            Island previousIsland = ListOfIslands[ListOfIslands.Count - 1];
            RightXOfLastIsland = previousIsland.RightXOfLastIsland;
        }
        Island island = new Island(ground, RightXOfLastIsland);
        ListOfIslands.Add(island);
    }
    public void ProcedurallySpawnIslands(Player player, Ground ground)
    {
        if (player.Position.X > RightXOfLastIsland - 200)
        {
            CreateIsland(ground);
        }
    }
}

class Island
{
    public int RightXOfLastIsland;

    public Island(Ground ground, int rightXOfLastIsland)
    {
        RightXOfLastIsland = rightXOfLastIsland;

        Random random = new Random();

        int tempRightX = RightXOfLastIsland / 100;

        int locationX = random.Next(tempRightX + 5, tempRightX + 10);
        int locationY = random.Next(5, 9);
        int lengthRowOfBlocks = random.Next(5, 10);

        Vector2 location = new Vector2(locationX * 100, locationY * 100);

        ground.CreateGroundBlocks(location, lengthRowOfBlocks);

        RightXOfLastIsland = RightXOfLastIsland + (lengthRowOfBlocks * 100);
    }
}
class AllIslands
{
public List listofilands=新列表(0);
public int RightXOfLastIsland=0;
大蒜素
{
}
公共岛(地面)
{
如果(listofilands.Count>0)
{
Island previousIsland=listofilands[listofilands.Count-1];
RightXOfLastIsland=previousIsland.RightXOfLastIsland;
}
岛屿=新岛屿(地面,右侧为Flastisland);
添加(岛);
}
公共作废程序Pawnislands(玩家,地面)
{
如果(player.Position.X>RightXOfLastIsland-200)
{
岛屿(地面);
}
}
}
阶级岛
{
Flastisland的公共权利;
公共岛(地上,内陆)
{
RightXOfLastIsland=RightXOfLastIsland;
随机=新随机();
int tempRightX=RightXOfLastIsland/100;
int locationX=random.Next(tempRightX+5,tempRightX+10);
int locationY=random.Next(5,9);
int lengthrowoblocks=random.Next(5,10);
矢量2位置=新矢量2(位置X*100,位置Y*100);
接地。创建接地块(位置、长接地块);
RightXOfLastIsland=RightXOfLastIsland+(lengthRowOfBlocks*100);
}
}

Vector2位置包含新生成岛屿的LeftX的x值,对吗?如果是这样的话,除了上一个值和块的长度之外,您没有将其值添加到最后一行的RightXOfLastIsland中吗?你有没有试过在一张纸上绘制/绘图?Vector2位置包含新生成岛屿的LeftX的x值,对吗?如果是这样的话,除了上一个值和块的长度之外,您没有将其值添加到最后一行的RightXOfLastIsland中吗?你试过在一张纸上画这个吗?