@@ 16-42 (lines=27) @@ | ||
13 | from ._Part import Part |
|
14 | ||
15 | ||
16 | class Pipe(Part): |
|
17 | ||
18 | def __init__(self, size: int, x: int, y: int, rotation: int = 0, *, |
|
19 | color: Union[List[int], Tuple[int]] = (90, 90, 90)): |
|
20 | super().__init__() |
|
21 | self.__rotation = rotation |
|
22 | self.__length = size |
|
23 | self.__color = color |
|
24 | self.set_pos(x, y) |
|
25 | ||
26 | def design_render(self, screen: 'Screen') -> Tuple[int, int, pygame.Surface]: |
|
27 | # Create the surface |
|
28 | surface = pygame.Surface((self.__length * screen.block_size, screen.block_size), pygame.SRCALPHA, 32) |
|
29 | surface = surface.convert_alpha() |
|
30 | ||
31 | # Draw the rect |
|
32 | rect = pygame.Rect(0, 0, self.__length * screen.block_size, screen.block_size) |
|
33 | pygame.draw.rect(surface, self.__color, rect) |
|
34 | ||
35 | # Rotate |
|
36 | surface = pygame.transform.rotate(surface, self.__rotation) |
|
37 | ||
38 | # Render |
|
39 | x, y = surface.get_size() |
|
40 | x = int((self._x * screen.block_size) - floor(x / 2)) |
|
41 | y = int((self._y * screen.block_size) - floor(y / 2)) |
|
42 | return x, y, surface |
|
43 |
@@ 16-42 (lines=27) @@ | ||
13 | from ._Part import Part |
|
14 | ||
15 | ||
16 | class Pipe(Part): |
|
17 | ||
18 | def __init__(self, size: int, x: int, y: int, rotation: int = 0, *, |
|
19 | color: Union[List[int], Tuple[int]] = (90, 90, 90)): |
|
20 | super().__init__() |
|
21 | self.__rotation = rotation |
|
22 | self.__length = size |
|
23 | self.__color = color |
|
24 | self.set_pos(x, y) |
|
25 | ||
26 | def design_render(self, screen: 'Screen') -> Tuple[int, int, pygame.Surface]: |
|
27 | # Create the surface |
|
28 | surface = pygame.Surface((self.__length * screen.block_size, screen.block_size), pygame.SRCALPHA, 32) |
|
29 | surface = surface.convert_alpha() |
|
30 | ||
31 | # Draw the rect |
|
32 | rect = pygame.Rect(0, 0, self.__length * screen.block_size, screen.block_size) |
|
33 | pygame.draw.rect(surface, self.__color, rect) |
|
34 | ||
35 | # Rotate |
|
36 | surface = pygame.transform.rotate(surface, self.__rotation) |
|
37 | ||
38 | # Render |
|
39 | x, y = surface.get_size() |
|
40 | x = int((self._x * screen.block_size) - floor(x / 2)) |
|
41 | y = int((self._y * screen.block_size) - floor(y / 2)) |
|
42 | return x, y, surface |
|
43 |