473,394 Members | 1,828 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,394 software developers and data experts.

Wall ball bounce

8
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.
Jun 1 '07 #1
7 3950
r035198x
13,262 8TB
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.
Well, I'm not going to download those files and I know a few others who wont as well. It's better if you tell us what characteristics you want your wall to have. The bouncing can be controlled by tracking the position of the ball on the canvas (or whatever it is you are using) and changing the direction of the ball as soon as it enters certain coordinates. You can even make the wall invisible.
Jun 1 '07 #2
Bigs
8
Well, I'm not going to download those files and I know a few others who wont as well. It's better if you tell us what characteristics you want your wall to have. The bouncing can be controlled by tracking the position of the ball on the canvas (or whatever it is you are using) and changing the direction of the ball as soon as it enters certain coordinates. You can even make the wall invisible.
It is a little hard to describe without actually seeing it. Well, basically I have two boxes:
Expand|Select|Wrap|Line Numbers
  1.        g.drawRect(10,0,950,500);
  2.        g.drawRect(350,170,200,150);
One box inside the other, right now the ball will bounce inside the first box, but the part I am having trouble with is making the inside box also make the ball bounce when hit.

For the first box I just took the x or y and then changed direction example:
Expand|Select|Wrap|Line Numbers
  1.          if  (x > 910)                 /** bounces back left when x = 910 */   
  2.          {dir = dir - 2;}
But, because the other box is on the inside it will not work. I need to find out how to add walls that the ball will bounce off of. Preferably something that will not require at lot of check for the ball going into a certain point. But, anything that works would be great.
Jun 1 '07 #3
r035198x
13,262 8TB
It is a little hard to describe without actually seeing it. Well, basically I have two boxes:
Expand|Select|Wrap|Line Numbers
  1.      g.drawRect(10,0,950,500);
  2.      g.drawRect(350,170,200,150);
One box inside the other, right now the ball will bounce inside the first box, but the part I am having trouble with is making the inside box also make the ball bounce when hit.

For the first box I just took the x or y and then changed direction example:
Expand|Select|Wrap|Line Numbers
  1. if (x > 910) /** bounces back left when x = 910 */ 
  2. {dir = dir - 2;}
But, because the other box is on the inside it will not work. I need to find out how to add walls that the ball will bounce off of. Preferably something that will not require at lot of check for the ball going into a certain point. But, anything that works would be great.
I still don't get the problem. What's different for the second box except for the co-ordinates? Can't you do it the same way you did with the first box?
Jun 1 '07 #4
Bigs
8
I still don't get the problem. What's different for the second box except for the co-ordinates? Can't you do it the same way you did with the first box?
The box is inside the other box. The reason I cant do it the same way is because it would be blocking the ball from moving freely in the first box because it would section off the entire area from that point. Think of it this way I have a pool of water and there is an island inside the pool.
Jun 1 '07 #5
r035198x
13,262 8TB
The box is inside the other box. The reason I cant do it the same way is because it would be blocking the ball from moving freely in the first box because it would section off the entire area from that point. Think of it this way I have a pool of water and there is an island inside the pool.
Ok. What's wrong with using :
The leftmost side of the box is at 350 + 200 = 550.
Expand|Select|Wrap|Line Numbers
  1.  if (x > 550) /** bounces back left when x = 550 */  { 
  2.  
  3. dir = dir - 2;
  4.  
  5. }
  6.  
  7.  
Jun 1 '07 #6
Bigs
8
It is because it is still counting for both inside and outside, box.
For example it may hit the inside box point and bounce but the program is also considering the entire point from there on. Making a line across causing the ball to bounce before it touches an outside corner as well. Bouncing off nothing.


Could you please look at the full program code, it is kind of hard to explain in words.
Jun 1 '07 #7
r035198x
13,262 8TB
It is because it is still counting for both inside and outside, box.
For example it may hit the inside box point and bounce but the program is also considering the entire point from there on. Making a line across causing the ball to bounce before it touches an outside corner as well. Bouncing off nothing.

Could you please look at the full program code, it is kind of hard to explain in words.
So you don't want the ball to get into the inner box?
You need to test both the x position and the y position deepending on the direction of the ball. e.g if the ball is travelling from left to right, do

if x >= 550 and if y is between 20 and 170 then move the ball back to the left
Jun 1 '07 #8

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.
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...
1
ilikepython
by: ilikepython | last post by:
Hi, I made a pong game with pygame. It works pretty good but I want the ball to bounce realistically. Just like in real pong when it bounces off the right edge it goes to the right and when it...
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: andreachilam | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.