Rotating objects in Java Applets
I am trying to create an Archer in Java.
I want to create an Archer that fires an arrow onto a trajectory path. The trajectory can be changed by pressing the "UP" or "DOWN" arrow key. This will move the arm up and down.
I created the Archer graphic. Its a simple network of lines. To correctly move the Arm to the right cordinate, I solved for the x cordinante of a circle (x-h)^2 + (y-k)^2. That was simple enough. When I change the value for the Y (what you control with the arrow keys) the Arm maintains its size and moves the proper place.
I want to mount a bow on the arm. The endpoint of the line for my arm is in the correct place, but if I place a bow on the arm it remains in the same spot. Is there a way to rotate objects in Java? I already move the arm in place, but to calculate the positions on the bow lines requires calculus... I have to find the tangent line to a circle and thats just to attach a single line to the bow... not to mention making a more complex bow. How do you rotate objects? Thats my main question. Is there a method I can call that I can rotate the rest of the object with? Is there any simpler method of undertaking this task? Its impossible that there isn't... theres so many simple flash games and I think I remember that my guns never skewed when I waved them up and down.
Help would bee appreciated
public class Archer
private double x;
private double y;
private double armY;
private double armX;
private double armxcord;
private double armycord;
private double bowslopex;
private double bowslopey;
public Archer(double aX, double aY, double yarm)
x = aX;
y = aY;
armY = yarm;
if(armY >= 10)
armY = 10;
public void ArmX()
armX = Math.sqrt(-Math.pow(armY, 2)+100);
armxcord = x + 18 + armX;
armycord = y + 10 - armY;
public void Bowslant()
bowslopex = (armxcord);
public void draw(Graphics2D g2)
Ellipse2D.Double head = new Ellipse2D.Double(x,y,10,10);
Line2D.Double body = new Line2D.Double(x+4,y+10,x+4,y+10);
Line2D.Double arm = new Line2D.Double(x+4,y+10,armxcord , armycord );
Line2D.Double bow1 = new Line2D.Double(armxcord, armycord,armxcord-armY, armycord-armX);
Line2D.Double bow2 = new Line2D.Double(armxcord, armycord,armxcord+armY, armycord+armX);