• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Problem with writing code.

 
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?



 
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?
 
Ranch Hand
Posts: 2410
  • 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.
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic