This is for a test game I'm making (2D click shooting).
How do I use the MouseListener method to get the X and Y coordinates of the location clicked and draw a line from another location to that point?
public boolean shot;
public boolean MouseClicked(MouseEvent e){
shot=true;
xmissile=e.getX();
ymissile=e.getY();
return true;
}
public void paint(Graphics g) {
if(shot==true){
//soldierpos[0] is X coordinate of soldier
//soldierpos[1] is Y coordinate of soldier
g.drawLine(soldierpos[0],soldierpos[1],xmissile,ymissile);
}
It doesn't seem to work. In the end though, I wish to make it fire a missile at an angle determined by mouse click in a straight line. How would I go about doing that?
Thanks for the help!

Start a new topic
Add Reply




MultiQuote
| 


