File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change 11"""Showcase of flying arrows that can stick to objects in a somewhat
22realistic looking way.
33"""
4- import sys
4+ import math
55from typing import List
66
77import pygame
@@ -146,7 +146,10 @@ def main():
146146 mouse_position = pymunk .pygame_util .from_pygame (
147147 Vec2d (* pygame .mouse .get_pos ()), screen
148148 )
149- cannon_body .angle = (mouse_position - cannon_body .position ).angle
149+ cannon_body .angle = max (
150+ - math .pi / 2 ,
151+ min (0 , (mouse_position - cannon_body .position ).angle ),
152+ )
150153 # move the unfired arrow together with the cannon
151154 arrow_body .position = cannon_body .position + Vec2d (
152155 cannon_shape .radius + 40 , 0
@@ -167,7 +170,7 @@ def main():
167170 # around even when fired straight up. Might not be as accurate, but
168171 # maybe look better.
169172 drag_force_magnitude = (
170- (1 - abs (dot )) * flight_speed ** 2 * drag_constant * flying_arrow .mass
173+ (1 - abs (dot )) * flight_speed ** 2 * drag_constant * flying_arrow .mass
171174 )
172175 arrow_tail_position = flying_arrow .position + Vec2d (- 50 , 0 ).rotated (
173176 flying_arrow .angle
@@ -222,4 +225,4 @@ def main():
222225
223226
224227if __name__ == "__main__" :
225- sys . exit ( main () )
228+ main ()
Original file line number Diff line number Diff line change @@ -210,7 +210,7 @@ def main():
210210 (0 , 0 ),
211211 shape .body .world_to_local (nearest ),
212212 )
213- mouse_joint .max_force = 50000
213+ mouse_joint .max_force = 7500
214214 mouse_joint .error_bias = (1 - 0.15 ) ** 60
215215 space .add (mouse_joint )
216216
@@ -249,4 +249,4 @@ def main():
249249
250250
251251if __name__ == "__main__" :
252- main ()
252+ main ()
You can’t perform that action at this time.
0 commit comments