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,7 +74,13 @@ 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 != 69) {
if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isCellEvent(x, y)) { if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isCellEvent(x, y)) {
directionMoveLast = directionMove; directionMoveLast = directionMove;
isMoving = true; isMoving = true;
@ -94,11 +100,9 @@ public class Person extends Cell {
set(x, y); 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_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);
} }
} }