2023-02-20 02:00:43 +01:00
|
|
|
from typing import Any, Tuple
|
|
|
|
import pygame as pg
|
2023-02-22 22:55:11 +01:00
|
|
|
from effects.effect import Effect
|
|
|
|
from util.color import Colors
|
|
|
|
from util.transform import transform_bounce
|
2023-02-20 02:00:43 +01:00
|
|
|
import random
|
|
|
|
from typing import Union, Generator
|
|
|
|
|
|
|
|
|
|
|
|
class ScanReticle(Effect):
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
bounds: pg.Rect,
|
|
|
|
colors: Tuple[
|
|
|
|
Union[pg.Color, Generator[pg.Color, None, None]],
|
|
|
|
Union[pg.Color, Generator[pg.Color, None, None]],
|
|
|
|
],
|
|
|
|
velocity=(1, 10),
|
|
|
|
x_factor=(0.1, 1),
|
|
|
|
y_factor=(0.1, 1),
|
|
|
|
*groups: pg.sprite.Group
|
|
|
|
) -> None:
|
|
|
|
self.min_velocity = velocity[0]
|
|
|
|
self.max_velocity = velocity[1]
|
|
|
|
|
|
|
|
self.velocity = random.randint(self.min_velocity, self.max_velocity)
|
|
|
|
self.ticks = random.randint(0, 360)
|
|
|
|
self.colors = colors
|
|
|
|
self.bounds = bounds
|
|
|
|
self.rect_size = min(self.bounds.width // 8, self.bounds.height // 8)
|
|
|
|
|
|
|
|
image = pg.Surface(self.bounds.size)
|
|
|
|
image.fill(Colors.Black)
|
|
|
|
image.set_colorkey(Colors.Black)
|
|
|
|
super().__init__(image, bounds, *groups)
|
|
|
|
self.bouncer = transform_bounce(
|
|
|
|
bounds=bounds, velocity=velocity, x_factor=x_factor, y_factor=y_factor
|
|
|
|
)
|
|
|
|
next(self.bouncer)
|
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-22 22:55:11 +01:00
|
|
|
target = self.bouncer.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,
|
|
|
|
),
|
|
|
|
10,
|
|
|
|
)
|
|
|
|
|
|
|
|
pg.draw.line(
|
|
|
|
self.image,
|
|
|
|
line_color,
|
|
|
|
(0, target[1]),
|
|
|
|
(self.bounds.width, target[1]),
|
|
|
|
10,
|
|
|
|
)
|
|
|
|
pg.draw.line(
|
|
|
|
self.image,
|
|
|
|
line_color,
|
|
|
|
(target[0], 0),
|
|
|
|
(target[0], self.bounds.height),
|
|
|
|
10,
|
|
|
|
)
|
|
|
|
|
|
|
|
# self.ticks += int(self.velocity / 180 * math.pi)
|
|
|
|
# self.velocity = random.randint(self.min_velocity, self.max_velocity)
|