Python Graphics Help

Reply

Join Date: Oct 2005
Posts: 5
Reputation: qwester is an unknown quantity at this point 
Solved Threads: 0
qwester qwester is offline Offline
Newbie Poster

Python Graphics Help

 
0
  #1
Oct 6th, 2005
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.
Attached Files
File Type: zip jm_soccer.zip (813 Bytes, 27 views)
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,959
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 917
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Python Graphics Help

 
0
  #2
Oct 6th, 2005
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.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,959
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 917
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Python Graphics Help

 
0
  #3
Oct 6th, 2005
The turtles are active! This is sure an interesting game. I changed the soccer function to this ...
  1. def soccer(num_steps, step_size, heading):
  2. turtle.reset()
  3. draw_table()
  4. top = 100/2
  5. bottom = top * -1
  6. right = 200/2
  7. left = right * -1
  8. turtle.left(heading)
  9. leftGoal = 0
  10. rightGoal = 0
  11. for step in range(num_steps):
  12. turtle.forward(step_size)
  13. x, y = turtle.position()
  14. # make the ball/turtle bounce
  15. if left >= x or x >= right:
  16. turtle.left(180-2*turtle.heading())
  17. else:
  18. if y <= bottom or top <= y:
  19. turtle.right(2*turtle.heading())
  20. if x <= -100 and -25 <= y <= 25:
  21. #print turtle.position() # test
  22. leftGoal += 1
  23. print "leftGoal =", leftGoal
  24. if x >= 100 and -25 <= y <= 25:
  25. #print turtle.position() # test
  26. rightGoal += 1
  27. print "rightGoal =", rightGoal
  28. print "Final score is right %d and left %d" % (rightGoal, leftGoal)
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.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Python Graphics Help

 
0
  #4
Oct 7th, 2005
Originally Posted by vegaseat
Please do not mix tabs and spaces for indentations, stick with spaces!
I usually use the option "fill tabs with spaces" . Most editers offer this.
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 137
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: Python Graphics Help

 
0
  #5
Oct 7th, 2005
I have use the space/tab feature too, but don't always know how many spaces each tab is.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC