473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to bounce a ball within a square?

I am doing a project of creating a playing pool and 2 balls bouncing within the pool. I have tried to use "while loop" and "if statement" to set restriction limiting the ball not to bounce out of the pool. However, the ball doesn't move or bounce.

It moves but stops after it hits one of the walls when I write this function below:
Expand|Select|Wrap|Line Numbers
  1. def move_ball(heading):
  2.     t1=turtle.Pen()
  3.     t1.color("yellow")
  4.     t1.shape("circle")
  5.     x,y=turtle.position()
  6.     while 200 > (t1.xcor()) >-200 and -90< (t1.ycor())<90:
  7.         t1.forward(1)
  8.         t1.setheading(heading)  
But, it doesn't move at all when I write this function below:
Expand|Select|Wrap|Line Numbers
  1. # here I try to do all restrictions of 4 walls  
  2.  
  3. # just 2 walls here
  4.  
  5. def wall_bottom(heading):
  6.     t1=turtle.Pen()
  7.     t1.color("yellow")
  8.     t1.shape("circle")
  9.     current=0
  10.     if 100<t1.ycor()<-100:
  11.         if 270 < t1.setheading() < 360:
  12.             t1.forward(1)
  13.             t1.setheading(0+(360-(t1.heading())))
  14.         else:
  15.             t1.forward(1)
  16.             t1.setheading(180-(t1.heading()-180))
  17.  
  18. def wall_top(heading):
  19.     t1=turtle.Pen()
  20.     t1.color("yellow")
  21.     t1.shape("circle")
  22.     if 200> t1.xcor() >-200:
  23.         if 90> t1.setheading()<0:
  24.             t1.forward(1)
  25.             t1.setheading(0-(180-(t1.heading())))
  26.         else:
  27.             t1.forward(1)
  28.             t1.setheading(180-(t1.heading()-180))
I don't know if I am doing the right things. This is so confusing. Please Help me for this. I want the ball bounce. Thanks!
Feb 16 '09 #1
0 1937

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bloon | last post by:
I have a question that how to debug a program only having .exe file. Is there any techniques or tools that can do that? Thanks a lot.
12
by: Gerard Flanagan | last post by:
Hello I'm pretty new to Python and was wondering why the 'Square' method in the following code doesn't work. It doesn't fail, just doesn't do anything ( at least, not what I'd like! ). Why...
2
by: Arjen | last post by:
Hello, When I send an e-mail to this sample e-mail address sample@mail.com then there are three options. 1. The e-mail comes over; 2. The e-mail bounce, because the e-mail address doesn't...
3
by: Darren Clark | last post by:
HI, I am after some assistance in finding what is the best way to parse through bounce back text...... because each server is different i cant really depend on Line x being the line where the...
2
by: Phlip | last post by:
Newsgroupies: One myth about USENET is that each group has a charter; some "official" list of on-topic concepts. When a post arrives "violating" this myth, the replies that support the myth can...
8
by: bevanward | last post by:
Hi all I have a large data set of points situated in 3d space. I have a simple primary key and an x, y and z value. What I would like is an efficient method for finding the group of points...
7
by: Bigs | last post by:
Source: http://fileho.com/download/120846695042/bounce2.zip.html How would I go about making a wall for my bouncing ball? For example if the ball hit the center box it would bounce.
2
by: SilentCodingOne | last post by:
I have a application where each time you click the add ball button a new randomly colored ball is added to the jpanel. It works fine except that the balls suddenly stop at the same spot. I want them...
18
by: Grant Edwards | last post by:
Could whoever is responsible for the gateway that is grabbing my postings off of Usenet and e-mailing them out please fix the headers in the mail messages so that I don't get the bounce messages?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.