微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我正在尝试将坡道放入具有随机生成地形的基于瓷砖的游戏中

如何解决我正在尝试将坡道放入具有随机生成地形的基于瓷砖的游戏中

我在尝试将斜坡添加到我的游戏地图生成中时遇到了很多麻烦(代码如下所示)。我想检查地砖左侧(面向左侧的坡道)和上方和右侧(面向右侧)是否有空气,但我不知道该怎么做。

def generate_chunk(x,y):
    chunk_data = []
    for y_pos in range(CHUNK_SIZE):
        for x_pos in range(CHUNK_SIZE):
            target_x = x * CHUNK_SIZE + x_pos
            target_y = y * CHUNK_SIZE + y_pos
            tile_type = 0 # nothing
            if x == 0:
                height = 0

            else:
                height = int(noise.pnoise1(target_x * 0.1,repeat=9999999) * 3)

                #------------------------------------------.
                                  #dirt:
            if target_y == 8 - height - 3:
                if x == 0:
                    if target_x == 0:
                        tile_type = 12

            if target_y > 8 - height:
                if target_y < 10 - height:
                    if random.randint(1,2) == 1:
                        tile_type = 10
                    else:
                        tile_type = 7 # dirt
                elif target_y == 10 - height:
                    tile_type = 10
                elif target_y == 11 - height:
                    if random.randint(1,3) == 1:
                        tile_type = 11
                    else:
                        tile_type = 9
                else:
                    tile_type = 9
                #------------------------------------------.
                                  #grass:

            elif target_y == 8 - height:
                if random.randint(1,3) == 1 or 2:
                    tile_type = 1 # grass
                else:
                    tile_type = 6
                #------------------------------------------.
                                  #ramps:
                
                #for target_x in chunk data: if target_x has height and target_x+1 has height+1 then put a rightward ramp. 
                    #if target_x has height and target_x+1 has height-1 then put a leftward ramp. 
                        #if target_x has height and target_x+1 has height-1 and target_x+2 has height then put a middle ramp.


                #to check if a tile is going to be a ramp,check for air. if there is air above and to the left of a block,turn it into a ramp pointing right. whereas if it 
                #has air up and to the right,turn it into a ramp pointing left.
                    #check every chunk loading,and save it,but i will need to check while it is being made,how.. for tile in tiles?           
                #------------------------------------------.
                    #plants:

            elif target_y == 8 - height - 1 and x != 0:
                if random.randint(1,2) == 1:
                    if random.randint(1,4) == 2:
                        tile_type = 3 # plant
                    elif random.randint(1,5) == 1:
                        tile_type = 8
                    elif random.randint(1,4) == 3:
                        tile_type = 4 # plant3
                    elif random.randint(1,5) == 4:
                        tile_type = 5 # plant4
                else:
                    if random.randint(1,5) != 1:
                        tile_type = 4
            if tile_type != 0:
                chunk_data.append([[target_x,target_y],tile_type])
    return chunk_data

game_map = {}

我可以发布它的外观图片,但我不知道您是否需要。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。