added doors and doorTo's
This commit is contained in:
parent
955d99f266
commit
397e3dab7c
57
src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java
Normal file
57
src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java
Normal file
@ -0,0 +1,57 @@
|
||||
package ruscz.game.gameOfProd.Cells;
|
||||
|
||||
import ruscz.game.gameOfProd.Dialog.Dialog;
|
||||
import ruscz.game.gameOfProd.Image.ImageCell;
|
||||
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DoorCell extends InteractionCell {
|
||||
private boolean isOpen;
|
||||
private boolean isLocked;
|
||||
private boolean requiresKey;
|
||||
|
||||
public DoorCell(int x, int y, String message, Dialog dialog, ImageCell imageCell, WindowOfFreeMove window, boolean requiresKey) {
|
||||
super(x, y, message, dialog, imageCell, window, true);
|
||||
this.isOpen = false;
|
||||
this.isLocked = true;
|
||||
this.requiresKey = requiresKey;
|
||||
}
|
||||
|
||||
public DoorCell(int x, int y, ImageCell imageCell, WindowOfFreeMove window) {
|
||||
super(x, y, null, null, imageCell, window, true);
|
||||
this.isOpen = false;
|
||||
this.isLocked = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics2D g) {
|
||||
int open = isOpen ? 1 : 0;
|
||||
g.drawImage(super.getImageCell().getImagesOfTiles().get(super.getImageCell().getImageFromCellMap("DOOR") + open), getX() * WindowOfFreeMove.CELL_SIZE,
|
||||
getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
public void setOpen(boolean open) {
|
||||
isOpen = open;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return isLocked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
isLocked = locked;
|
||||
}
|
||||
|
||||
public boolean isRequiresKey() {
|
||||
return requiresKey;
|
||||
}
|
||||
|
||||
public void setRequiresKey(boolean requiresKey) {
|
||||
this.requiresKey = requiresKey;
|
||||
}
|
||||
}
|
||||
@ -95,26 +95,43 @@ public class Person extends Cell {
|
||||
else if (map.isActiveTriggerCell(x,y) && isInEvent) {
|
||||
map.findTriggerByXY(x,y).readNextLine();
|
||||
}
|
||||
else if (isDoorInFront(x,y,directionSight)) {
|
||||
DoorCell door = map.findDoorByXY(x, y, directionSight);
|
||||
if (!door.isLocked()) {
|
||||
if (door.isOpen())
|
||||
door.setOpen(false);
|
||||
else
|
||||
door.setOpen(true);
|
||||
}
|
||||
else if (!isInEvent) {
|
||||
isInEvent = true;
|
||||
door.startEvent();
|
||||
}
|
||||
else {
|
||||
door.readNextLine();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (directionMove != WindowOfFreeMove.KEY_EVENT) {
|
||||
if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isInteractionCell(x, y)) {
|
||||
if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isInteractionCell(x, y) && !map.isClosedDoor(x, y)) {
|
||||
directionMoveLast = directionMove;
|
||||
isMoving = true;
|
||||
} else if (directionMove != 0 && map.isBusyCell(x, y)) {
|
||||
directionMoveLast = 0;
|
||||
} else if (directionMove != 0 && map.isInteractionCell(x, y)) {
|
||||
directionMoveLast = 0;
|
||||
} else if (directionMove != 0 && map.isClosedDoor(x, y)) {
|
||||
directionMoveLast = 0;
|
||||
}
|
||||
if (map.isCellMoveTo(x, y)) {
|
||||
if (map.isCellMoveTo(x, y) && !map.isClosedDoor(x, y)) {
|
||||
set(x, y);
|
||||
WindowOfFreeMove.setCanPersonMove(false);
|
||||
if (!isMoving) {
|
||||
map.findEventByXY(x, y).moveToMap();
|
||||
}
|
||||
} else {
|
||||
if (!map.isInteractionCell(x, y) && !map.isBusyCell(x, y))
|
||||
{
|
||||
if (!map.isInteractionCell(x, y) && !map.isBusyCell(x, y) && !map.isClosedDoor(x, y)) {
|
||||
set(x, y);
|
||||
}
|
||||
}
|
||||
@ -152,6 +169,24 @@ public class Person extends Cell {
|
||||
return map.isInteractionCell(x, y);
|
||||
}
|
||||
|
||||
private boolean isDoorInFront(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.isDoor(x, y);
|
||||
}
|
||||
|
||||
public void stopPerson(){
|
||||
directionMove = 0;
|
||||
directionMoveLast = 0;
|
||||
|
||||
@ -18,6 +18,7 @@ public class Map {
|
||||
private LinkedList<Block> block;
|
||||
private LinkedList<InteractionCell> interactionCells;
|
||||
private LinkedList<TriggerCell> triggerCells;
|
||||
private LinkedList<DoorCell> doorCells;
|
||||
private LinkedList<Npc> npcs;
|
||||
private int idExit;
|
||||
private ImageCell imageCell;
|
||||
@ -33,6 +34,7 @@ public class Map {
|
||||
moveToCells = new LinkedList<>();
|
||||
interactionCells = new LinkedList<>();
|
||||
triggerCells = new LinkedList<>();
|
||||
doorCells = new LinkedList<>();
|
||||
npcs = new LinkedList<>();
|
||||
block = new LinkedList<>();
|
||||
imageCell = new ImageCell();
|
||||
@ -59,6 +61,7 @@ public class Map {
|
||||
block = new LinkedList<>();
|
||||
interactionCells = new LinkedList<>();
|
||||
triggerCells = new LinkedList<>();
|
||||
doorCells = new LinkedList<>();
|
||||
mapArray = new TypeOfCell[height][width];
|
||||
npcs = new LinkedList<>();
|
||||
imageCell = new ImageCell();
|
||||
@ -86,6 +89,7 @@ public class Map {
|
||||
moveToCells = new LinkedList<>();
|
||||
interactionCells = new LinkedList<>();
|
||||
triggerCells = new LinkedList<>();
|
||||
doorCells = new LinkedList<>();
|
||||
block = new LinkedList<>();
|
||||
imageCell = new ImageCell();
|
||||
npcs = new LinkedList<>();
|
||||
@ -157,6 +161,13 @@ public class Map {
|
||||
map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(window.getDialogBar()), map.getImageCell(), window));
|
||||
} else if (line[x].equals("SPAWN")) {
|
||||
map.setSpawnPoint(x, y);
|
||||
} else if (line[x].contains("DOOR") && !line[x].contains("DOORTO")) {
|
||||
ImageCell imageCell = new ImageCell();
|
||||
String[] door = line[x].split(",");
|
||||
if (line[x].equals("DOOR"))
|
||||
map.addInteractionEvent(new DoorCell(x, y, map.getImageCell(), window));
|
||||
else
|
||||
map.addInteractionEvent(new DoorCell(x, y, door[1], new Dialog(window.getDialogBar()), map.getImageCell(), window, Boolean.parseBoolean(door[2])));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -180,6 +191,17 @@ public class Map {
|
||||
else
|
||||
map.addMoveToEvent(new EventMoveToCell(Integer.parseInt(moveTo[1]), Integer.parseInt(moveTo[2]), x, y, findMapByName(moveTo[3], window), window, false));
|
||||
}
|
||||
else if (line[x].contains("DOORTO")) {
|
||||
String[] doorTo = line[x].split(",");
|
||||
if (doorTo[1].equals("locked")) {
|
||||
map.addInteractionEvent(new DoorCell(x, y, doorTo[2], new Dialog(window.getDialogBar()), map.getImageCell(), window, Boolean.parseBoolean(doorTo[3])));
|
||||
map.addMoveToEvent(new EventMoveToCell(Integer.parseInt(doorTo[4]), Integer.parseInt(doorTo[5]), x, y, findMapByName(doorTo[6], window), window, false));
|
||||
}
|
||||
else {
|
||||
map.addInteractionEvent(new DoorCell(x, y, map.getImageCell(), window));
|
||||
map.addMoveToEvent(new EventMoveToCell(Integer.parseInt(doorTo[1]), Integer.parseInt(doorTo[2]), x, y, findMapByName(doorTo[3], window), window, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
@ -204,6 +226,11 @@ public class Map {
|
||||
triggerCells.add(triggerCell);
|
||||
}
|
||||
|
||||
public void addInteractionEvent(DoorCell doorCell) {
|
||||
mapArray[doorCell.getX()][doorCell.getY()] = TypeOfCell.EVENT;
|
||||
doorCells.add(doorCell);
|
||||
}
|
||||
|
||||
public void setNpcs(Npc npc){
|
||||
npcs.add(npc);
|
||||
}
|
||||
@ -242,6 +269,8 @@ public class Map {
|
||||
|
||||
public LinkedList<TriggerCell> getTriggerCells() { return triggerCells; }
|
||||
|
||||
public LinkedList<DoorCell> getDoorCells() { return doorCells; }
|
||||
|
||||
public void setIdExit(int id) {
|
||||
this.idExit = id;
|
||||
}
|
||||
@ -290,6 +319,21 @@ public class Map {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDoor(int x, int y) {
|
||||
for (DoorCell cell : doorCells)
|
||||
if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("ruscz.game.gameOfProd.Cells.DoorCell")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isClosedDoor(int x, int y) {
|
||||
for (DoorCell cell : doorCells)
|
||||
if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("ruscz.game.gameOfProd.Cells.DoorCell") && !cell.isOpen())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public EventMoveToCell findEventByXY(int x, int y) {
|
||||
for (EventMoveToCell cell : moveToCells)
|
||||
if (x == cell.getX() && y == cell.getY())
|
||||
@ -324,4 +368,32 @@ public class Map {
|
||||
return cell;
|
||||
return triggerCells.getFirst();
|
||||
}
|
||||
|
||||
public DoorCell findDoorByXY(int x, int y, int directionSight) {
|
||||
switch (directionSight) {
|
||||
case 1:
|
||||
x--;
|
||||
break;
|
||||
case 3:
|
||||
x++;
|
||||
break;
|
||||
case 2:
|
||||
y--;
|
||||
break;
|
||||
case 0:
|
||||
y++;
|
||||
break;
|
||||
}
|
||||
for (DoorCell cell : doorCells)
|
||||
if (x == cell.getX() && y == cell.getY())
|
||||
return cell;
|
||||
return doorCells.getFirst();
|
||||
}
|
||||
|
||||
public DoorCell findDoorByXY(int x, int y) {
|
||||
for (DoorCell cell : doorCells)
|
||||
if (x == cell.getX() && y == cell.getY())
|
||||
return cell;
|
||||
return doorCells.getFirst();
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,6 +102,8 @@ public class MapManager {
|
||||
actualMap.getPerson().set(-1, -1);
|
||||
break;
|
||||
}
|
||||
if (actualMap.isDoor(cell.getX(), cell.getY()))
|
||||
actualMap.findDoorByXY(cell.getX(), cell.getY()).setOpen(true);
|
||||
saveManager.saveGame();
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,6 +215,9 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
for (Cell cell : mapManager.getActualMap().getInteractionEventCells()) {
|
||||
cell.paint(g2D);
|
||||
}
|
||||
for (Cell cell : mapManager.getActualMap().getDoorCells()) {
|
||||
cell.paint(g2D);
|
||||
}
|
||||
for (Person person : mapManager.getActualMap().getNpcs()) {
|
||||
person.paint(g2D);
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 51 KiB |
2
src/main/resources/dialogs/locked.txt
Normal file
2
src/main/resources/dialogs/locked.txt
Normal file
@ -0,0 +1,2 @@
|
||||
It's locked..
|
||||
<end>
|
||||
@ -2,3 +2,4 @@ BLOCK 2
|
||||
MOVETO 1
|
||||
EVENT 3
|
||||
TRIGGER 4
|
||||
DOOR 254
|
||||
@ -18,4 +18,4 @@ BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK EMPTY EMPTY EMPTY TRIGGER,ohhimark EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK BLOCK BLOCK BLOCK moveto,0,1,office BLOCK BLOCK BLOCK BLOCK
|
||||
BLOCK BLOCK BLOCK BLOCK DOORTO,0,1,office BLOCK BLOCK BLOCK BLOCK
|
||||
@ -2,3 +2,4 @@ BLOCK 2
|
||||
MOVETO 1
|
||||
EVENT 3
|
||||
TRIGGER 4
|
||||
DOOR 254
|
||||
@ -1,5 +1,5 @@
|
||||
20 12
|
||||
BLOCK BLOCK BLOCK BLOCK moveto,0,3,boss BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK block BLOCK BLOCK BLOCK BLOCK block BLOCK BLOCK
|
||||
BLOCK BLOCK BLOCK BLOCK DOORTO,0,3,boss BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK
|
||||
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK
|
||||
@ -10,4 +10,4 @@ BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BL
|
||||
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK BLOCK block BLOCK BLOCK BLOCK BLOCK block BLOCK BLOCK BLOCK BLOCK block BLOCK BLOCK BLOCK BLOCK block BLOCK BLOCK
|
||||
BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK block BLOCK BLOCK
|
||||
@ -1,4 +1,5 @@
|
||||
BLOCK 2
|
||||
MOVETO 1
|
||||
EVENT 3
|
||||
EVENT 0
|
||||
TRIGGER 4
|
||||
DOOR 254
|
||||
@ -3,16 +3,16 @@ BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BL
|
||||
BLOCK block block block EMPTY EMPTY EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY inter,laugh inter,laugh EMPTY EMPTY BLOCK
|
||||
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block
|
||||
BLOCK BLOCK EMPTY BLOCK BLOCK BLOCK EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block
|
||||
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY DOOR EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block
|
||||
BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK DOOR BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block
|
||||
BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block
|
||||
BLOCK block EMPTY block BLOCK block EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block
|
||||
BLOCK block EMPTY block BLOCK block EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK block EMPTY block BLOCK block EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK BLOCK BLOCK
|
||||
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK DOOR BLOCK BLOCK BLOCK
|
||||
BLOCK EMPTY block block EMPTY inter,minecraft inter,minecraft EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK EMPTY block block EMPTY inter,minecraft inter,minecraft EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY block EMPTY EMPTY EMPTY block block
|
||||
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block block EMPTY block block block
|
||||
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY DOOR EMPTY EMPTY EMPTY EMPTY EMPTY block block EMPTY block block block
|
||||
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
|
||||
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,1,2,office EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
|
||||
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,0,2,m1 EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block EMPTY block EMPTY BLOCK
|
||||
|
||||
@ -64,7 +64,7 @@
|
||||
<event>
|
||||
<x>4</x>
|
||||
<y>18</y>
|
||||
<active>true</active>
|
||||
<active>false</active>
|
||||
</event>
|
||||
</events>
|
||||
</map>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<location>
|
||||
<map>openspace</map>
|
||||
<x>8</x>
|
||||
<y>15</y>
|
||||
<map>office</map>
|
||||
<x>4</x>
|
||||
<y>1</y>
|
||||
</location>
|
||||
Loading…
x
Reference in New Issue
Block a user