User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jul 2008
Posts: 30
Reputation: besktrap is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
besktrap besktrap is offline Offline
Light Poster

help with pygame lines

  #1  
Jul 21st, 2008
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Location: Durham, NC
Posts: 197
Reputation: jlm699 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 29
jlm699's Avatar
jlm699 jlm699 is offline Offline
Junior Poster

Re: help with pygame lines

  #2  
Jul 22nd, 2008
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. **
Reply With Quote  
Join Date: Jul 2008
Posts: 30
Reputation: besktrap is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
besktrap besktrap is offline Offline
Light Poster

Re: help with pygame lines

  #3  
Jul 22nd, 2008
Any idea where I could get some example code for something like this?
Reply With Quote  
Join Date: Apr 2008
Posts: 26
Reputation: FreezeBlink is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
FreezeBlink FreezeBlink is offline Offline
Light Poster

Re: help with pygame lines

  #4  
Jul 22nd, 2008
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.
Reply With Quote  
Join Date: Jul 2008
Posts: 30
Reputation: besktrap is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
besktrap besktrap is offline Offline
Light Poster

Re: help with pygame lines

  #5  
Jul 22nd, 2008
as of right now, the square is just x and y. No rotations.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 10:58 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC