public void draw() //Draw ball
{
if (runBall == true)
{
Graphics g = box.getGraphics();
//g.setXORMode(box.getBackground());
g.drawImage(new ImageIcon("C:\\Junaid Java\\Junaid Java ISU\\Pics\\cannon 1.gif").getImage(), 0, 350, null);
g.dispose();
}
else if(runEnemy == true)
{
Graphics e = box.getGraphics();
e.drawOval(xE,yE,xELength,yELength);
e.dispose();
}
}
//////////////////////////////////////////////////
/*This is how the ball will move - Speed of ball*/
//////////////////////////////////////////////////
public void moveBall()
{
if (runBall == true)
{
elapsed = System.currentTimeMillis() - start; //Current time
if (!box.isVisible())
return;
/*Set Ball*/
Graphics g = box.getGraphics();
g.setXORMode(box.getBackground()); //Removes trail of the ball
g.fillOval(x, y, xLength, yLength);
if (xE - x <= sumR)
{
//hit = true;
//dxE = 0;
return;
}
///////////////////////////
/*Speed of ball*/
x += dx;
y += dy;
Dimension d = box.getSize();
///////////////////////////
/*Change velocity of ball*/
///////////////////////////
if (x>= 615 || y>= 390)
{
dx = 0;
dy = 0;
}
else
{
if (x>=0)
{
dx = (Math.cos((Math.toRadians(angle)))) * velocity + windX; //X Speed
}
dy = (Math.sin((Math.toRadians(angle)))) * velocity + ((windY + (accelY * (elapsed))) * 0.0005); //Y Speed
}
g.fillOval(x, y, xLength, yLength);
g.dispose();
runEnemy = false;
}
}
public void moveEnemy()
{
int i = 0;
if (runEnemy == true)
{
if (!box.isVisible())
return;
/*Set enemy*/
/////////////
Graphics e = box.getGraphics();
e.setXORMode(box.getBackground());
e.drawOval(xE,yE,xELength,yELength);
xE += dxE;
//yE += dyE;
Dimension d = box.getSize();
////////////////////////////
/*Change velocity of enemy*/
////////////////////////////
if(xE >= 600)
{
dxE *= -1;
}
else if(xE <= 50)
{
dxE *= -1;
}
e.drawOval(xE, yE, xELength, yELength);
runBall = false;
}
} |