diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java new file mode 100644 index 0000000..b86ee54 --- /dev/null +++ b/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java @@ -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; + } +} diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java index 2f7c79a..a3782bc 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java @@ -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; diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index b3c7c28..9a20d97 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -18,6 +18,7 @@ public class Map { private LinkedList block; private LinkedList interactionCells; private LinkedList triggerCells; + private LinkedList doorCells; private LinkedList 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 getTriggerCells() { return triggerCells; } + public LinkedList 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(); + } } diff --git a/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java b/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java index c34406c..8967fb3 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java @@ -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(); } } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index 8cdf40f..1a59b91 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -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); } diff --git a/src/main/resources/Openspace1.png b/src/main/resources/Openspace1.png index 1b21ecf..f8b17ce 100644 Binary files a/src/main/resources/Openspace1.png and b/src/main/resources/Openspace1.png differ diff --git a/src/main/resources/dialogs/locked.txt b/src/main/resources/dialogs/locked.txt new file mode 100644 index 0000000..f547311 --- /dev/null +++ b/src/main/resources/dialogs/locked.txt @@ -0,0 +1,2 @@ +It's locked.. + \ No newline at end of file diff --git a/src/main/resources/maps/boss-cellmap.txt b/src/main/resources/maps/boss-cellmap.txt index bafbaf0..ecb4ed5 100644 --- a/src/main/resources/maps/boss-cellmap.txt +++ b/src/main/resources/maps/boss-cellmap.txt @@ -1,4 +1,5 @@ BLOCK 2 MOVETO 1 EVENT 3 -TRIGGER 4 \ No newline at end of file +TRIGGER 4 +DOOR 254 \ No newline at end of file diff --git a/src/main/resources/maps/boss.txt b/src/main/resources/maps/boss.txt index 43cd705..0ad3b9b 100644 --- a/src/main/resources/maps/boss.txt +++ b/src/main/resources/maps/boss.txt @@ -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 \ No newline at end of file +BLOCK BLOCK BLOCK BLOCK DOORTO,0,1,office BLOCK BLOCK BLOCK BLOCK \ No newline at end of file diff --git a/src/main/resources/maps/office-cellmap.txt b/src/main/resources/maps/office-cellmap.txt index bafbaf0..ecb4ed5 100644 --- a/src/main/resources/maps/office-cellmap.txt +++ b/src/main/resources/maps/office-cellmap.txt @@ -1,4 +1,5 @@ BLOCK 2 MOVETO 1 EVENT 3 -TRIGGER 4 \ No newline at end of file +TRIGGER 4 +DOOR 254 \ No newline at end of file diff --git a/src/main/resources/maps/office.txt b/src/main/resources/maps/office.txt index dbc3db1..1c31a2f 100644 --- a/src/main/resources/maps/office.txt +++ b/src/main/resources/maps/office.txt @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/src/main/resources/maps/openspace-cellmap.txt b/src/main/resources/maps/openspace-cellmap.txt index bafbaf0..fdd1800 100644 --- a/src/main/resources/maps/openspace-cellmap.txt +++ b/src/main/resources/maps/openspace-cellmap.txt @@ -1,4 +1,5 @@ BLOCK 2 MOVETO 1 -EVENT 3 -TRIGGER 4 \ No newline at end of file +EVENT 0 +TRIGGER 4 +DOOR 254 \ No newline at end of file diff --git a/src/main/resources/maps/openspace.txt b/src/main/resources/maps/openspace.txt index 4c00670..415a2e5 100644 --- a/src/main/resources/maps/openspace.txt +++ b/src/main/resources/maps/openspace.txt @@ -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 diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index 245388a..f79dde1 100644 --- a/src/main/resources/save/savedGame/events.txt +++ b/src/main/resources/save/savedGame/events.txt @@ -64,7 +64,7 @@ 4 18 - true + false diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index d826f54..e33ef6b 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -1,5 +1,5 @@ - openspace - 8 - 15 + office + 4 + 1 \ No newline at end of file