•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 423,657 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,185 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 204 | Replies: 4
![]() |
•
•
Join Date: Jul 2008
Posts: 30
Reputation:
Rep Power: 1
Solved Threads: 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...
How would I tell python not to let "square" go through the line?
pygame.draw.line(screen, (0, 0, 0), (84, 368), (510, 368))
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.
Let's Go Pens!
** Just because I reply to your question does not invite you to PM me. Keep discussions on the thread of topic, I will not answer your questions over PM. **
** Just because I reply to your question does not invite you to PM me. Keep discussions on the thread of topic, I will not answer your questions over PM. **
•
•
Join Date: Apr 2008
Posts: 26
Reputation:
Rep Power: 1
Solved Threads: 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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Starting Python (Python)
- Projects for the Beginner (Python)
- New Code Snippet: Game of Life (Python)
Other Threads in the Python Forum
- Previous Thread: class question
- Next Thread: Creating EXCEL file using Python Script


Linear Mode