Initial version of pathfinding - fixed SolderPen
This commit is contained in:
parent
a8e68af6db
commit
2644f5a2dc
@ -5,6 +5,7 @@ import com.droidquest.Wire;
|
||||
import com.droidquest.chipstuff.Port;
|
||||
import com.droidquest.devices.Device;
|
||||
import com.droidquest.items.Item;
|
||||
import com.droidquest.pathfinder.Node;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -12,6 +13,7 @@ import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SolderingPen extends Device implements Avatar {
|
||||
private boolean hot;
|
||||
@ -388,50 +390,23 @@ public class SolderingPen extends Device implements Avatar {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MouseClick(MouseEvent e) {
|
||||
int button = 0;
|
||||
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
|
||||
button = 1;
|
||||
}
|
||||
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
|
||||
button = 3;
|
||||
}
|
||||
@Override
|
||||
protected int getWidthModifier() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (button == 1) {
|
||||
if (e.getClickCount() == 1) {
|
||||
autoX = e.getX() - 2;
|
||||
autoY = e.getY() - 20;
|
||||
automove = 1;
|
||||
}
|
||||
else if (e.getClickCount() == 2) {
|
||||
int dx = e.getX() - 2 - x;
|
||||
int dy = e.getY() - 20 - y;
|
||||
if (Math.abs(dx) > Math.abs(dy)) {
|
||||
autoY = 0;
|
||||
autoX = 28;
|
||||
if (dx < 0) {
|
||||
autoX = -28;
|
||||
}
|
||||
automove = 2;
|
||||
}
|
||||
else {
|
||||
autoX = 0;
|
||||
autoY = 32;
|
||||
if (dy < 0) {
|
||||
autoY = -32;
|
||||
}
|
||||
automove = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected int getHeightModifier() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
if (button == 3) {
|
||||
KeyEvent k = new KeyEvent(e.getComponent(), e.getID(),
|
||||
e.getWhen(), 0,
|
||||
KeyEvent.VK_SPACE, ' ');
|
||||
KeyUp(k);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setFinePositioning(MouseEvent e) {
|
||||
// Fine positioning needed for solderpen
|
||||
int finalX = e.getX() - getWidthModifier();
|
||||
int finalY = e.getY() - getHeightModifier();
|
||||
autoPath.add(new Node(finalX, finalY));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -234,6 +234,19 @@ public class Item implements Serializable, Cloneable {
|
||||
autoPath = pf.search(startX, startY, endX, endY, this);
|
||||
}
|
||||
|
||||
|
||||
protected int getWidthModifier() {
|
||||
return width / 2;
|
||||
}
|
||||
|
||||
protected int getHeightModifier() {
|
||||
return height / 2;
|
||||
}
|
||||
|
||||
protected void setFinePositioning(MouseEvent e) {
|
||||
// By default, no fine positioning
|
||||
}
|
||||
|
||||
public void MouseClick(MouseEvent e) {
|
||||
int button = 0;
|
||||
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
|
||||
@ -254,6 +267,8 @@ public class Item implements Serializable, Cloneable {
|
||||
findPath(startX, startY, endX, endY);
|
||||
|
||||
if(autoPath != null && autoPath.size() > 0) {
|
||||
setFinePositioning(e);
|
||||
|
||||
Node next = autoPath.remove(0);
|
||||
|
||||
autoX = next.getX();
|
||||
@ -264,8 +279,8 @@ public class Item implements Serializable, Cloneable {
|
||||
}
|
||||
}
|
||||
else if (e.getClickCount() == 2) {
|
||||
int dx = e.getX() - width / 2 - x;
|
||||
int dy = e.getY() - height / 2 - y;
|
||||
int dx = e.getX() - getWidthModifier() - x;
|
||||
int dy = e.getY() - getHeightModifier() - y;
|
||||
if (Math.abs(dx) > Math.abs(dy)) {
|
||||
autoY = 0;
|
||||
autoX = 28;
|
||||
|
Loading…
Reference in New Issue
Block a user