I want to make a simple shooting game. I have a Plane Class that contains IMG and Shape ( This is a border for that IMG, so I can use isIntersect method) attribute.
Then I rotate and translate the object ( Using AffineTransform ), after that I want to get the coordinate of it. Can someone help me?
Ps: I tried to use Rectangle than a Shape, but it seems that I can't make a Rectangle Object with CreateTransformedShape.
Here is my code :
public class EPlane {
Shape l = new Rectangle(0,0,45,55);
BufferedImage ep;
private String imgFileName = "Eplane.PNG";
ArrayList<Rectangle> EShoot = new ArrayList();
int live;
AffineTransform at;
AffineTransform at2;
AffineTransform at3;
boolean Alrdy = false;
EPlane(){
this.live = 5;
at = new AffineTransform();
at2 = new AffineTransform();
at3 = new AffineTransform();
URL imgUrl = getClass().getClassLoader().getResource(imgFileName);
if (imgUrl == null) {
System.err.println("couldn't find file: " + imgFileName);
} else {
try {
ep = ImageIO.read(imgUrl);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
And the class who want to find the x Coordinate
public class EPlaneCommander {
ArrayList<ArrayList<EPlane>> EPSList = new ArrayList();
int count = 0;
int count1 = 0;
int count2 = 0;
public EPlaneCommander() {
ArrayList<EPlane> EPS = new ArrayList();
ArrayList<EPlane> EPS1 = new ArrayList();
ArrayList<EPlane> EPS2 = new ArrayList();
EPSList.add(EPS);
EPSList.add(EPS1);
EPSList.add(EPS2);
}
public void move1() {
if (count % 50 == 1 && EPSList.get(0).size() < 10) {
EPSList.get(0).add(new EPlane());
}
for (int i = 0; i < EPSList.get(1).size(); i++) {
if (!EPSList.get(0).get(i).Alrdy) {
EPSList.get(0).get(i).at.translate(400, 0);
EPSList.get(0).get(i).Alrdy = true;
EPSList.get(0).get(i).l = EPSList.get(0).get(i).at.createTransformedShape(EPSList.get(0).get(i).l);
EPSList.get(0).get(i).at2.rotate(0.004, 0, 0);
}
//EPS.get(i).at2.rotate(0.0001, 0, 0);
EPSList.get(0).get(i).l = EPSList.get(0).get(i).at2.createTransformedShape(EPSList.get(0).get(i).l);
EPSList.get(0).get(i).at.rotate(0.004, -400, 0);
Point s = (Point) EPSList.get(2).get(i).at.createTransformedShape(EPSList.get(0).get(i).l);
}
count++;
}