def start(self): """ NomalBehaivor start method will be called when the object is instantiate on scene """ self.time = Time.now() self.period = 1.5 font_path = "Balance/assets/fonts/neuropolxrg.ttf" message_x = 15 message_y = 300 message_size = 14 score = str(int(Constants.current_score)) score_size = 28 score_x = 30 score_y = 240 title_x = 20 title_y = 180 title_size = 50 self.game_object_list = [ Text(Vector2(title_x, title_y), "You died", Material(Color.red), title_size, font_path), Text(Vector2(score_x, score_y), "Score: " + score, Material(Color.white), score_size, font_path), Text(Vector2(message_x, message_y), "Press arrows keys to try again", Material(Color.white), message_size, font_path) ] self.setup_fader() BackgroundParticlesController()
def start(self): """ NomalBehaivor start method will be called when the object is instantiate on scene """ self.time = Time.now() self.period = 0.9 font_path = "Balance/assets/fonts/neuropolxrg.ttf" message_x = 10 message_y = 270 message_size = 14 title_x = 37 title_y = 200 title_size = 50 self.setup_soundtrack() BackgroundParticlesController() self.game_object_list = [ Text(Vector2(message_x, message_y), "Press arrows keys to start playing", Material(Color.white), message_size, font_path), Text(Vector2(title_x, title_y), "Balance", Material(Color.white), title_size, font_path) ] self.setup_fader()
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.angle = 0.0 self.angularSpeed = 5.0 self.game_object_list = [ PlayerCircle( Vector2(Constants.circCenter_x + Constants.circRadius, Constants.screen_height + 15), 15, Material(Color.blue, alpha=240)), PlayerCircle( Vector2(Constants.circCenter_x - Constants.circRadius, Constants.screen_height + 15), 15, Material(Color.orange, alpha=240)) ] self.in_initial_animation = True self.should_play = True self.initial_time = Time.now()
def generate_obstacle(self): random_pos = int(randfloat(self.size / 2 + Constants.circCenter_x - Constants.circRadius, Constants.screen_width - (self.size / 2 + Constants.circCenter_x - Constants.circRadius))) star = Star(Vector2(random_pos, -self.size), self.size, Material(Color.yellow)) self.game_object_list.append(star)
def generate_obstacle(self): random_pos = int(randfloat(self.radius + Constants.circCenter_x - Constants.circRadius, Constants.screen_width - (self.radius + Constants.circCenter_x - Constants.circRadius))) circle = InvencibleCircle(Vector2(random_pos, -2 * self.radius), self.radius, Material(Color.purple)) self.game_object_list.append(circle)
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 __init__(self, position=Vector2(0, 0), dimension=Vector2(10, 10), material=Material(), layer=0, scale=Vector2(1, 1)): """ Add the rectangle mesh component Call the superclass constructor passing basic game_object parameters :param position.x: initial position x of the rectangle :param position.y: initial position y of the rectangle :param dimension.x: initial width of the rectangle :param dimension.y: initial height of the rectangle :param color: initial color of the rectangle """ super(BasicRectangle, self).__init__(position, 0, Vector2(1, 1), layer) self.material = Material(material.color, material.alpha) self.dimension = dimension self.polygon_mesh = PolygonMesh(self)
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 generate_particles(self): for i in range(5): rect = Rectangle( Vector2(rand(0, Constants.screen_width), rand(0, Constants.screen_height)), Vector2(0.007 * Constants.screen_width, 0.007 * Constants.screen_width), Material(Color.silver), -3) rect.polygon_collider = [] rect.collidable = False self.first_layer.append(rect) for i in range(5): rect = Rectangle( Vector2(rand(0, Constants.screen_width), rand(0, Constants.screen_height)), Vector2(0.007 * Constants.screen_width, 0.007 * Constants.screen_width), Material(Color.gray), -3) rect.polygon_collider = [] rect.collidable = False self.second_layer.append(rect)
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 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 __init__(self, position=Vector2(0, 0), radius=2, material=Material(Color.white), layer=0): """ Add the circle mesh component Call the superclass constructor passing basic game_object parameters :param position_x: initial position x of the circle :param position_y: initial position y of the circle :param radius: initial radius of the circle :param color: initial color of the circle """ super(BasicCircle, self).__init__(position, 0, Vector2(1, 1), layer) self.material = material self.radius = radius self.circle_mesh = CircleMesh(self, radius)
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): font_path = "Balance/assets/fonts/neuropolxrg.ttf" self.time_to_update_score = 0.095 self.score_per_step = 1 # Number of steps of the Balance required to update the score self.last_update_time = Time.now() self.score = 0.0 score_x = 10.0 score_y = 5.0 score_message = str(int(self.score)) score_color = Color.white score_size = 15 self.game_object_list = [ Text(Vector2(score_x, score_y), score_message, Material(score_color), score_size, font_path) ] self.game_object_list[0].text_mesh.message = str(int(self.score))
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 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()