import random from libs.animation import Animation from libs.texture import TextureWrapper import pyray as ray class Renda: @staticmethod def create(tex: TextureWrapper, index: int): map = [Renda0, Renda1, Renda2] selected_obj = map[index] return selected_obj(tex, index) class BaseRenda: def __init__(self, tex: TextureWrapper, index: int): self.name = 'renda_' + str(index) self.hori_move = Animation.create_move(1500, total_distance=1280) self.hori_move.start() def update(self, current_time_ms: float): self.hori_move.update(current_time_ms) class Renda0(BaseRenda): def __init__(self, tex: TextureWrapper, index: int): super().__init__(tex, index) self.vert_move = Animation.create_move(1500, total_distance=800) self.vert_move.start() self.frame = random.randint(0, 5) self.x = random.randint(0, 500) self.y = random.randint(0, 20) def update(self, current_time_ms: float): super().update(current_time_ms) self.vert_move.update(current_time_ms) def draw(self, tex: TextureWrapper): tex.draw_texture('renda', self.name, frame=self.frame, x=self.hori_move.attribute+self.x, y=-self.vert_move.attribute+self.y) class Renda1(BaseRenda): def __init__(self, tex: TextureWrapper, index: int): super().__init__(tex, index) self.frame = random.randint(0, 5) self.y = random.randint(0, 200) self.rotate = Animation.create_move(800, total_distance=360) self.rotate.start() self.origin = ray.Vector2(64, 64) def update(self, current_time_ms: float): super().update(current_time_ms) self.rotate.update(current_time_ms) if self.rotate.is_finished: self.rotate.restart() def draw(self, tex: TextureWrapper): tex.draw_texture('renda', self.name, frame=self.frame, x=self.hori_move.attribute+self.origin.x, y=self.y+self.origin.y, origin=self.origin, rotation=self.rotate.attribute) class Renda2(BaseRenda): def __init__(self, tex: TextureWrapper, index: int): super().__init__(tex, index) self.vert_move = Animation.create_move(1500, total_distance=800) self.vert_move.start() self.x = random.randint(0, 500) self.y = random.randint(0, 20) def update(self, current_time_ms: float): super().update(current_time_ms) self.vert_move.update(current_time_ms) def draw(self, tex: TextureWrapper): tex.draw_texture('renda', self.name, x=self.hori_move.attribute+self.x, y=-self.vert_move.attribute+self.y) class RendaController: def __init__(self, tex: TextureWrapper, index: int, path: str ='background'): self.rendas = set() tex.load_zip(path, 'renda') self.tex = tex self.index = index self.path = path def add_renda(self): self.rendas.add(Renda.create(self.tex, self.index)) def update(self, current_time_ms: float): remove = set() for renda in self.rendas: renda.update(current_time_ms) if renda.hori_move.is_finished: remove.add(renda) for renda in remove: self.rendas.remove(renda) def draw(self): for renda in self.rendas: renda.draw(self.tex)