コード例 #1
0
    def update(self):

        if (Time.now() - self.last_update_time) * Time.time_scale >= self.time_to_update_score:
            self.score = self.score + self.score_per_step
            self.last_update_time = Time.now()
            Constants.current_score = self.score
            self.game_object_list[0].text_mesh.message = str(int(self.score))
コード例 #2
0
 def should_spawn(self):
     """
     :return: if it should spawn
     """
     if Time.now() - self.time > self.period:
         self.time = Time.now()
         return True
     else:
         return False
コード例 #3
0
    def increase_difficult(self):
        if Time.now() - self.last_increases_dificculty_time > self.time_to_increase_difficult \
                and self.game_difficuty < self.max_difficult:

            self.game_difficuty += 1
            self.last_increases_dificculty_time = Time.now()
            self.time_to_increase_difficult *= 1.03
            self.generation_obstacle_difficult = (1 - (self.game_difficuty - 1) * 0.2 / self.max_difficult)
            self.generate_difficulty_text()

            if self.game_difficuty == 2:
                obstacle = MiddleRectObstacleController(Vector2(0, 0), 0, Vector2(0, 0), 0)
                obstacle.start()
                self.obstacle_generators.append(obstacle)

            if self.game_difficuty == 3:
                obstacle = TwoInOneSimpleObstacleController(Vector2(0, 0), 0, Vector2(0, 0), 0)
                obstacle.start()
                self.obstacle_generators.append(obstacle)

            if self.game_difficuty == 4:
                obstacle = TwoSideBySideSimpleObstacleController(Vector2(0, 0), 0, Vector2(0, 0), 0)
                obstacle.start()
                self.obstacle_generators.append(obstacle)

            if self.game_difficuty == 5:
                obstacle = HalfMoonSpinningRectObstacleController(Vector2(0, 0), 0, Vector2(0, 0), 0)
                obstacle.start()
                self.obstacle_generators.append(obstacle)

            if self.game_difficuty == 6:
                obstacle = InvisibleMiddleObstacleController(Vector2(0, 0), 0, Vector2(0, 0), 0)
                obstacle.start()
                self.obstacle_generators.append(obstacle)
                self.delete_object_with_specific_type(MiddleRectObstacleController)

            if self.game_difficuty == 7:
                obstacle = InvisibleSimpleObstacleController(Vector2(0, 0), 0, Vector2(0, 0), 0)
                obstacle.start()
                self.obstacle_generators.append(obstacle)

            if self.game_difficuty == 8 and len(self.obstacle_generators) > 3:
                obstacle = RectTranslateXObstacleController(Vector2(0, 0), 0, Vector2(0, 0), 0)
                obstacle.start()
                self.obstacle_generators.append(obstacle)
                self.delete_object_with_specific_type(SimpleObstacleController)
                self.delete_object_with_specific_type(TwoInOneSimpleObstacleController)

            if self.game_difficuty == 9:
                obstacle = SpinningMiddleRectObstacleController(Vector2(0, 0), 0, Vector2(0, 0), 0)
                obstacle.start()
                self.obstacle_generators.append(obstacle)

            if self.game_difficuty == 10:
                self.delete_object_with_specific_type(TwoSideBySideSimpleObstacleController)
                self.delete_object_with_specific_type(InvisibleSimpleObstacleController)
                self.delete_object_with_specific_type(HalfMoonSpinningRectObstacleController)
コード例 #4
0
 def should_spawn(self):
     if self.num_of_periods != "inf":
         self.actual_period += 1
         if self.num_of_periods > self.actual_period:
             return False
     if (Time.now() - self.last_time) > self.period:
         self.last_time = Time.now()
         return True
     else:
         return False
コード例 #5
0
 def change_scene(self):
     """
     Will fade screen out and the change it
     """
     if self.should_fade_out:
         ScreenFader(fade="out", fade_duration=self.fade_out_duration)
         self.should_fade_out = False
         self.should_change_scene = True
         self.change_scene_timer = Time.now()
         Time.time_scale = 0
     if self.should_change_scene and Time.now(
     ) - self.change_scene_timer > self.fade_out_duration + 0.2:
         Time.time_scale = 1.0
         Scene.change_scene(2)
コード例 #6
0
    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 = "game/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()
