Created
January 19, 2011 14:49
-
-
Save anonymous/786255 to your computer and use it in GitHub Desktop.
for maryrosecook and pistol slut
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def DetectCollision(grenade, obj): | |
hgw = grenade.width / 2 # half grenade width | |
hgh = grenade.height / 2 | |
aug_obj = Rectangle(obj.x1 - hgw, obj.y1 - hgh, | |
obj.x2 + hgw, obj.y2 + hgh) | |
if aug_obj.contains(grenade.center): | |
BounceGrenade(grenade, aug_obj) | |
def BounceGrenade(grenade, aug_obj): | |
vsegs = [Segment(aug_obj.x1, aug_obj.y1, aug_obj.x1, aug_obj.y2), | |
Segment(aug_obj.x2, aug_obj.y1, aug_obj.x2, aug_obj.y2)] | |
hsegs = [Segment(aug_obj.x1, aug_obj.y1, aug_obj.x2, aug_obj.y1), | |
Segment(aug_obj.x1, aug_obj.y2, aug_obj.x2, aug_obj.y2)] | |
trajectory = Segment(grenade.last_center, grenade.center) | |
for seg in vsegs: | |
if trajectory.intersect(seg): | |
distance_into_obj = grenade.center - seg.x1 | |
grenade.center -= Vector(2 * distance_into_obj, 0) | |
return | |
for seg in hsegs: | |
if trajectory.intersect(seg): | |
distance_into_obj = grenade.center - seg.y1 | |
grenade.center -= Vector(0, 2 * distance_into_obj) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment