2023-02-23 01:56:05 +01:00
|
|
|
from typing import Any, Optional, Tuple
|
2023-02-20 02:00:43 +01:00
|
|
|
import pygame as pg
|
2023-02-23 01:56:05 +01:00
|
|
|
from effects.effect import MovingEffect
|
2023-02-24 18:21:21 +01:00
|
|
|
from util.color import Colors, ColorGenerator
|
2023-02-23 01:56:05 +01:00
|
|
|
from util.transform import PositionGenerator
|
2023-02-20 02:00:43 +01:00
|
|
|
|
2023-02-23 01:56:05 +01:00
|
|
|
|
|
|
|
class ScanReticle(MovingEffect):
|
2023-02-20 02:00:43 +01:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
bounds: pg.Rect,
|
|
|
|
colors: Tuple[
|
2023-02-24 18:21:21 +01:00
|
|
|
ColorGenerator,
|
|
|
|
ColorGenerator,
|
2023-02-20 02:00:43 +01:00
|
|
|
],
|
2023-02-23 01:56:05 +01:00
|
|
|
mover: Optional[PositionGenerator] = None,
|
2023-02-20 02:00:43 +01:00
|
|
|
*groups: pg.sprite.Group
|
|
|
|
) -> None:
|
|
|
|
self.colors = colors
|
|
|
|
self.bounds = bounds
|
2023-03-05 01:46:59 +01:00
|
|
|
self.rect_size = min(self.bounds.width // 3, self.bounds.height // 3)
|
2023-02-20 02:00:43 +01:00
|
|
|
|
|
|
|
image = pg.Surface(self.bounds.size)
|
|
|
|
image.fill(Colors.Black)
|
|
|
|
image.set_colorkey(Colors.Black)
|
2023-02-23 01:56:05 +01:00
|
|
|
super().__init__(image, bounds, mover, *groups)
|
2023-02-22 22:55:11 +01:00
|
|
|
self.update(is_beat=False)
|
2023-02-20 02:00:43 +01:00
|
|
|
|
|
|
|
def update(self, *args: Any, **kwargs: Any) -> None:
|
|
|
|
|
2023-02-23 01:56:05 +01:00
|
|
|
target = self.mover.send(((self.rect_size, self.rect_size), kwargs["is_beat"]))
|
2023-02-20 02:00:43 +01:00
|
|
|
|
|
|
|
self.image.fill(Colors.Black)
|
|
|
|
|
|
|
|
line_color = (
|
|
|
|
self.colors[0]
|
|
|
|
if isinstance(self.colors[0], pg.Color)
|
|
|
|
else next(self.colors[0])
|
|
|
|
)
|
|
|
|
rect_color = (
|
|
|
|
self.colors[1]
|
|
|
|
if isinstance(self.colors[1], pg.Color)
|
|
|
|
else next(self.colors[1])
|
|
|
|
)
|
|
|
|
pg.draw.rect(
|
|
|
|
self.image,
|
|
|
|
rect_color,
|
|
|
|
(
|
|
|
|
target[0] - self.rect_size // 2,
|
|
|
|
target[1] - self.rect_size // 2,
|
|
|
|
self.rect_size,
|
|
|
|
self.rect_size,
|
|
|
|
),
|
2023-02-24 17:23:22 +01:00
|
|
|
0 if kwargs["is_beat"] else 20,
|
2023-02-20 02:00:43 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
pg.draw.line(
|
|
|
|
self.image,
|
|
|
|
line_color,
|
|
|
|
(0, target[1]),
|
|
|
|
(self.bounds.width, target[1]),
|
2023-02-24 17:23:22 +01:00
|
|
|
20,
|
2023-02-20 02:00:43 +01:00
|
|
|
)
|
|
|
|
pg.draw.line(
|
|
|
|
self.image,
|
|
|
|
line_color,
|
|
|
|
(target[0], 0),
|
|
|
|
(target[0], self.bounds.height),
|
2023-02-24 17:23:22 +01:00
|
|
|
20,
|
2023-02-20 02:00:43 +01:00
|
|
|
)
|