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
53
54
55
56
57
58
59
60
61
|
import pygame
from display import Scaling
class FieldSprite(pygame.sprite.Sprite):
def __init__(self, rect: pygame.Rect):
super().__init__()
self.rect = rect
self.image = pygame.Surface(self.rect.size)
self.image.fill("green")
class Field():
def __init__(self, scaling: Scaling = None):
self.scaling = scaling if scaling else Scaling(50,0,0)
self.sprites = pygame.sprite.Group()
self.updated = True
self.areas = [(0,0,40_000,28_000)]
def area_to_rect(self, area):
x, y, w, h = area
return pygame.Rect(
x * self.scaling.scale + self.scaling.left,
y * self.scaling.scale + self.scaling.top,
w * self.scaling.scale,
h * self.scaling.scale)
def coordinates_inside_area(self, area, x, y):
if x < area[0]:
return False
if y < area[1]:
return False
if x >= area[0]+area[2]:
return False
if y >= area[1]+area[3]:
return False
return True
def slice(self, x: int, y: int, direction: bool, thickness: int):
""" Slice one area into two areas """
# Find the overlapping area
for area in self.areas:
if self.coordinates_inside_area(area, x, y):
break
else:
return False
self.areas.remove(area)
return False
def __update_sprites(self):
self.sprites.empty()
for area in self.areas:
self.sprites.add(FieldSprite(self.area_to_rect(area)))
def get_sprites(self):
if self.updated:
self.__update_sprites()
return self.sprites
def __del__(self):
pass
|