i have been having a lot of trouble with trying to add ramps into my game map generation(code as seen below), i want to check for air up and to the left of a ground tile (for leftward facing ramp) and up and right(for rightward) but im not sure how i should do that. i would appreciate any help.. this has been bugging me for some time now and i havent found anyone who is actually able to help me, and all the videos ive seen dont help. thanks!(:
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 = {}
i can post pictures of what it looks like but i dont know if you need that or not.
https://stackoverflow.com/questions/66927146/i-am-trying-to-put-ramps-into-a-tile-based-game-with-randomly-generated-terrain April 03, 2021 at 10:06AM
没有评论:
发表评论