diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index 36a1a36..72c843e 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -1,9 +1,9 @@ package ruscz.game.gameOfProd.Cells; -import ruscz.game.gameOfProd.Cells.Cell; import ruscz.game.gameOfProd.Dialog.Dialog; import ruscz.game.gameOfProd.Image.ImageCell; import ruscz.game.gameOfProd.Image.ImageDialog; +import ruscz.game.gameOfProd.Map.Map; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import java.awt.*; @@ -77,4 +77,8 @@ public class InteractionCell extends Cell { g.drawImage(imageCell.getImagesOfTiles().get(334), getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); } + + public ImageCell getImageCell() { + return imageCell; + } } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java index a8c64aa..2eda704 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java @@ -88,15 +88,18 @@ public class Person extends Cell { else if (isEventInFront(x,y,directionSight) && isInEvent) { map.findInteractionByXY(x, y, directionSight).readNextLine(); } + else if (map.isActiveTriggerCell(x,y) && isInEvent) { + map.findTriggerByXY(x,y).readNextLine(); + } break; } if (directionMove != 69) { - if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isCellEvent(x, y)) { + if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isInteractionCell(x, y)) { directionMoveLast = directionMove; isMoving = true; } else if (directionMove != 0 && map.isBusyCell(x, y)) { directionMoveLast = 0; - } else if (directionMove != 0 && map.isCellEvent(x, y)) { + } else if (directionMove != 0 && map.isInteractionCell(x, y)) { directionMoveLast = 0; } if (map.isCellMoveTo(x, y)) { @@ -106,13 +109,19 @@ public class Person extends Cell { map.findEventByXY(x, y).moveToMap(); } } else { - if (!map.isBusyCell(x, y) && !map.isCellEvent(x, y)) { + if (!map.isBusyCell(x, y) && !map.isInteractionCell(x, y)) { set(x, y); } } } directionMove = 0; + + if (map.isActiveTriggerCell(x,y) && !isInEvent) { + isInEvent = true; + WindowOfFreeMove.setNextMove(WindowOfFreeMove.KEY_EVENT); + map.findTriggerByXY(x,y).startEvent(); + } } } @@ -131,7 +140,7 @@ public class Person extends Cell { y++; break; } - return map.isCellEvent(x, y); + return map.isInteractionCell(x, y); } public void stopPerson(){ diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java new file mode 100644 index 0000000..c23339b --- /dev/null +++ b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java @@ -0,0 +1,33 @@ +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 TriggerCell extends InteractionCell { + private boolean isActive; + + public TriggerCell(int x, int y, String message, Dialog dialog, ImageCell imageCell) { + super(x, y, message, dialog, imageCell); + this.isActive = true; + } + + @Override + public void endEvent() { + super.endEvent(); + this.isActive = false; + } + + @Override + public void paint(Graphics2D g) { + super.paint(g); + g.drawImage(super.getImageCell().getImagesOfTiles().get(147), getX() * WindowOfFreeMove.CELL_SIZE, + getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); + } + + public boolean getActive() { return isActive; } + + public void setActive(boolean isActive) { this.isActive = isActive; } +} diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index bf79c67..9ce3e55 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -12,7 +12,8 @@ public class Map { private Person person; private LinkedList moveToCells; private LinkedList block; - private LinkedList eventCells; + private LinkedList interactionCells; + private LinkedList triggerCells; private boolean isBlocked; private int idExit; private ImageCell imageCell; @@ -22,7 +23,8 @@ public class Map { idExit = 0; mapArray = new TypeOfCell[height][width]; moveToCells = new LinkedList(); - eventCells = new LinkedList(); + interactionCells = new LinkedList(); + triggerCells = new LinkedList(); block = new LinkedList(); isBlocked = false; imageCell = new ImageCell(); @@ -50,7 +52,8 @@ public class Map { idExit = 0; moveToCells = new LinkedList(); block = new LinkedList(); - eventCells = new LinkedList(); + interactionCells = new LinkedList(); + triggerCells = new LinkedList(); mapArray = new TypeOfCell[height][width]; this.isBlocked = isBlocked; imageCell = new ImageCell(); @@ -84,7 +87,12 @@ public class Map { public void addInteractionEvent(InteractionCell interactionCell) { mapArray[interactionCell.getX()][interactionCell.getY()] = TypeOfCell.EVENT; - eventCells.add(interactionCell); + interactionCells.add(interactionCell); + } + + public void addInteractionEvent(TriggerCell triggerCell) { + mapArray[triggerCell.getX()][triggerCell.getY()] = TypeOfCell.EVENT; + triggerCells.add(triggerCell); } public void setName(String name) { @@ -112,7 +120,7 @@ public class Map { } public LinkedList getInteractionEventCells() { - return eventCells; + return interactionCells; } public void setIdExit(int id) { @@ -197,13 +205,20 @@ public class Map { return false; } - public boolean isCellEvent(int x, int y) { - for (InteractionCell cell : eventCells) + public boolean isInteractionCell(int x, int y) { + for (InteractionCell cell : interactionCells) if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("ruscz.game.gameOfProd.Cells.InteractionCell")) return true; return false; } + public boolean isActiveTriggerCell(int x, int y) { + for (TriggerCell cell : triggerCells) + if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("ruscz.game.gameOfProd.Cells.TriggerCell") && cell.getActive()) + return true; + return false; + } + public EventMoveToCell findEventByXY(int x, int y) { for (EventMoveToCell cell : moveToCells) if (x == cell.getX() && y == cell.getY()) @@ -226,9 +241,16 @@ public class Map { y++; break; } - for (InteractionCell cell : eventCells) + for (InteractionCell cell : interactionCells) if (x == cell.getX() && y == cell.getY()) return cell; - return eventCells.getFirst(); + return interactionCells.getFirst(); + } + + public TriggerCell findTriggerByXY(int x, int y) { + for (TriggerCell cell : triggerCells) + if (x == cell.getX() && y == cell.getY()) + return cell; + return triggerCells.getFirst(); } } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index bec2d1d..b214541 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -2,6 +2,7 @@ package ruscz.game.gameOfProd.Windows; import ruscz.game.gameOfProd.Cells.Cell; import ruscz.game.gameOfProd.Cells.EventMoveToCell; import ruscz.game.gameOfProd.Cells.InteractionCell; +import ruscz.game.gameOfProd.Cells.TriggerCell; import ruscz.game.gameOfProd.Dialog.Dialog; import ruscz.game.gameOfProd.Dialog.DialogBar; import ruscz.game.gameOfProd.Map.Map; @@ -55,6 +56,8 @@ public class WindowOfFreeMove extends JFrame { this.map.createMap(); } + public static void setNextMove(int nextMove) { WindowOfFreeMove.nextMove = nextMove; } + public WindowOfFreeMove() { isReadyToPaint = false; canPersonMove = true; @@ -153,6 +156,7 @@ public class WindowOfFreeMove extends JFrame { m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4, this)); m1.addInteractionEvent(new InteractionCell(3,5,"first-dialog", new Dialog(dialogBar), m1.getImageCell())); m1.addInteractionEvent(new InteractionCell(5, 5, "dialog-test", new Dialog(dialogBar), m1.getImageCell())); + m1.addInteractionEvent(new TriggerCell(7,5,"second-dialog", new Dialog(dialogBar), m1.getImageCell())); m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3, this)); m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1, this)); diff --git a/src/main/resources/second-dialog.txt b/src/main/resources/second-dialog.txt new file mode 100644 index 0000000..eb7c310 --- /dev/null +++ b/src/main/resources/second-dialog.txt @@ -0,0 +1,7 @@ +Cop: Turn around! +Me: every now and then I get a little bit lonely, +and you're never comming 'round +Cop: Turn around! +Me: every now and then... +*gets tazed* + \ No newline at end of file