

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Color;

public class Ball {

   private static final int DIAMETER = 80;
   int x = (int) (Math.random()*2000)+1000 ;
   int y =(int) (Math.random()*2000)+1000  ;
   int xa = 1;
   int ya = 1;
   private Game game;
   
   
   public Ball(Game game) {
      this.game= game;
      
   
   }

   void move() {
      if (x + xa < 0)
         xa = 1;
         
      if (x + xa > game.getWidth() - DIAMETER)
         xa = -1;
         
      if (y + ya < 0)
         ya = 1;
         
      if (y + ya > game.getHeight() - DIAMETER)
         ya = -1;
   
         
      if (collision()){
         game.gameOver();
      }
      x = x + xa;
      y = y + ya;
   }
   
   private boolean collisionbox() {
      return game.ball.getBounds().intersects(getBounds());
   }

   private boolean collision() {
      return game.player.getBounds().intersects(getBounds());
   }

   public void paint(Graphics2D g) {
      g.setColor(Color.red);  
      g.fillOval(x, y, DIAMETER, DIAMETER);
   }
	
   public Rectangle getBounds() {
      return new Rectangle(x, y, DIAMETER, DIAMETER);
   }
}