コード例 #7
0
    def start(self):
        """
        NormalBehavior start method
        will be called when the object is instantiate on scene
        """
        self.time = Time.now()
        self.period = 1.5

        font_path = "game/assets/fonts/neuropolxrg.ttf"

        message_x = 15
        message_y = 300
        message_size = 14

        title_x = 20
        title_y = 180
        title_size = 50

        self.game_object_list = [
            Text(Vector2(title_x, title_y), "PAUSED", Material(Color.red),
                 title_size, font_path),
            Text(Vector2(message_x, message_y), "Press space to keep playing",
                 Material(Color.white), message_size, font_path),
            Rectangle(Vector2(0, 0),
                      Vector2(Constants.screen_width, Constants.screen_height),
                      Material(Color.mask))
        ]

        self.game_object_list[2].collidable = False
コード例 #8
0
 def start(self):
     """
     Will start a particle effect
     """
     self.physics.inst_velocity = self.inst_vel
     self.particle_system = ParticleSystem(self,
                                           Particle,
                                           quant=15,
                                           period=0.01,
                                           vel_min=30,
                                           vel_max=130,
                                           duration=0.9,
                                           gravity=130,
                                           layer=10,
                                           inherit_vel=True,
                                           inherit_vel_mult=0.5,
                                           unscaled=True,
                                           num_of_periods=1)
     self.particle_system.set_circ_gen(self.transform.position,
                                       radius=self.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.spawn_time = Time.now()
コード例 #9
0
 def update(self):
     """
     Will be destroyed after a time
     """
     self.physics.inst_velocity = self.inst_vel
     if Time.now() - self.spawn_time > 0.01:
         self.destroy_me()
コード例 #10
0
    def update(self):

        if Time.time_scale == 0.0:
            #Paused game. Adjust timers
            self.time_of_last_invencibily += Time.delta_time(True)

        difference_time = Time.now() - self.time_of_last_invencibily
        if difference_time > self.invecible_time:
            for i in range(2):
                self.player_controller.game_object_list[
                    i].is_invencible = False
            self.get_back_to_original_colors()
            self.current_animation_tick_index = 0
        else:
            value = min(difference_time / self.invecible_time,
                        1)  # Just to convert between 0 and 1
            diff = abs(
                value -
                self.animation_ticks_times[self.current_animation_tick_index])
            if (diff < 0.01):
                self.current_animation_tick_index += 1
                self.tick_colors()

        for obstacle in self.game_object_list:
            if obstacle.transform.position.y > Constants.screen_height:
                self.game_object_list.remove(obstacle)
                obstacle.destroy(obstacle)
                GameObject.destroy(obstacle)
            else:
                self.fall(obstacle)
        self.delete_power_up_text()
コード例 #11
0
    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 = "game/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()
コード例 #12
0
 def initial_animation(self):
     if self.in_initial_animation:
         if self.should_play:
             self.should_play = False
             self.game_object_list[0].animator.play()
             self.game_object_list[1].animator.play()
     if Time.now() - self.initial_time > 1.0:
         self.in_initial_animation = False
コード例 #13
0
 def start(self):
     self.obstacle_generators = [
         SimpleObstacleController(Vector2(0, 0), 0, Vector2(0, 0), 0)
     ]
     self.rect_x_controller = RandomXFinalObstacleController(Vector2(0, 0), 0, Vector2(0, 0), 0)
     self.obstacle_geneation_delta = 1500
     self.last_generation_time = 1000 * Time.now()
     self.game_object_list = []
     self.last_increases_dificculty_time = Time.now()
     self.game_difficuty = 1
     self.time_to_increase_difficult = 6.2
     self.generation_obstacle_difficult = 1
     self.max_difficult = 10
     self.should_delete_difficulty_text = False
     self.diff_text_gen_time = 0.0
     for obstacle_generator in self.obstacle_generators:
         obstacle_generator.start()
コード例 #14
0
    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()
コード例 #15
0
 def update(self):
     """
     NomalBehaivor update method
     will be call every frame
     """
     if self.should_spawn():
         self.spawn_block()
     if self.pressed_button() and self.can_press_button:
         self.should_timer = True
         self.can_press_button = False
     if self.should_timer:
         ScreenFader(fade="out")
         self.timer = Time.now()
         self.should_timer = False
         self.should_change_scene = True
     if self.should_change_scene:
         if Time.now() - self.timer > 0.68:
             Scene.change_scene(1)
コード例 #16
0
 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()
コード例 #17
0
    def generate_random_obstacle(self):
        self.last_generation_time = 1000 * Time.now()

        number_of_obstacles = int(min(self.game_difficuty, len(self.obstacle_generators)))
        random_ind = rand(0, number_of_obstacles-1)
        random_obstacle_generator = self.obstacle_generators[random_ind]
        if type(random_obstacle_generator) == RectTranslateXObstacleController:
            self.last_generation_time -= 300

        if self.game_difficuty == self.max_difficult:
            self.rect_x_controller.generate_obstacle()
        random_obstacle_generator.generate_obstacle()
コード例 #18
0
 def initialize_scene(self):
     """
     When is the correct time, initialize scene
     This will happen just once
     """
     if Time.now() - self.initial_time > 0.45 and self.should_initialize:
         self.should_initialize = False
         self.background_particle_controller = BackgroundParticlesController(
         )
         self.player_controller = PlayerController()
         self.obstacle_controller_wrapper = ObstacleControllerWrapper()
         self.items_controller = ItemsControllerWrapper()
         self.score_controller = ScoreController()
コード例 #19
0
    def get_star(self):
        self.sound_collect.play()
        obstacle = self.game_object_list[0]

        #plus score effect
        font_path = "game/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
コード例 #20
0
    def update(self):

        if Time.time_scale < 0.5:
            #Adjust timers to new delta
            self.last_generation_time += 1000 * Time.delta_time(True)
            self.last_increases_dificculty_time += Time.delta_time(True)

        self.increase_difficult()
        self.delete_difficulty_text()

        if (1000 * Time.now() - self.last_generation_time) * Time.time_scale > self.obstacle_geneation_delta * \
                self.generation_obstacle_difficult:
            self.generate_random_obstacle()

        for obstacle_generator in self.obstacle_generators:
            game_objs = obstacle_generator.game_object_list
            self.game_object_list.extend(game_objs)
コード例 #21
0
 def __init__(self,
              game_object,
              spawn_game_obj_class,
              layer=0,
              quant=1,
              quant_proport_to_len=False,
              period=0.05,
              vel_min=80,
              vel_max=160,
              duration=1.0,
              gravity=0,
              inherit_vel=False,
              inherit_vel_mult=1,
              spawn_prob="lin",
              vel_prob="lin",
              unscaled=False,
              num_of_periods="inf"):
     super().__init__(game_object)
     self.duration = duration
     self.gravity = gravity
     self.vel_min = vel_min
     self.layer = layer
     self.vel_max = vel_max
     self.inherit_vel = inherit_vel
     self.quant_proport_to_len = quant_proport_to_len
     self.inherit_vel_mult = inherit_vel_mult
     self.quant = quant
     self.turned_on = False
     self.period = period
     self.spawn_game_obj_class = spawn_game_obj_class
     self.last_time = Time.now()
     self.ini_point_method = None
     self.fin_point_method = None
     self.generation_mode = None
     self.obj_list = list()
     self.spawn_prob = None
     self.vel_prob = None
     self.define_vel_prob(vel_prob)
     self.define_spawn_prob(spawn_prob)
     self.unscaled = unscaled
     self.num_of_periods = num_of_periods
     self.actual_period = 0
     if self.inherit_vel:
         if self.game_object.physics is None:
             self.game_object.physics = Physics(self.game_object)
コード例 #22
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()
コード例 #23
0
    def start(self):

        font_path = "game/assets/fonts/neuropolxrg.ttf"

        self.time_to_update_score = 0.095
        self.score_per_step = 1  # Number of steps of the game 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))
コード例 #24
0
 def start(self):
     self.particle_system = ParticleSystem(self,
                                           Particle,
                                           quant=30,
                                           period=0.02,
                                           vel_min=40,
                                           vel_max=80,
                                           duration=2,
                                           gravity=98,
                                           layer=10
                                           )
     self.particle_system.set_circ_gen(self.transform.position,
                                       1, 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.spawn_time = Time.now()
コード例 #25
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 = "game/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
コード例 #26
0
    def get_power_up(self):
        self.sound_collect.play()
        power_up = self.game_object_list[0]
        #Power up text effect
        font_path = "game/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
コード例 #27
0
 def update(self):
     if Time.now() - self.spawn_time > 0.03:
         self.destroy_me()
コード例 #28
0
 def setup_initializer(self):
     self.initial_time = Time.now()
     self.should_initialize = True
コード例 #29
0
 def __init__(self, position, destroy_time=1.0):
     self.destroy_time = destroy_time
     self.creation_time = Time.now()
     self.creator_obj = None
     super().__init__(position=position, radius=1)
コード例 #30
0
 def update(self):
     if Time.now() - self.creation_time > self.destroy_time:
         self.destroy_me()