def generate_obstacle(self): direction = rand(0, 1) < 0.5 obstacle_width = 0.45 * Constants.screen_width obstacle_height = 0.06 * Constants.screen_height rect1 = Rectangle(Vector2(direction * 0.5 * Constants.screen_width + 12, - obstacle_height), Vector2(obstacle_width, obstacle_height), Material((255, 255, 255))) rect2_x = rect1.transform.position.x - 12 if rect2_x == 0: rect2_x = 0.5 * Constants.screen_width + 12 else: rect2_x = 0.0 + 12 rect2 = Rectangle(Vector2(rect2_x, rect1.transform.position.y), Vector2(obstacle_width, obstacle_height), Material((255, 255, 255))) rect1.animation = ObstaclePulsingAnimation(rect1) rect1.animator = Animator(rect1, [rect1.animation]) rect1.animator.play() rect2.animation = ObstaclePulsingAnimation(rect2) rect2.animator = Animator(rect2, [rect2.animation]) rect2.animator.play() self.game_object_list.append([rect1, rect2])
def start(self): self.physics = Physics(self) self.star_score_controller = GameObject.find_by_type( "StarScoreController")[0] self.main_scene_controller = GameObject.find_by_type( "MainSceneController")[0] self.invencible_power_up_controller = GameObject.find_by_type( "InvenciblePowerUpController")[0] self.animation = CirclePlayerInitialAnimation(self) self.animator = Animator(self, [self.animation]) self.death_sound = mixer.Sound( 'Balance/assets/soundtrack/ball_death_01.ogg') self.particle_system = ParticleSystem(self, Particle, quant=5, period=0.07, vel_min=30, vel_max=200, duration=0.5, inherit_vel=True, inherit_vel_mult=-0.7) self.particle_system.set_circ_gen(self.transform.position, self.circle_mesh.get_radius(), mode="directional", direct_met=self.direct_met, ini_angle_met=self.ini_angle_met, fin_angle_met=self.fin_angle_met) self.particle_system.play()
def generate_obstacle(self): direction = rand(0, 1) < 0.5 rect = Rectangle(Vector2(direction * 0.5 * Constants.screen_width + 12, - 0.06 * Constants.screen_height), Vector2(0.45 * Constants.screen_width,0.06 * Constants.screen_height), Material((255, 255, 255))) rect.animation = ObstaclePulsingAnimation(rect) rect.animator = Animator(rect, [rect.animation]) rect.animator.play() self.game_object_list.append(rect)
def generate_obstacle(self): self.obstacle_width = 0.3 * Constants.screen_width self.obstacle_height = 0.06 * Constants.screen_height rect = Rectangle( Vector2(0.5 * Constants.screen_width - 0.5 * self.obstacle_width, -3 * self.obstacle_height), Vector2(self.obstacle_width, self.obstacle_height), Material((255, 255, 255))) rect.animation = ObstaclePulsingAnimation(rect) rect.animator = Animator(rect, [rect.animation]) rect.animator.play() self.game_object_list.append(rect)
def get_star(self): self.sound_collect.play() obstacle = self.game_object_list[0] #plus score effect font_path = "Balance/assets/fonts/neuropolxrg.ttf" plus_score = Text(obstacle.transform.position, "+50", Material(Color.white, alpha=255), 15, font_path) plus_score.transform.position.x -= plus_score.text_mesh.size plus_score.animation = TextUpFadeOutAnimation(plus_score) plus_score.animator = Animator(plus_score, [plus_score.animation]) plus_score.animator.play() self.time_of_last_plus_score = Time.now() self.plus_score = plus_score self.should_delete_plus_score_text = True self.score_controller.score += self.points_per_star
def generate_obstacle(self): self.obstacle_width = 0.45 * Constants.screen_width self.obstacle_height = 0.06 * Constants.screen_height rect = Rectangle( Vector2(0.5 * Constants.screen_width - 0.5 * self.obstacle_width, -self.obstacle_height), Vector2(self.obstacle_width, self.obstacle_height), Material((255, 255, 255))) direction = rand(0, 1) < 0.5 if direction == 0: direction = -1 rect.direction = direction rect.transform.rotate(0) rect.animation = ObstaclePulsingAnimation(rect) rect.animator = Animator(rect, [rect.animation]) rect.animator.play() self.game_object_list.append(rect)
def get_power_up(self): self.sound_collect.play() power_up = self.game_object_list[0] #Power up text effect font_path = "Balance/assets/fonts/neuropolxrg.ttf" text_size = 15 power_up_text = Text(power_up.transform.position, "INVENCIBLE!", Material(Color.purple, alpha=255), text_size, font_path) power_up_text.transform.position.x -= power_up_text.text_mesh.size power_up_text.animation = TextUpFadeOutAnimation(power_up_text) power_up_text.animator = Animator(power_up_text, [power_up_text.animation]) power_up_text.animator.play() for i in range(2): self.player_controller.game_object_list[i].is_invencible = True self.change_colors_to_green() self.time_of_last_invencibily = Time.now() self.power_up_text = power_up_text self.should_delete_power_up_text = True
def generate_obstacle(self): side = randint(0, 1) rect = Rectangle( Vector2(-self.obstacle_width / 2 + Constants.screen_width * side, -self.obstacle_height), Vector2(self.obstacle_width, self.obstacle_height), Material((255, 255, 255))) rect.animation = ObstaclePulsingAnimation(rect) rect.animator = Animator(rect, [rect.animation]) rect.animator.play() if side == 1: rect.side = -1 else: rect.side = 1 self.game_object_list.append(rect)
def generate_obstacle(self): random_pos = int( randfloat(Constants.screen_width - self.obstacle_size / 2 - 1, -self.obstacle_size / 2 + 1)) rect = Rectangle(Vector2(random_pos, -self.obstacle_size), Vector2(self.obstacle_size, self.obstacle_size), Material((255, 255, 255))) rect.animation = ObstaclePulsingAnimation(rect) rect.animator = Animator(rect, [rect.animation]) rect.animator.play() direction = randint(0, 1) if direction == 0: direction = -1 rect.vel = direction # Checks if going left or right. Can be 1 for right or -1 for left self.game_object_list.append(rect)
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 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 generate_difficulty_text(self): title_x = 0.35 * Constants.screen_width title_y = 0.3 * Constants.screen_height title_size = 50 text = "HARDER!" if self.game_difficuty == self.max_difficult: text = "MAX DIFFICULTY!" title_size = 28 title_x = 0.20 * Constants.screen_width font_path = "Balance/assets/fonts/neuropolxrg.ttf" diff_text = Text(Vector2(title_x - title_size, title_y), text, Material(Color.red, alpha=255), title_size, font_path) diff_text.transform.position.x -= diff_text.text_mesh.size diff_text.animation = TextUpFadeOutAnimation(diff_text) diff_text.animator = Animator(diff_text, [diff_text.animation]) diff_text.animator.play() self.diff_text = diff_text self.diff_text_gen_time = Time.now() self.should_delete_difficulty_text = True
def turn_invisible(self, game_obj): game_obj.animation = PowerUpFadeOut(game_obj) game_obj.animator = Animator(game_obj, [game_obj.animation]) game_obj.animator.play()
def start(self): self.animation = ParticleFadeAnimation( self, self.creator_obj.particle_system.duration) self.animator = Animator(self, [self.animation]) self.animator.play()