Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with writing code.

 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic