Thread: Ping pong game
View Single Post
  #2 (permalink)  
Old 03-18-2008, 06:55 PM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Declare "box" as a member variable and use setLocation to move/position it in the paint method.
Code:
int appletsize_x = 300; int appletsize_y = 300; Rectangle box = new Rectangle(60, 25); Graphics2D g2 = (Graphics2D) g; box.setLocation(x_pos,y_pos); g2.draw(box);
Then when it is time for collision–checking in your ball Runnable you can get access to the box as an obstacle with
Code:
int minX = box.x; int maxX = box.x + box.width; int maxY = box.y + box.height;
Reply With Quote