| | |
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 |
abrupt alarm ansi anti apache approximation array assignment backend beginner binary bluetooth builtin calculator character cmd converter countpasswordentry curved customdialog cx-freeze dan08 data decimals dictionary directory exe file float format function gnu halp heads homework http ideas inches input itunes java leftmouse library line lines linux list lists loop module mouse mysqlquery number numbers numeric output parsing path phonebook pointer prime programming push py2exe pygame python random recursion redirect schedule screensaverloopinactive script scrolledtext software sqlite ssh statictext statistics string strings sudokusolver terminal text thread time tlapse tuple twoup ubuntu unicode urllib urllib2 variable ventrilo webservice wikipedia wordgame write wxpython xlib






