from typing import Any, Optional, Tuple import pygame as pg from effects.effect import MovingEffect from util.color import Colors, ColorGenerator from util.transform import PositionGenerator class ScanReticle(MovingEffect): def __init__( self, bounds: pg.Rect, colors: Tuple[ ColorGenerator, ColorGenerator, ], mover: Optional[PositionGenerator] = None, *groups: pg.sprite.Group ) -> None: self.colors = colors self.bounds = bounds self.rect_size = min(self.bounds.width // 3, self.bounds.height // 3) image = pg.Surface(self.bounds.size) image.fill(Colors.Black) image.set_colorkey(Colors.Black) super().__init__(image, bounds, mover, *groups) self.update(is_beat=False) def update(self, *args: Any, **kwargs: Any) -> None: target = self.mover.send(((self.rect_size, self.rect_size), kwargs["is_beat"])) 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, ), 0 if kwargs["is_beat"] else 20, ) pg.draw.line( self.image, line_color, (0, target[1]), (self.bounds.width, target[1]), 20, ) pg.draw.line( self.image, line_color, (target[0], 0), (target[0], self.bounds.height), 20, )