52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from DrawType import DrawType
|
|
from Point import Point
|
|
from Vec import Vec
|
|
|
|
|
|
class PointGrid:
|
|
|
|
def __init__(self, grid_cell_size, cell_count, maze, radius=8):
|
|
self.grid_cell_size = grid_cell_size
|
|
self.points = []
|
|
self.big_points_positions = [
|
|
(2, 1),
|
|
(27, 1),
|
|
(2, 27),
|
|
(27, 27)
|
|
] # Idle-Punkte bekommen feste Position
|
|
|
|
# Fill the points list based on size of one cell, screen height and width
|
|
for x in range(0, int(cell_count)):
|
|
self.points.append([])
|
|
for y in range(0, int(cell_count)):
|
|
point = Point(Vec(x * grid_cell_size + grid_cell_size / 2, y * grid_cell_size + grid_cell_size / 2),
|
|
Vec(radius + (5 if (x, y) in self.big_points_positions else 0),
|
|
radius + (5 if (x, y) in self.big_points_positions else 0)),
|
|
(x, y) in self.big_points_positions)
|
|
self.points[x].append(point)
|
|
if maze.maze[x][y] > 0:
|
|
point.eat()
|
|
|
|
def draw(self, screen, color, draw_type: DrawType = DrawType.circle):
|
|
|
|
# Loop through the points list
|
|
for xList in self.points:
|
|
for point in xList:
|
|
# Check if point is eaten
|
|
if not point.eaten:
|
|
point.draw(screen, color, draw_type)
|
|
|
|
def get_surrounding_points(self, player_position):
|
|
x = int(player_position.x / self.grid_cell_size)
|
|
y = int(player_position.y / self.grid_cell_size)
|
|
|
|
result = []
|
|
|
|
for ix in range(x - 1, x + 2):
|
|
for iy in range(y - 1, y + 2):
|
|
if 0 <= ix < len(self.points):
|
|
if 0 <= iy < len(self.points[ix]):
|
|
result.append(self.points[ix][iy])
|
|
|
|
return result
|