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) {
if ((directionMove >= WindowOfFreeMove.KEY_LEFT) && (directionMove <= WindowOfFreeMove.KEY_DOWN))
if ((directionMove >= WindowOfFreeMove.KEY_LEFT) && (directionMove <= WindowOfFreeMove.KEY_EVENT))
this.directionMove = directionMove;
}
@ -74,7 +74,13 @@ public class Person extends Cell {
if (y == WindowOfFreeMove.CANVAS_HEIGHT)
y = 0;
break;
case WindowOfFreeMove.KEY_EVENT:
if (isEventInFront(x,y,directionSight)) {
System.out.println("showEvent");
}
break;
}
if (directionMove != 69) {
if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isCellEvent(x, y)) {
directionMoveLast = directionMove;
isMoving = true;
@ -94,11 +100,9 @@ public class Person extends Cell {
set(x, y);
}
}
directionMove = 0;
if (isEventInFront(x,y,directionSight)) {
System.out.println("showEvent");
}
directionMove = 0;
}
}

View File

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