File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Problem with writing code. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with writing code." Watch "Problem with writing code." New topic
Author

Problem with writing code.

Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
I can't think of what to do. What I want is the ball to bounce off the paddle if it hits the paddle. The paddle is defined to 80. And then if it doesn't then it keeps going until it hits the edge where I set it so the timer stops. I can't think right as to what to do... its like a brain freeze! How can I set it so that it if it hits the paddles range and bouces off?





Live And Let Learn.
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
set a certain point on the line of the padel to a constant, and:

if (ballX == Paddle2X)//assuming paddle 2 is on the right.
ballX --;
else
ballX ++;

and you can have a Paddle1 constant also, so you can do the same for it.

if(ballX == Paddle1X)//assuming paddle 1 is on the left.
ballX ++;
else
ballX --;

and have this in a timer listener "BallListener" or something like that.

-Justin-

[ May 08, 2006: Message edited by: Justin Fox ]
[ May 08, 2006: Message edited by: Justin Fox ]

You down with OOP? Yeah you know me!
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
Thanks again Justin for your advice. I'm almost done the game!! Now I want to turn the entire screen black when somebody loses. So if X = 0 then fill area black. But I still get flashing form the other objects. I think its because of the timer. How can I fix this with what I have now?

Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
K... fixed that part. Now I have a general question. I want to get rid of the flashing between all of my objects and I have a feeling its because I'm using Timers. My friend said that I may be able to fix it using something buffer? I can't remember what exactly it was but is there some type of buffer that will get rid of the flashing?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I think your friend means double buffering. The basic process is that you create an image offscreen and do all your drawing on it. Then when it is complete you copy the image in memory into the visible area.
 
wood burning stoves
 
subject: Problem with writing code.
 
Similar Threads
Giving Pong Computer Intelligence.
Computer Pad Not Stopping!
Making Y--
Double Buffering Problem
My Games Flashing!!