Beispiel #1
0
 def move_object(self, physics_object):
     """accelerate the object towards the maximum velocity vector"""
     
     if not isinstance(physics_object, Object):
         raise Exception("physics_object must be of type physics.Object.  Got: " + physics_object.__class__())
     
     x_object_velocity = physics_object.velocity[0]
     y_object_velocity = physics_object.velocity[1]
     
     x_acceleration = self.acceleration_vector[0]
     y_acceleration = self.acceleration_vector[1]
     
     if x_acceleration != self.velocity_vector[0]:
         
         x_acceleration_vector = min(
             abs(self.velocity_vector[0] - x_object_velocity),
             abs(x_acceleration)
         ) * mathfuncs.sign(x_acceleration)
         
         physics_object.accelerate(x_acceleration, 0)
     
     if y_acceleration != self.velocity_vector[1]:
         
         x_acceleration_vector = min(
             abs(self.velocity_vector[1] - y_object_velocity),
             abs(y_acceleration)
         ) * mathfuncs.sign(y_acceleration)
         
         physics_object.accelerate(0, y_acceleration)
    def test_delta_change(self, animation, point_name, frame_index):
        delta = animation.animation_deltas[frame_index][point_name]
        last_delta = animation.animation_deltas[frame_index - 1][point_name]

        if mathfuncs.sign(delta[0]) != mathfuncs.sign(last_delta[0]):
            # or mathfuncs.sign(delta[1]) != mathfuncs.sign(last_delta[1])):
            return True
        else:
            return False
Beispiel #3
0
 def create_collision_effects(self, attack_result_rendering_info):
     
     attack_knockback_vector = attack_result_rendering_info.knockback_vector
     
     damage = attack_result_rendering_info.attack_damage
     effect_height = max(50, damage)
     effect_width = max(50, .2 * damage)
     fade_rate = .2
     
     angle_in_degrees = 0
     
     if attack_knockback_vector[0] == 0:
         if mathfuncs.sign(attack_knockback_vector[1]) == 1:
             angle_in_degrees = 0
         else:
             angle_in_degrees = 180
             
     elif attack_knockback_vector[1] == 0:
         if mathfuncs.sign(attack_knockback_vector[0]) == 1:
             angle_in_degrees = 90
         else:
             angle_in_degrees = 270
         
     else:
         angle_in_degrees = math.degrees(
             math.asin(attack_knockback_vector[1] / math.hypot(
                     attack_knockback_vector[0], attack_knockback_vector[1]
                 )
             )
         )
     
     attack_point = attack_result_rendering_info.attack_point
     if not attack_point.id in self.point_effects:
         if attack_result_rendering_info.clash_indicator:
             self.point_effects[attack_point.id] = ClashEffect(
                 attack_result_rendering_info.clash_position,
                 angle_in_degrees,
                 effect_width,
                 effect_height,
                 .7,
                 fade_rate,
                 1
             )
         else:
             self.point_effects[attack_point.id] = HitEffect(
                 attack_result_rendering_info.attack_point.pos,
                 angle_in_degrees,
                 effect_width,
                 effect_height,
                 .7,
                 fade_rate,
                 .6
             )
Beispiel #4
0
 def apply_physics(self, duration, gravity = True):
     
     system = []
     
     self.set_velocity(duration)
     self.model.resolve_self(duration, gravity)
     
     if (self.is_aerial() == False or 
     self.get_player_state() in [PlayerStates.WALKING, PlayerStates.RUNNING, PlayerStates.CROUCHING, PlayerStates.STANDING, PlayerStates.LANDING]):
         system.append(gamestate.stage.ground)
         
         if (((self.action.action_state == PlayerStates.FLOATING)
         or  (self.action.action_state == PlayerStates.JUMPING)) and
         (mathfuncs.sign(self.model.velocity[1]) > 0)):
             self.transition(self.actions[PlayerStates.LANDING])
     
     if self.model.orientation == physics.Orientations.FACING_RIGHT:
         if self.model.position[0] + self.model.width > gamestate.stage.right_wall.position[0]:
             system.append(gamestate.stage.right_wall)
     elif self.model.orientation == physics.Orientations.FACING_LEFT:
         if self.model.position[0] > gamestate.stage.right_wall.position[0]:
             system.append(gamestate.stage.right_wall)
     
     if self.model.orientation == physics.Orientations.FACING_RIGHT:
         if self.model.position[0] < gamestate.stage.left_wall.position[0]:
             system.append(gamestate.stage.left_wall)
     elif self.model.orientation == physics.Orientations.FACING_LEFT:
         if self.model.position[0] - self.model.width < gamestate.stage.left_wall.position[0]:
             system.append(gamestate.stage.left_wall)
     
     self.model.resolve_system(system, duration)
 def collide(self, object, duration):
     """Accelerate an object that collides with the ground"""
     x_velocity = object.velocity[0]
     y_velocity = object.velocity[1]
     
     if x_velocity != 0:
         #apply friction to object
         friction_sign = -1 * mathfuncs.sign(x_velocity)
         x_velocity = x_velocity + (friction_sign*self.friction*duration)
         
         #stop if the x velocity changes sign as a result of friction
         if mathfuncs.sign(x_velocity) == friction_sign:
             x_velocity = 0
     
     if object.velocity[1] > 0:
         #apply an equal and opposite force to gravity
         y_velocity = 0
     
     object.velocity = (x_velocity,y_velocity)
     
     if object.position[1] + object.height > self.position[1]:
         object.shift((0, (self.position[1] - object.height) - object.position[1]))