ฉันอยากทำเกมยิงปืนแบบง่ายๆ ฉันมีคลาสเครื่องบินที่มีแอตทริบิวต์ IMG และรูปร่าง (นี่คือเส้นขอบสำหรับ IMG นั้น ดังนั้นฉันจึงสามารถใช้วิธี isIntersect ได้)
จากนั้นฉันหมุนและแปลวัตถุ (โดยใช้ AffineTransform ) หลังจากนั้นฉันต้องการรับพิกัดของมัน ใครสามารถช่วยฉันได้บ้าง?
ป.ล.: ฉันพยายามใช้สี่เหลี่ยมผืนผ้ามากกว่ารูปร่าง แต่ดูเหมือนว่าฉันไม่สามารถสร้างวัตถุสี่เหลี่ยมผืนผ้าด้วย CreateTransformedShape ได้
นี่คือรหัสของฉัน:
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();
}
}
}
และคลาสที่ต้องการหาพิกัด x
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++;
}