Ejemplo n.º 1
0
    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])
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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()
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
 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()
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
    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
Ejemplo n.º 11
0
 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
Ejemplo n.º 13
0
    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)
Ejemplo n.º 15
0
    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()
Ejemplo n.º 17
0
 def start(self):
     self.animation = ParticleFadeAnimation(
         self, self.creator_obj.particle_system.duration)
     self.animator = Animator(self, [self.animation])
     self.animator.play()
Ejemplo n.º 18
0
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)