【发布时间】:2021-02-20 15:33:02
【问题描述】:
【问题讨论】:
-
Pygame 没有内置功能。如果您想这样做,请查看OpenCV - Hough Line Transform。对于 Python 中的 OpenCV,您可以使用 opencv-python
标签: python pygame pygame-surface
【问题讨论】:
标签: python pygame pygame-surface
地图由大小为 64 的方形图块组成。棕色对象的颜色为 RGB(90,40,2),绿色对象的颜色为 RGB(57,214,105)。
通过读取每个图块中心的 1 个像素并将其与棕色进行比较来创建一个网格:
map_image = pygame.image.load("KkiJJ.png")
map_size = map_image.get_size()
tile_size = 64
grid = []
for x in range(map_size[0] // tile_size):
column = []
for y in range(map_size[1] // tile_size):
color = map_image.get_at((x*tile_size + tile_size//2, y*tile_size + tile_size//2))
if color.r == 90 and color.g == 44 and color.b == 2:
column.append(1)
else:
column.append(0)
grid.append(column)
c 列和r 行中的瓦片坐标可以用pygame.Rect 对象表示:
r = pygame.Rect(c * tile_size, r * tile_size, tile_size, tile_size)
【讨论】: