class InvencibleCircle(BasicCircle): def __init__(self, position, radius, material): super(InvencibleCircle, self).__init__(position, radius, material, layer=-2) self.circle_collider = CircleCollider(self) self.should_die = False # Todo: create a power_up class that is superclass of invencible circle and star def start(self): self.particle_system = ParticleSystem(self, Particle, quant=1, period=0.15, vel_min=30, vel_max=60, duration=0.8, gravity=98, inherit_vel=True) self.particle_system.set_circ_gen(self.transform.position, self.circle_mesh.get_radius(), mode="radial", direct_met=self.direct_met, ini_angle_met=self.ini_angle_met, fin_angle_met=self.fin_angle_met) self.particle_system.play() self.animation = LitterBounce(self) self.animator = Animator(self, [self.animation, PowerUpFadeOut(self)]) self.animator.play() def die(self): # TODO: change how collider works: dont use the collider list Collider.remove(self) self.circle_collider = None self.animator.play_next_animation() self.should_die = True self.die_time = Time.now() def update(self): if self.should_die: if Time.now() - self.die_time > 0.4: self.destroy_me() def ini_angle_met(self): return 150 def fin_angle_met(self): return 390 def direct_met(self): return Vector2(0, -1)
class Particle(BasicParticleCirc): def __init__(self, position): self.change = True super().__init__(position) def start(self): self.animation = ParticleFadeAnimation( self, self.creator_obj.particle_system.duration) self.animator = Animator(self, [self.animation]) self.animator.play() def update(self): if self.change: self.change = False self.material = Material(self.creator_obj.material.color) if Time.now() - self.creation_time > self.destroy_time: self.destroy_me()
class ScreenFader(BasicRectangle): def __init__(self, fade="in", fade_duration=0.7): """ Constructor, will decide whether to fade in or fade out :param fade: string telling fade in or out """ self.fade = fade self.fade_duration = fade_duration if fade == "in": alp = 255 else: alp = 0 super().__init__(Vector2(0, 0), Vector2(Engine.screen_width, Engine.screen_height), Material(Color.black, alpha=alp), 1000) def start(self): """ Create a animation that fades the entire screen Pass this animation to animator and play it """ key_frames = list() if self.fade == "in": key_frames.append(KeyFrame(0.0, alpha=255)) key_frames.append(KeyFrame(self.fade_duration, alpha=0)) else: key_frames.append(KeyFrame(0.0, alpha=0)) key_frames.append(KeyFrame(self.fade_duration, alpha=255)) self.animation = Animation(self, key_frames, should_loop=False, unscaled="True") self.animator = Animator(self, animation_list=[self.animation]) self.animator.play() self.creation_time = Time.now() def update(self): """ Will destroy the animation after finished it """ if Time.now() - self.creation_time > self.fade_duration * 2: GameObject.destroy(self)
class Star(GameObject): def __init__(self, center_position, radius, material): """ Add the polygon mesh component Call the superclass constructor passing basic game_object parameters """ super(Star, self).__init__(center_position, 0, Vector2(1, 1), 2) self.material = material self.circle_collider = CircleCollider(self) self.circle_mesh = CircleMesh(self, radius) self.polygon_mesh = PolygonMesh(self) self.should_die = False def _get_points(self): point_list = list() angle = math.pi / 2 + math.pi for i in range(5): point_list.append( Vector2( self.transform.position.x + self.circle_mesh.get_radius() * math.cos(angle), self.transform.position.y + self.circle_mesh.get_radius() * math.sin(angle))) angle = angle + 36 * math.pi / 180 point_list.append( Vector2( self.transform.position.x + self.circle_mesh.get_radius() / 2 * math.cos(angle), self.transform.position.y + self.circle_mesh.get_radius() / 2 * math.sin(angle))) angle = angle + 36 * math.pi / 180 for i in range(5): point = point_list[i] point_list[i] = Geometry.rotate_point( Vector2(self.transform.position.x, self.transform.position.y), point, self.transform.rotation) return point_list def fall(self, distance, angular_distance): self.transform.translate( Vector2(self.transform.position.x, self.transform.position.y + distance)) self.transform.rotate(angular_distance) def die(self): # TODO: change how collider works: dont use the collider list Collider.remove(self) self.circle_collider = None self.circle_collider = None self.animator.play_next_animation() self.should_die = True self.die_time = Time.now() def start(self): self.particle_system = ParticleSystem(self, Particle, quant=1, period=0.15, vel_min=30, vel_max=60, duration=0.8, gravity=98, inherit_vel=True) self.particle_system.set_circ_gen(self.transform.position, self.circle_mesh.get_radius(), mode="radial", direct_met=self.direct_met, ini_angle_met=self.ini_angle_met, fin_angle_met=self.fin_angle_met) self.particle_system.play() self.animation = LitterBounce(self) self.animator = Animator(self, [self.animation, PowerUpFadeOut(self)]) self.animator.play() def update(self): if self.should_die: if Time.now() - self.die_time > 0.4: self.destroy_me() def ini_angle_met(self): return 150 def fin_angle_met(self): return 390 def direct_met(self): return Vector2(0, -1)