diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java index f42d289..6b00360 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java @@ -33,7 +33,14 @@ public class EventMoveToCell extends Cell { window.getMapManager().getActualMap().setIdExit(id); window.paintMapOnWindow(); window.repaintCanvas(); - window.setCanPersonMove(true); + if (!isActiveTriggerBehindMoveTo()) + window.setCanPersonMove(true); + } + + private boolean isActiveTriggerBehindMoveTo() { + int x = window.getMapManager().getActualMap().getPerson().getX(); + int y = window.getMapManager().getActualMap().getPerson().getY(); + return map.isActiveTriggerCell(x, y); } @Override diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index 61d19b4..b23ebdc 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -187,6 +187,12 @@ public class InteractionCell extends Cell { } readNextLine(); } + else if (data.contains("")) { + String[] eventInfo = data.split(" "); + Map map = Map.findMapByName(eventInfo[1], window); + map.findTriggerByXY(Integer.parseInt(eventInfo[2]), Integer.parseInt(eventInfo[3])).setActive(Boolean.parseBoolean(eventInfo[4])); + readNextLine(); + } else { if (data.contains("
")) data = "" + data + ""; @@ -242,8 +248,8 @@ public class InteractionCell extends Cell { else if (data[1].contains("")) { Map map = Map.findMapByName(data[2], window); window.getMapManager().setMap(map); - map.getPerson().set(map.getSpawnPoint()[0], map.getSpawnPoint()[1]); - map.getPerson().setDirectionSight(Integer.parseInt(data[3])); + map.getPerson().set(Integer.parseInt(data[3]), Integer.parseInt(data[4])); + map.getPerson().setDirectionSight(Integer.parseInt(data[5])); map.setIdExit(0); } else if (data[1].equals("")) { diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java index 815af13..b354943 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java @@ -14,6 +14,11 @@ public class TriggerCell extends InteractionCell { this.isActive = true; } + public TriggerCell(int x, int y, String message, Dialog dialog, Map map, WindowOfFreeMove window, boolean active) { + super(x, y, message, dialog, map, window, false); + this.isActive = active; + } + @Override public void endEvent() { super.endEvent(); diff --git a/src/main/java/ruscz/game/gameOfProd/Game.java b/src/main/java/ruscz/game/gameOfProd/Game.java index fd04903..e54b3d1 100644 --- a/src/main/java/ruscz/game/gameOfProd/Game.java +++ b/src/main/java/ruscz/game/gameOfProd/Game.java @@ -1,5 +1,6 @@ package ruscz.game.gameOfProd; +import ruscz.game.gameOfProd.LevelEditor.TilesetOverview; import ruscz.game.gameOfProd.Windows.WindowOfBattle; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import ruscz.game.gameOfProd.Windows.WindowOfMenu; @@ -15,6 +16,7 @@ public class Game extends JFrame { private WindowOfMenu menu; private WindowOfFreeMove freeMove; private WindowOfBattle battle; + private TilesetOverview tilesetOverview; public WindowOfMenu getMenu() { return menu; @@ -48,6 +50,9 @@ public class Game extends JFrame { // add(battle); // battle.startBattle(); + //Tohle spustí na začátku tileset overview +// tilesetOverview = new TilesetOverview(); + setDefaultCloseOperation(EXIT_ON_CLOSE); setUndecorated(true); setBounds(0, 0, CELL_SIZE * WINDOW_WIDTH, CELL_SIZE * WINDOW_HEIGHT); diff --git a/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java b/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java index f3183bb..bae557d 100644 --- a/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java @@ -59,7 +59,7 @@ public class ImageCell { private void imageTileset(String[] mapInfo) { try { - image = ImageIO.read(new File("src/main/resources/" + mapInfo[1])); + image = ImageIO.read(new File("src/main/resources/tilesets/" + mapInfo[1])); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/ruscz/game/gameOfProd/Image/ImageDoor.java b/src/main/java/ruscz/game/gameOfProd/Image/ImageDoor.java index 1cd31f4..641fdc2 100644 --- a/src/main/java/ruscz/game/gameOfProd/Image/ImageDoor.java +++ b/src/main/java/ruscz/game/gameOfProd/Image/ImageDoor.java @@ -26,7 +26,7 @@ public class ImageDoor { public ImageDoor(String door, Rectangle[] rectangles) { try { String[] doorInfo = door.split(","); - image = ImageIO.read(new File("src/main/resources/" + doorInfo[0])); + image = ImageIO.read(new File("src/main/resources/tilesets/" + doorInfo[0])); size = Integer.parseInt(doorInfo[1]); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/ruscz/game/gameOfProd/LevelEditor/TilesetOverview.java b/src/main/java/ruscz/game/gameOfProd/LevelEditor/TilesetOverview.java new file mode 100644 index 0000000..19b43aa --- /dev/null +++ b/src/main/java/ruscz/game/gameOfProd/LevelEditor/TilesetOverview.java @@ -0,0 +1,149 @@ +package ruscz.game.gameOfProd.LevelEditor; + +import javax.imageio.ImageIO; +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.LinkedList; + +public class TilesetOverview extends JFrame { + + private JLayeredPane view; + private JLayeredPane tilesetPanel; + private JScrollPane scrollPane; + private JLabel info; + + private int offset = 0; + private int tilesetOffset = 0; + private LinkedList activeTilesets; + private LinkedList imagesOfTiles; + + public TilesetOverview() { + final File folder = new File("src/main/resources/tilesets/"); + view = new JLayeredPane(); + tilesetPanel = new JLayeredPane(); + scrollPane = new JScrollPane(tilesetPanel); + listFilesForFolder(folder); + } + + public void listFilesForFolder(File folder) { + activeTilesets = new LinkedList<>(); + for (final File fileEntry : folder.listFiles()) { + loadTileset(fileEntry.getName()); + } + JButton generate = new JButton("Generate Tileset Overview"); + generate.setBounds(50, offset, 200, 50); + generate.addActionListener(actionEvent -> { + generateOverview(); + }); + + add(generate); + + info = new JLabel(); + info.setBounds(300, 830, 200, 50); + add(info); + + tilesetPanel.setPreferredSize(new Dimension(630, 800)); + + scrollPane.setLocation(300, 0); + scrollPane.setBounds(300, 0, 650, 800); + scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + scrollPane.setWheelScrollingEnabled(true); + scrollPane.getVerticalScrollBar().setUnitIncrement(10); + + view.add(scrollPane); + add(view); + + setDefaultCloseOperation(EXIT_ON_CLOSE); + setBounds(0, 0, 1000, 1000); + setLocationRelativeTo(null); + setVisible(true); + setResizable(false); + } + + private void loadTileset(String name) { + JLabel text = new JLabel(name); + text.setBounds(50 , offset, 200, 50); + JCheckBox checkBox = new JCheckBox(); + checkBox.setBounds(220, offset, 30, 50); + checkBox.addActionListener(actionEvent -> { + if (activeTilesets.contains(name)) activeTilesets.remove(name); + else activeTilesets.add(name); + }); + checkBox.setName(name); + + add(text); + add(checkBox); + offset += 70; + } + + private void generateOverview() { + tilesetOffset = 0; + imagesOfTiles = new LinkedList<>(); + tilesetPanel.removeAll(); + for (String name : activeTilesets) { + JPanel tileset = new JPanel(); + LinkedList tileList = new LinkedList<>(); + BufferedImage image = null; + try { + image = ImageIO.read(new File("src/main/resources/tilesets/" + name)); + } catch (IOException e) { + e.printStackTrace(); + } + + int width = image.getWidth(); + int height = image.getHeight(); + int tileSize = 32; + + int Xtiles = width / tileSize; + int Ytiles = height / tileSize; + int tiles = Xtiles * Ytiles; + + Rectangle[] rectangles = new Rectangle[tiles]; + int count = 0; + for (int i = 0; i < rectangles.length / Ytiles; i++) { + for (int j = 0; j < rectangles.length / Xtiles; j++) { + rectangles[count] = new Rectangle(tileSize * i, tileSize * j, tileSize, tileSize); + count++; + } + } + for (int i = 0; i < tiles; i++) { + BufferedImage tileImage = image.getSubimage(rectangles[i].x, rectangles[i].y, rectangles[i].height, rectangles[i].width); + imagesOfTiles.add(tileImage); + ImageIcon imageIcon = new ImageIcon(tileImage); + JLabel tile = new JLabel("" + (imagesOfTiles.size() - 1) + "", imageIcon, JLabel.CENTER); + tile.setHorizontalTextPosition(JLabel.CENTER); + tile.setPreferredSize(new Dimension(tileSize, tileSize)); + tile.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + info.setIcon(new ImageIcon(tileImage.getScaledInstance(50, 50, Image.SCALE_DEFAULT))); + info.setText(tile.getText()); + } + }); + tileList.add(tile); + } +// + for (int i = 0; i < Ytiles; i++) { + for (int j = 0; j < Xtiles; j++) { + tileset.add(tileList.get(i + (j*Ytiles))); + } + } +// for (int i = 0; i < 16; i++) { +// tileset.add(tileList.get(i)); +// } + tileset.setBounds(0, tilesetOffset, width + (Xtiles * 6), height + (Ytiles * 6)); + tilesetOffset += height + + (Ytiles * 6); + tilesetPanel.add(tileset); + int panelWidth = tilesetPanel.getWidth(); + if (panelWidth < width + (Xtiles * 6)) panelWidth = width + (Xtiles * 6); + tilesetPanel.setPreferredSize(new Dimension(panelWidth, tilesetOffset)); + } + view.repaint(); + } +} diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index 9f5776d..296189a 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -110,7 +110,10 @@ public class Map { map.addInteractionEvent(new InteractionCell(x, y, event[1], new Dialog(window.getDialogBar()), map, window, false)); } else if (line[x].contains("TRIGGER")) { String[] trigger = line[x].split(","); - map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(window.getDialogBar()), map, window)); + if (trigger.length == 2) + map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(window.getDialogBar()), map, window)); + else + map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(window.getDialogBar()), map, window, Boolean.parseBoolean(trigger[2]))); } else if (line[x].equals("SPAWN")) { map.setIdExit(0); map.setSpawnPoint(x, y); diff --git a/src/main/resources/Openspace2.png b/src/main/resources/Openspace2.png deleted file mode 100644 index d858a2a..0000000 Binary files a/src/main/resources/Openspace2.png and /dev/null differ diff --git a/src/main/resources/dialogs/cutscenes/cutscene-error.txt b/src/main/resources/dialogs/cutscenes/cutscene-error.txt index c5efc6a..0e8a278 100644 --- a/src/main/resources/dialogs/cutscenes/cutscene-error.txt +++ b/src/main/resources/dialogs/cutscenes/cutscene-error.txt @@ -1,6 +1,6 @@ <1> false <1> error -<3> openspace 4 +<3> openspace 14 16 4 <3> Shit.. <5> null <5> null diff --git a/src/main/resources/dialogs/cutscenes/cutscene-work.txt b/src/main/resources/dialogs/cutscenes/cutscene-work.txt new file mode 100644 index 0000000..2b6ab62 --- /dev/null +++ b/src/main/resources/dialogs/cutscenes/cutscene-work.txt @@ -0,0 +1,3 @@ +<1> test +<3> null +<3> \ No newline at end of file diff --git a/src/main/resources/dialogs/nextstep.txt b/src/main/resources/dialogs/nextstep.txt new file mode 100644 index 0000000..786bc1e --- /dev/null +++ b/src/main/resources/dialogs/nextstep.txt @@ -0,0 +1,4 @@ +Ok, I should probably go back to my desk and check
out the Game-of-Prod's code to familiarize myself
with it. +I have a feeling this is going to be a long day.
But hey, new project is always exciting. + openspace 14 16 true + \ No newline at end of file diff --git a/src/main/resources/dialogs/ohhimark.txt b/src/main/resources/dialogs/ohhimark.txt index 18283c6..cddd546 100644 --- a/src/main/resources/dialogs/ohhimark.txt +++ b/src/main/resources/dialogs/ohhimark.txt @@ -7,4 +7,6 @@ I know, this is on very short notice
but as you've probably heard,
we ki And that someone is gonna be,
you guessed it, you. You start by tomorrow. You can go now. Bye. + office 4 2 true + openspace 6 4 false \ No newline at end of file diff --git a/src/main/resources/maps/office.txt b/src/main/resources/maps/office.txt index f1fe249..9f525c2 100644 --- a/src/main/resources/maps/office.txt +++ b/src/main/resources/maps/office.txt @@ -1,7 +1,7 @@ 20 13 BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK BLOCK BLOCK BLOCK DOORTO,true,0,3,boss BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK DOOR,true,locked BLOCK BLOCK BLOCK BLOCK DOOR,true,locked 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 TRIGGER,nextstep,false 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 BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK diff --git a/src/main/resources/maps/openspace.txt b/src/main/resources/maps/openspace.txt index 712e6ec..6e34227 100644 --- a/src/main/resources/maps/openspace.txt +++ b/src/main/resources/maps/openspace.txt @@ -15,7 +15,7 @@ BLOCK EMPTY block block inter,minecraft block block EMPTY BLOCK,u EMPTY EMPTY EM BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY DOOR,false 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,2,2,office EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY SPAWN block EMPTY block EMPTY BLOCK +BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,2,2,office EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY TRIGGER,cutscene-work,false block EMPTY block EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY block block EMPTY block block block 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 diff --git a/src/main/resources/A2_Ground.png b/src/main/resources/tilesets/A2_Ground.png similarity index 100% rename from src/main/resources/A2_Ground.png rename to src/main/resources/tilesets/A2_Ground.png diff --git a/src/main/resources/A5_Tiles.png b/src/main/resources/tilesets/A5_Tiles.png similarity index 100% rename from src/main/resources/A5_Tiles.png rename to src/main/resources/tilesets/A5_Tiles.png diff --git a/src/main/resources/CertificateOfShame.png b/src/main/resources/tilesets/CertificateOfShame.png similarity index 100% rename from src/main/resources/CertificateOfShame.png rename to src/main/resources/tilesets/CertificateOfShame.png diff --git a/src/main/resources/D_Inside_House.png b/src/main/resources/tilesets/D_Inside_House.png similarity index 100% rename from src/main/resources/D_Inside_House.png rename to src/main/resources/tilesets/D_Inside_House.png diff --git a/src/main/resources/D_OutDoor.png b/src/main/resources/tilesets/D_OutDoor.png similarity index 100% rename from src/main/resources/D_OutDoor.png rename to src/main/resources/tilesets/D_OutDoor.png diff --git a/src/main/resources/Openspace1.png b/src/main/resources/tilesets/Openspace1.png similarity index 100% rename from src/main/resources/Openspace1.png rename to src/main/resources/tilesets/Openspace1.png diff --git a/src/main/resources/tilesets/Openspace2.png b/src/main/resources/tilesets/Openspace2.png new file mode 100644 index 0000000..0599a8e Binary files /dev/null and b/src/main/resources/tilesets/Openspace2.png differ diff --git a/src/main/resources/dark-door.png b/src/main/resources/tilesets/dark-door.png similarity index 100% rename from src/main/resources/dark-door.png rename to src/main/resources/tilesets/dark-door.png diff --git a/src/main/resources/tutorialtiles.png b/src/main/resources/tilesets/tutorialtiles.png similarity index 100% rename from src/main/resources/tutorialtiles.png rename to src/main/resources/tilesets/tutorialtiles.png