From 52efb4032a18d61aac6744cc9aa478dc44c7da11 Mon Sep 17 00:00:00 2001 From: musilto9 Date: Fri, 24 Apr 2020 15:21:52 +0200 Subject: [PATCH] improved dialog --- .../gameOfProd/Cells/InteractionCell.java | 9 +++ .../java/ruscz/game/gameOfProd/Cells/Npc.java | 49 ++++++++++++---- .../game/gameOfProd/Dialog/DialogBar.java | 4 +- .../java/ruscz/game/gameOfProd/Map/Map.java | 7 +++ .../{100ň100.png => main-face.png} | Bin src/main/resources/dialogs/dialog.txt | 26 +++++++++ src/main/resources/maps/openspace.txt | 2 +- src/main/resources/save/savedGame/events.txt | 55 ------------------ src/main/resources/save/savedGame/person.txt | 6 -- src/main/resources/save/savedGame/village.txt | 1 - 10 files changed, 82 insertions(+), 77 deletions(-) rename src/main/resources/characters/{100ň100.png => main-face.png} (100%) diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index d9f7fe8..61d19b4 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -178,6 +178,15 @@ public class InteractionCell extends Cell { } readNextLine(); } + else if (data.contains("")) { + String[] directionSight = data.split(" "); + if (directionSight[1].equals("main")) + window.getMapManager().getActualMap().getPerson().setDirectionSight(Integer.parseInt(directionSight[2])); + else { + window.getMapManager().getActualMap().findNpcByName(directionSight[1]).setDirection(Integer.parseInt(directionSight[2])); + } + readNextLine(); + } else { if (data.contains("
")) data = "" + data + ""; diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java index 140d147..dfa346f 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java @@ -10,17 +10,27 @@ import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; public class Npc extends Person { private MapManager mapManager; private String name; + private int direction; + private int width; + private int height; + private int offsetX; + private int offsetY; + private int widthCoef; + private int heightCoef; + private String imageNpc; public Npc(int x, int y, String name, Map map, MapManager mapManager) { super(x, y, map); this.name = name; this.mapManager = mapManager; + loadNpc(); } public void move(int endX, int endY) { @@ -65,26 +75,41 @@ public class Npc extends Person { set(x, getY()); } + private void loadNpc() { + File dialogFile = new File("src/main/resources/characters/" + name + ".txt"); + Scanner scanner = null; + try { + scanner = new Scanner(dialogFile); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + scanner.nextLine(); + String[] imageInfo = scanner.nextLine().split(" "); + width = Integer.parseInt(imageInfo[0]); + height = Integer.parseInt(imageInfo[1]); + direction = Integer.parseInt(imageInfo[2]); + offsetX = Integer.parseInt(imageInfo[3]); + offsetY = Integer.parseInt(imageInfo[4]); + widthCoef = Integer.parseInt(imageInfo[5]); + heightCoef = Integer.parseInt(imageInfo[6]); + imageNpc = scanner.nextLine(); + } + @Override public void paint(Graphics2D g) { BufferedImage image = null; try { - File dialogFile = new File("src/main/resources/characters/" + name + ".txt"); - Scanner scanner = new Scanner(dialogFile); - scanner.nextLine(); - String[] imageInfo = scanner.nextLine().split(" "); - int width = Integer.parseInt(imageInfo[0]); - int height = Integer.parseInt(imageInfo[1]); - int direction = Integer.parseInt(imageInfo[2]); - int offsetX = Integer.parseInt(imageInfo[3]); - int offsetY = Integer.parseInt(imageInfo[4]); - int widthCoef = Integer.parseInt(imageInfo[5]); - int heightCoef = Integer.parseInt(imageInfo[6]); - image = ImageIO.read(new File("src/main/resources/characters/" + scanner.nextLine())).getSubimage(width * direction, 0, width, height); + image = ImageIO.read(new File("src/main/resources/characters/" + imageNpc)).getSubimage(width * direction, 0, width, height); g.drawImage(image, getX() * getSize() + (getSize() / 5) + offsetX, getY() * getSize() - (getSize() * 3/5) + offsetY, getSize() * widthCoef/5, getSize() * heightCoef/2, null); } catch (IOException e) { e.printStackTrace(); } } + + public void setDirection(int direction) { + this.direction = direction; + } + + public String getName() { return name; } } diff --git a/src/main/java/ruscz/game/gameOfProd/Dialog/DialogBar.java b/src/main/java/ruscz/game/gameOfProd/Dialog/DialogBar.java index b317fb7..b9ffa9f 100644 --- a/src/main/java/ruscz/game/gameOfProd/Dialog/DialogBar.java +++ b/src/main/java/ruscz/game/gameOfProd/Dialog/DialogBar.java @@ -25,9 +25,9 @@ public class DialogBar extends JPanel { WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT / 4, this); if (imageDialog != null){ - g.drawImage(imageDialog.getImage(), WindowOfFreeMove.CELL_SIZE / 4, WindowOfFreeMove.CELL_SIZE / 4, - WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT / 4 - WindowOfFreeMove.CELL_SIZE / 2, + g.drawImage(imageDialog.getImage(), WindowOfFreeMove.CELL_SIZE / 4, WindowOfFreeMove.CELL_SIZE / 4 + 3, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT / 4 - WindowOfFreeMove.CELL_SIZE / 2, + WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT / 4 - WindowOfFreeMove.CELL_SIZE / 2 - 3, this); } this.paintChildren(g); diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index ca9a1ed..9f5776d 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -400,6 +400,13 @@ public class Map { return null; } + public Npc findNpcByName(String name) { + for (Npc npc : npcs) { + if (npc.getName().equals(name)) return npc; + } + return null; + } + public int[] directionSightSwitch(int x, int y, int directionSight) { switch (directionSight) { case 1: diff --git a/src/main/resources/characters/100ň100.png b/src/main/resources/characters/main-face.png similarity index 100% rename from src/main/resources/characters/100ň100.png rename to src/main/resources/characters/main-face.png diff --git a/src/main/resources/dialogs/dialog.txt b/src/main/resources/dialogs/dialog.txt index adff964..d25534c 100644 --- a/src/main/resources/dialogs/dialog.txt +++ b/src/main/resources/dialogs/dialog.txt @@ -7,4 +7,30 @@ I mean he wouldn't just vanish, right? boy2-face.png voice5 Beats me. + main 2 + main-face.png + voice1 +Hi, guys. + girl1 1 + girl1-face.png + voice2 +Hi. + boy2 1 + boy2-face.png + voice5 +Hi, Mark. + girl1-face.png + voice2 +Mark, Hugo says you should go see him.
Sounds important. + main-face.png + voice1 +Is he in the meeting room? + girl1-face.png + voice2 +No, he's in his office upstairs. + main-face.png + voice1 +Thanks. + girl1 2 + boy2 0 \ No newline at end of file diff --git a/src/main/resources/maps/openspace.txt b/src/main/resources/maps/openspace.txt index 3a2505e..712e6ec 100644 --- a/src/main/resources/maps/openspace.txt +++ b/src/main/resources/maps/openspace.txt @@ -3,7 +3,7 @@ BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BL BLOCK block block block EMPTY block block 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,u EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block -BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY TRIGGER,dialog DOOR,false EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block +BLOCK block EMPTY EMPTY EMPTY EMPTY TRIGGER,dialog EMPTY DOOR,false EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block BLOCK BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block BLOCK BLOCK DOOR,true,locked,false BLOCK BLOCK BLOCK DOOR,true 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 block CHEST,confroom block block EMPTY block diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index 576140a..e69de29 100644 --- a/src/main/resources/save/savedGame/events.txt +++ b/src/main/resources/save/savedGame/events.txt @@ -1,55 +0,0 @@ - - tutorial - - - 11 - 6 - false - - - - - openspace - - - 7 - 4 - true - - - 15 - 7 - false - - - - - office - - - 1 - 9 - false - - - - - boss - - - 4 - 18 - true - - - - - treasure - - - 6 - 1 - false - - - diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index 3cc0ef4..e69de29 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -1,6 +0,0 @@ - - office - 17 - 11 - 2 - \ No newline at end of file diff --git a/src/main/resources/save/savedGame/village.txt b/src/main/resources/save/savedGame/village.txt index 1b4bc7b..e69de29 100644 --- a/src/main/resources/save/savedGame/village.txt +++ b/src/main/resources/save/savedGame/village.txt @@ -1 +0,0 @@ -TODO: Village \ No newline at end of file