Sikkepitje.nl

Sikkepitje.nl

this private cloud

DevShack

PyGame

Python programming with PyGame

Keep this under your pillow

Game Media

Sounds

Music

Zowel VLC als Pygame speelt alle klassieke Amiga-formaten, zoals MOD, S3M en XM !

Image

Documentatie

Elastic collision

Fragment uit Rice rocks met ballen met elastische botsing

if len(pong.balls) > 1:
    founded = False
    for ball in pong.balls:
        if founded:
            if self.touch(ball):
                # Elastic collision (with radius as mass)
                sound_balls_collision.play()
                sum = self.radius + ball.radius
                diff = self.radius - ball.radius

                double = 2*ball.radius
                new_x = float(diff*self.vel.x + double*ball.vel.x)/sum
                new_y = float(diff*self.vel.y + double*ball.vel.y)/sum

                double = 2*self.radius
                ball.vel.x = float(double*self.vel.x
                                   - diff*ball.vel.x)/sum
                ball.vel.y = float(double*self.vel.y
                                   - diff*ball.vel.y)/sum

                self.vel.x = new_x
                self.vel.y = new_y
        elif self.same_pos(ball):
            founded = True