Esempio n. 1
0
 def __update_velocity(self):
     self.velocity.x = self.velocity.x + (
         self.acceleration.x *
         Time.delta_time(self.unscaled, self.game_object.time_scale))
     self.velocity.y = self.velocity.y + (
         (self.acceleration.y + self.gravity) *
         Time.delta_time(self.unscaled, self.game_object.time_scale))
Esempio n. 2
0
 def __update_position(self):
     new_position = Vector2(
         self.transform.position.x +
         (self.velocity.x *
          Time.delta_time(self.unscaled, self.game_object.time_scale)),
         self.transform.position.y +
         (self.velocity.y *
          Time.delta_time(self.unscaled, self.game_object.time_scale)))
     self.transform.translate(new_position)
Esempio n. 3
0
    def fall(self, obstacle):
        new_x = obstacle.transform.position.x + self.translate_velocity \
                * Time.delta_time() * obstacle.vel

        if new_x > Constants.screen_width - self.obstacle_size/2 \
                or new_x < -self.obstacle_size/2:
            obstacle.vel *= -1
        obstacle.transform.position = Vector2(
            new_x, obstacle.transform.position.y +
            self.fall_velocity * Time.delta_time())
Esempio n. 4
0
    def fall(self, obstacle_pair):
        visible_condition = 0.1 * Constants.screen_height < obstacle_pair[1].transform.position.y < 0.45 * Constants.screen_height
        if visible_condition:
            obstacle_pair[1].transform.position = Vector2(obstacle_pair[1].transform.position.x,
                                                          obstacle_pair[1].transform.position.y
                                                  + 4 * self.fall_velocity * Time.delta_time())
        else:
            obstacle_pair[1].transform.position = Vector2(obstacle_pair[1].transform.position.x,
                                                          obstacle_pair[1].transform.position.y
                                        + self.fall_velocity * Time.delta_time())

        obstacle_pair[0].transform.position = Vector2(obstacle_pair[0].transform.position.x,
                                                      obstacle_pair[0].transform.position.y
                                                      + self.fall_velocity * Time.delta_time())
Esempio n. 5
0
 def __init__(self,
              game_object,
              mass=None,
              gravity=0,
              velocity=Vector2(0, 0),
              acceleration=Vector2(0, 0),
              angular_velocity=0,
              angular_acceleration=0,
              unscaled=False):
     super(Physics, self).__init__(game_object)
     gravity *= 10
     self.mass = mass
     self.velocity = velocity
     self.acceleration = acceleration
     self.angular_velocity = angular_velocity
     self.angular_acceleration = angular_acceleration
     self.unscaled = unscaled
     self.gravity = gravity
     self.inst_velocity = velocity
     p = self.transform.position
     t = Time.delta_time(self.unscaled, self.game_object.time_scale)
     self.position_vect = [
         Vector2(p.x, p.y),
         Vector2(p.x, p.y),
         Vector2(p.x, p.y)
     ]
     self.time_vect = [t, t, t]
Esempio n. 6
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()
Esempio n. 7
0
 def fall(self):
     """
     make the rectangle fall with constant velocity
     """
     self.transform.translate(
         Vector2(
             self.transform.position.x, self.transform.position.y +
             self.fall_velocity * Time.delta_time()))
Esempio n. 8
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)
Esempio n. 9
0
 def __update_inst_velocity(self):
     del self.time_vect[0]
     self.time_vect.append(
         Time.delta_time(self.unscaled, self.game_object.time_scale))
     del self.position_vect[0]
     self.position_vect.append(
         Vector2(self.transform.position.x, self.transform.position.y))
     dir = self.position_vect[2] - self.position_vect[0]
     t = self.time_vect[0] + self.time_vect[1] + self.time_vect[2]
     if t == 0:
         self.inst_velocity = Vector2(0, 0)
     else:
         self.inst_velocity = dir / t
Esempio n. 10
0
    def update(self):
        """
        Method that will run every frame while this animation is running
        """
        self.current_animation_time += Time.delta_time(
            self.unscaled, self.game_object.time_scale)
        if self.should_change_key_frame():

            # todo remove this set interpolation

            self.__set_interpolation(
                self.key_frames[self.current_kf_idx].interpolation)
            self.__play_on_each_parameter()
        else:
            self.__next_key()
            self.new_frame = True
            self.__set_interpolation(
                self.key_frames[self.current_kf_idx].interpolation)
            self.__play_on_each_parameter()
Esempio n. 11
0
 def __is_end_of_key_frame(self):
     """
     Verify if it is the end of a keyframe
     """
     return abs(self.current_animation_time - self.key_frames[self.current_kf_idx + 1].time)\
            < Time.delta_time(self.unscaled, self.game_object.time_scale) * (3 / 2)
Esempio n. 12
0
 def fall(self, obstacle):
     obstacle.fall(self.fall_velocity * Time.delta_time(),
                   self.angular_speed * Time.delta_time())
Esempio n. 13
0
 def __update_rotation(self):
     self.transform.rotate(
         self.angular_velocity *
         Time.delta_time(self.unscaled, self.game_object.time_scale))
Esempio n. 14
0
 def fall(self, obstacle):
     obstacle.transform.position = Vector2(
         obstacle.transform.position.x, obstacle.transform.position.y +
         self.fall_velocity * Time.delta_time())
     obstacle.transform.rotate(self.angular_speed * Time.delta_time() *
                               obstacle.side)
Esempio n. 15
0
 def fall(self, obstacle):
     obstacle.transform.position.y = obstacle.transform.position.y + (
         self.fall_velocity * Time.delta_time())
Esempio n. 16
0
 def fall(self, obstacle):
     obstacle.transform.position = Vector2(
         obstacle.transform.position.x, obstacle.transform.position.y +
         self.fall_velocity * Time.delta_time())
Esempio n. 17
0
 def __update_angular_velocity(self):
     self.angular_velocity = self.angular_velocity + (
         self.angular_acceleration *
         Time.delta_time(self.unscaled, self.game_object.time_scale))
Esempio n. 18
0
 def turn_left(self):
     self.angle = (self.angle - self.angularSpeed * Time.delta_time()) % (2 * math.pi)
     self.update_circles()