helo,
i am trying to put in a targeting system to target an enemy from my hero and i have a rectangle behind the enemy so i call mouseclicked
// user release mouse buton - mouse released method
@Override
public void mouseReleased(MouseEvent e) {
// caled when mouse buton released
if (e.getButton() == 3) {
// check where click was example: left top from the center of wooyl along with sub quadrent and move unit
wooyl = detectquadrent(e, wooyl);
Rectangle click = new Rectangle(e.getX(), e.getY(), 1, 1);
if (wolftargetcheck(click)) {
resetwolftarget();
}
}
and the method is
/** scan wolf list to see if any wolf are intersecting wooyl click location */
private boolean wolftargetcheck(Rectangle xy) {
boolean noclick = true;
Iterator<unit> wolfiteratorfive = wolf.values().iterator();
while(wolfiteratorfive.hasNext()) {
unit wolfobjectfive = wolfiteratorfive.next();
if (xy.intersects(wolfobjectfive.unitrectangle)) {
//System.out.println("working");
wolfobjectfive.targeted = true;
noclick = false;
break;
}
}
return noclick;
}
and i have set the enemy background rectangle to the displayed image location, and width excetera
wolfdeathsouthernwestern = new ImageIcon("libbisouthernwesterndeath2.gif");
curentimage = wolfeastern;
curentanimated = wolfmovingwestern;
unitrectangle = new Rectangle(x.intValue(), y.intValue(), curentimage.getWidth(), curentimage.getHeight());
and that is updated all the time in paintcomponent when it changes
if (wolfobject.facing.equals("southernwestern")) {
g.drawImage(wolfobject.wolfsouthernwestern, wolfobject.x.intValue(), wolfobject.y.intValue(), this);
wolfobject.curentimage = wolfobject.wolfsouthernwestern;
}
wolfobject.unitrectangle = new Rectangle(wolfobject.x.intValue(), wolfobject.y.intValue(), wolfobject.curentimage.getWidth(),
wolfobject.curentimage.getHeight());
and i am displaying the rectangle and it look good, the unit rectangle so i do not understand when i click on the wolf toward the botom it does not target then when i click above the wolf it targets
the workspace project is at:
and the main clas is roleplayinggamehorn.java
it is for 1366 / 768 resolution, window