first step towards interactions

This commit is contained in:
musilto9 2020-03-11 21:41:20 +01:00
parent d1d553949f
commit 76739987aa
5 changed files with 48 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import java.awt.*;
public class InteractionCell extends Cell {
InteractionCell(){
super(-1,-1, WindowOfFreeMove.CELL_SIZE, Color.ORANGE);
}

View File

@ -13,6 +13,7 @@ public class Map {
private Person person;
private LinkedList<EventMoveToCell> moveToCells;
private LinkedList<Block> block;
private LinkedList<InteractionCell> eventCells;
private boolean isBlocked;
private int idExit;
private ImageCell imageCell;
@ -49,6 +50,7 @@ public class Map {
idExit = 0;
moveToCells = new LinkedList<EventMoveToCell>();
block = new LinkedList<Block>();
eventCells = new LinkedList<InteractionCell>();
mapArray = new TypeOfCell[height][width];
this.isBlocked = isBlocked;
imageCell = new ImageCell();
@ -80,6 +82,11 @@ public class Map {
moveToCells.add(moveToCell);
}
public void addInteractionEvent(InteractionCell interactionCell) {
mapArray[interactionCell.getX()][interactionCell.getY()] = TypeOfCell.EVENT;
eventCells.add(interactionCell);
}
public void setName(String name) {
this.name = name;
}
@ -104,6 +111,10 @@ public class Map {
return moveToCells;
}
public LinkedList<InteractionCell> getInteractionEventCells() {
return eventCells;
}
public void setIdExit(int id) {
this.idExit = id;
}
@ -182,6 +193,13 @@ public class Map {
return false;
}
boolean isCellEvent(int x, int y) {
for (InteractionCell cell : eventCells)
if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("InteractionCell"))
return true;
return false;
}
EventMoveToCell findEventByXY(int x, int y) {
for (EventMoveToCell cell : moveToCells)
if (x == cell.getX() && y == cell.getY())

View File

@ -75,11 +75,13 @@ public class Person extends Cell {
y = 0;
break;
}
if (directionMove != 0 && !map.isBusyCell(x, y)) {
if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isCellEvent(x, y)) {
directionMoveLast = directionMove;
isMoving = true;
} else if (directionMove != 0 && map.isBusyCell(x, y)) {
directionMoveLast = 0;
} else if (directionMove != 0 && map.isCellEvent(x, y)) {
directionMoveLast = 0;
}
if (map.isCellMoveTo(x, y)) {
set(x, y);
@ -88,13 +90,36 @@ public class Person extends Cell {
map.findEventByXY(x, y).moveToMap();
}
} else {
if (!map.isBusyCell(x, y)) {
if (!map.isBusyCell(x, y) && !map.isCellEvent(x,y)) {
set(x, y);
}
}
directionMove = 0;
if (isEventInFront(x,y,directionSight)) {
System.out.println("showEvent");
}
}
}
private boolean isEventInFront(int x, int y, int directionSight) {
switch (directionSight) {
case 1:
x--;
break;
case 3:
x++;
break;
case 2:
y--;
break;
case 0:
y++;
break;
}
return map.isCellEvent(x, y);
}
public void stopPerson(){
directionMove = 0;
directionMoveLast = 0;

View File

@ -1,3 +1,3 @@
public enum TypeOfCell {
BLOCK, EMPTY, MOVETO, SPAWNPOINT;
BLOCK, EMPTY, MOVETO, EVENT, SPAWNPOINT;
}

View File

@ -149,6 +149,7 @@ public class WindowOfFreeMove extends JFrame {
m1.addMoveToEvent(new EventMoveToCell(1, 1, 8, 8, m2, this));
m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4, this));
m1.addInteractionEvent(new InteractionCell(5, 5));
m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3, this));
m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1, this));