- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
def find_where_ball_collides_on_a_wall(
ball_w, ball_z,
ball_wol, ball_zol,
ball_rad,
wall_type,
wall_w1, wall_z1,
wall_w2, wall_z2,
wall_rad):
toetoadly = ball_rad + wall_rad
did_collide = False
New_ball_w = ball_w + ball_wol
New_ball_z = ball_z + ball_zol
angle_hit_at = None
Relate_ball_w = ball_w - wall_w1
Relate_ball_z = ball_z - wall_z1
Relate_wall_w2 = wall_w2 - wall_w1
Relate_wall_z2 = wall_z2 - wall_z1
arc_tangeriney = arc_tangent_2D(Relate_wall_w2, Relate_wall_z2)
Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_Relate_wall_w2, Rotate_Relate_wall_z2 = points_rotated_by_angle_2D(((Relate_ball_w, Relate_ball_z), (Relate_wall_w2, Relate_wall_z2)), 0, 0, arc_tangeriney)
Rotate_ball_wol, Rotate_ball_zol = point_rotated_by_angle_2D(ball_wol, ball_zol, 0, 0, arc_tangeriney)
Rotate_Relate_ball_collide_w, Rotate_Relate_ball_collide_z, did_hit_weird_line = Find_where_ball_stops_on_line_w(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, ball_rad, 0, wall_rad)
if Rotate_Relate_ball_w > -toetoadly and Rotate_Relate_ball_w < toetoadly:
HE_HE_strange_popper_z = Rotate_Relate_ball_z
else:
HE_HE_strange_popper_z = Rotate_Relate_ball_collide_z
Rotate_angle_hit_at = None
if HE_HE_strange_popper_z < Rotate_Relate_wall_z2:
if ball_is_going_towards_point(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, 0, Rotate_Relate_wall_z2):
p1_touched, p1_collide_w, p1_collide_z, p1_angle_hit_at = find_where_ball_collides_on_another_ball(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, ball_rad, 0, Rotate_Relate_wall_z2, wall_rad)
if p1_touched:
Rotate_Relate_ball_collide_w = p1_collide_w
Rotate_Relate_ball_collide_z = p1_collide_z
Rotate_angle_hit_at = p1_angle_hit_at
did_collide = True
elif HE_HE_strange_popper_z > 0:
if ball_is_going_towards_point(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, 0, 0):
p2_touched, p2_collide_w, p2_collide_z, p2_angle_hit_at = find_where_ball_collides_on_another_ball(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, ball_rad, 0, 0, wall_rad)
if p2_touched:
Rotate_Relate_ball_collide_w = p2_collide_w
Rotate_Relate_ball_collide_z = p2_collide_z
Rotate_angle_hit_at = p2_angle_hit_at
did_collide = True
else:
if did_hit_weird_line:
did_collide = True
if Rotate_Relate_ball_collide_w < 0: Rotate_angle_hit_at = 90
else: Rotate_angle_hit_at = 270
if did_collide:
arc_tangeriney_2 = -arc_tangeriney
angle_hit_at = Rotate_angle_hit_at + arc_tangeriney
New_ball_w, New_ball_z = point_rotated_by_angle_2D(Rotate_Relate_ball_collide_w, Rotate_Relate_ball_collide_z, 0, 0, arc_tangeriney_2)
New_ball_w += wall_w1
New_ball_z += wall_z1
return did_collide, New_ball_w, New_ball_z, angle_hit_at #, is_moving_towards
Пример написания "физики" на python + pygame. Одна из функций. Всего кода - 900+ строк.
http://www.pygame.org/docs/ref/draw.html -> смотрим комментарий к pygame.draw.circle
guest 30.09.2009 11:46 # 0
diok 30.09.2009 11:56 # 0
yvu 30.09.2009 14:08 # 0
guest 30.09.2009 20:44 # 0
guest 01.10.2009 09:43 # +1
bildja 04.10.2009 02:05 # +1
guest 06.10.2009 14:36 # 0
guest 29.11.2009 02:05 # 0
guest 29.11.2009 02:05 # +1
dicos 11.12.2009 18:19 # 0
4cppMan 22.12.2009 22:24 # −2