0

I'm writing a gravity simulation in python and pygame, and had a quick question. Say I have an object that I can move. Lets call it "square". Then I created a line like so...

pygame.draw.line(screen, (0, 0, 0), (84, 368), (510, 368))

How would I tell python not to let "square" go through the line?:?:

3
Contributors
4
Replies
6
Views
10 Years
Discussion Span
Last Post by besktrap
0

You would need to keep track of the boundary of 'square', which would be the leading edge of movement (this gets really complicated if square is rotating while falling), and then do a comparison to make sure that the leading edge isn't at the line... if it is past the line either stop movement or reverse the direction with the proper exit angle, momentum, and kinetic energy.

0

Any idea where I could get some example code for something like this?

0

What you're looking for is collision checking. Off the top of my head, I don't have any examples of it, but a search on 'Python Square Collision Checking' or something like that might turn up an answer.

Will the square rotate, or will it always be aligned with the x/y axes? Because if it doesn't rotate, it would be much simpler to simulate.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.