| | |
Python Graphics Help
![]() |
•
•
Join Date: Oct 2005
Posts: 5
Reputation:
Solved Threads: 0
Hello, I'm having trouble with a project that I am doing in turtle graphics.
I'm making a graphic of a soccer field with a ball bouncing around, but I want the ball to stop when it hits the net. I can get the ball to stop when it hits the net though, it keeps on bouncing. Any suggestions would be appreciated. The if statement that I am trying to use is
if -100>x>100 and -25>y>25:\
return
and I have an attachment of the work I have done.
I'm making a graphic of a soccer field with a ball bouncing around, but I want the ball to stop when it hits the net. I can get the ball to stop when it hits the net though, it keeps on bouncing. Any suggestions would be appreciated. The if statement that I am trying to use is
if -100>x>100 and -25>y>25:\
return
and I have an attachment of the work I have done.
I am experimenting with your attachment. Please do not mix tabs and spaces for indentations, stick with spaces! A few comments would be nice! It just makes it nicer for other people to use and check your code.
What do you want to use to start the program? Just for initial testing I am using soccer(1000, 1, 30)
You could score goals as your x,y coordinates of the turtle fall within the range of the goal-fronts.
What do you want to use to start the program? Just for initial testing I am using soccer(1000, 1, 30)
You could score goals as your x,y coordinates of the turtle fall within the range of the goal-fronts.
May 'the Google' be with you!
The turtles are active! This is sure an interesting game. I changed the soccer function to this ...
This way you can keep track of right and left goal scores. To make the game more interesting you may want to add a small random bounce to your deflections.
Python Syntax (Toggle Plain Text)
def soccer(num_steps, step_size, heading): turtle.reset() draw_table() top = 100/2 bottom = top * -1 right = 200/2 left = right * -1 turtle.left(heading) leftGoal = 0 rightGoal = 0 for step in range(num_steps): turtle.forward(step_size) x, y = turtle.position() # make the ball/turtle bounce if left >= x or x >= right: turtle.left(180-2*turtle.heading()) else: if y <= bottom or top <= y: turtle.right(2*turtle.heading()) if x <= -100 and -25 <= y <= 25: #print turtle.position() # test leftGoal += 1 print "leftGoal =", leftGoal if x >= 100 and -25 <= y <= 25: #print turtle.position() # test rightGoal += 1 print "rightGoal =", rightGoal print "Final score is right %d and left %d" % (rightGoal, leftGoal)
May 'the Google' be with you!
![]() |
Similar Threads
- Starting Python (Python)
- Python! Thoughts? (Python)
- Tkinter or wxPython? (Python)
- text adventure programming help (Python)
Other Threads in the Python Forum
- Previous Thread: JPEG Base64 Image String (Python)
- Next Thread: Calling c function from python
| Thread Tools | Search this Thread |
alarm ansi app assignment avogadro backend beginner binary bluetooth character cmd customdialog cx-freeze data decimals dictionary directory dynamic error exe file float format function generator getvalue gnu graphics halp heads homework http ideas import input ip itunes java leftmouse line linux list lists loop maintain maze millimeter module mouse number numbers output parsing path pointer port prime programming progressbar push py2exe pygame python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh statistics string strings sudokusolver sum text thread threading time tlapse tuple tutorial ubuntu unicode url urllib urllib2 variable variables ventrilo vigenere web webservice wikipedia write wxpython xlib






