added event trigger

This commit is contained in:
musilto9 2020-03-11 22:07:57 +01:00
parent 00ec0ea77e
commit cdb5180f99
2 changed files with 26 additions and 21 deletions

View File

@ -37,7 +37,7 @@ public class Person extends Cell {
} }
public void setDirectionMove(int directionMove) { public void setDirectionMove(int directionMove) {
if ((directionMove >= WindowOfFreeMove.KEY_LEFT) && (directionMove <= WindowOfFreeMove.KEY_DOWN)) if ((directionMove >= WindowOfFreeMove.KEY_LEFT) && (directionMove <= WindowOfFreeMove.KEY_EVENT))
this.directionMove = directionMove; this.directionMove = directionMove;
} }
@ -74,31 +74,35 @@ public class Person extends Cell {
if (y == WindowOfFreeMove.CANVAS_HEIGHT) if (y == WindowOfFreeMove.CANVAS_HEIGHT)
y = 0; y = 0;
break; break;
case WindowOfFreeMove.KEY_EVENT:
if (isEventInFront(x,y,directionSight)) {
System.out.println("showEvent");
}
break;
} }
if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isCellEvent(x, y)) { if (directionMove != 69) {
directionMoveLast = directionMove; if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isCellEvent(x, y)) {
isMoving = true; directionMoveLast = directionMove;
} else if (directionMove != 0 && map.isBusyCell(x, y)) { isMoving = true;
directionMoveLast = 0; } else if (directionMove != 0 && map.isBusyCell(x, y)) {
} else if (directionMove != 0 && map.isCellEvent(x, y)) { directionMoveLast = 0;
directionMoveLast = 0; } else if (directionMove != 0 && map.isCellEvent(x, y)) {
} directionMoveLast = 0;
if (map.isCellMoveTo(x, y)) {
set(x, y);
WindowOfFreeMove.setCanPersonMove(false);
if (!isMoving) {
map.findEventByXY(x, y).moveToMap();
} }
} else { if (map.isCellMoveTo(x, y)) {
if (!map.isBusyCell(x, y) && !map.isCellEvent(x,y)) {
set(x, y); set(x, y);
WindowOfFreeMove.setCanPersonMove(false);
if (!isMoving) {
map.findEventByXY(x, y).moveToMap();
}
} else {
if (!map.isBusyCell(x, y) && !map.isCellEvent(x, y)) {
set(x, y);
}
} }
} }
directionMove = 0;
if (isEventInFront(x,y,directionSight)) { directionMove = 0;
System.out.println("showEvent");
}
} }
} }

View File

@ -18,6 +18,7 @@ public class WindowOfFreeMove extends JFrame {
static final int KEY_UP = 38; static final int KEY_UP = 38;
static final int KEY_RIGHT = 39; static final int KEY_RIGHT = 39;
static final int KEY_DOWN = 40; static final int KEY_DOWN = 40;
static final int KEY_EVENT = 69;
private Canvas canvas; private Canvas canvas;
private static JPanel dialogBar; private static JPanel dialogBar;
@ -74,7 +75,7 @@ public class WindowOfFreeMove extends JFrame {
inputTimer = new Timer(10, new ActionListener() { inputTimer = new Timer(10, new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
if (!map.getPerson().getIsMoving() && canPersonMove) { if (!map.getPerson().getIsMoving() && canPersonMove && nextMove != KEY_EVENT) {
map.getPerson().setDirectionMove(nextMove); map.getPerson().setDirectionMove(nextMove);
} }
} }