[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Working on a new project, Involves Collision



http://www.pick.ucam.org/~ptc24/brickbats.html
is a basic search for an open-source break-out game.  I think it's even written in pygame.  Anyway, the collision for any such game is not too hard, just check if the ball is inside any box.  Something like:

for box in boxes:
    if abs( ball_x_pos - box.x_pos ) <= 20: #20 is 1/2 the box's width
        if abs( ball_y_pos - box.y_pos ) <= 10: #10 is 1/2 the box's height
            boxes.remove(box())
            score += 100

That's an interesting background, BTW, if you made it.
Ian