-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile_map_perlin_functions.py
52 lines (41 loc) · 1.72 KB
/
tile_map_perlin_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Contains tile_map generation using perlin noise"""
from random import randint
import pygame
from global_vars import *
from perlin_noise_generation import *
from tile_map_functions import *
def create_tiles_with_coloring(
) -> tuple[
dict[int,tuple[tuple[int,int],int,pygame.Color]], # tile_map
list[tuple[tuple[pygame.Vector2, pygame.Vector2], float]], # vector_list
]:
tile_map = create_tiles(False)
vector_list = create_initial_vectors()
color_tiles_using_vectors_before_tile_creation(tile_map,vector_list)
check_water_or_land_with_color(tile_map)
check_surrounding_tiles(tile_map)
return (tile_map,vector_list)
def check_water_or_land_with_color(tile_map: dict[int, tuple[tuple[int, int], int, pygame.Color]]):
if tile_map:
LAND_CHANCE_RGB_R_INT = convert_percentage_to_rgb_r_int()
for tile_id, tile in tile_map.items():
position = tile[0]
color = tile[2]
# print("Color:",pygame.Color(color))
# print("4D:",pygame.Color("#4D4D4D").r)
if pygame.Color(color).r < LAND_CHANCE_RGB_R_INT:
new_tile_type = 1
else:
new_tile_type = 0
tile = (position,int(new_tile_type),color)
tile_map.update({tile_id:tile})
def convert_percentage_to_rgb_r_int():
MAX = 16*9+9 # "#999999".r
return int((LAND_CHANCE_PERCENT_INT)/100 * MAX)
def update_vector_gen_tiles(
tile_map: dict[int, tuple[tuple[int, int], int, pygame.Color]],
vector_list:list[tuple[tuple[pygame.Vector2, pygame.Vector2], float]]
):
color_tiles_using_vectors_before_tile_creation(tile_map,vector_list,"#000000")
check_water_or_land_with_color(tile_map)
check_surrounding_tiles(tile_map)