package breakout;

import cs101.awt.*;
import cs101.io.*;
import cs101.lang.*;
import java.awt.Point;
import java.awt.Color;
import java.awt.Graphics;


/*other players balls are drawn as ghost ball
 *added to the ballrepository
 *appears to be moving because reading its center off the network*/
public class GhostBall implements BreakOutBall
{	
	ScreenCanvas screen;
	BrickRepository brickrepos;
	BallRepository ballrepos;
	Point center = new Point(0,0);
	public double radius=6.0, xVel, yVel;
	public int ballType;
	
	//constructor - instances created by ballrepository's makeghostball method
	public GhostBall (ScreenCanvas screen, BrickRepository brickrepos,
						BallRepository ballrepos, int centerX,
						int centerY, 
						int ballType)
	{
		this.screen = screen;
		this.brickrepos = brickrepos;
		this.ballrepos = ballrepos;
		//this.xVel = xVel;
		//this.yVel = yVel;
		this.center.setLocation (centerX, centerY);
		this.ballType = ballType;
	}
	
	public Point getCenter()
	{
		return this.center;
	}
	
	public void changeCenter(int x, int y)
	{
		this.center.setLocation(x, y);
	}
	
	public double getRadius()
	{
		return this.radius;
	}
	
	public double getXvelocity()
	{
		return this.xVel;
	}
	
	public double getYvelocity()
	{
		return this.yVel;
	}
	
	public void changeXvelocity(double xVel)
	{
		this.xVel = xVel;
	}
	
	public void changeYvelocity(double yVel)
	{
		this.yVel = yVel;
	}
	
	public void paintGhostBall(Graphics g)
	{
		if ( (this.center.y+this.radius) >= (this.screen.getMaxY()) ) //if hits bottom
		{
			//when ghostball is a ghost for a classicball thats multiple deletes the ball
			if (this.ballType == Constants.DEL_BALL)
			{
				this.ballrepos.deleteBall(this);
			}
		}
		
		if ( (this.center.y-this.radius) < 140) //checks to see if ball has hit bricks
														// only if in range of bricks
		{
			this.brickrepos.checkGhostHit(this);
			
		}
		
		double xCorner = this.center.getX() - radius;
		double yCorner = this.center.getY() - radius;
		g.setColor(Color.lightGray);
		g.fillOval((int)xCorner, (int)yCorner, (int)(2*radius), (int)(2*radius));
	}
	

}