From 5d2555b91b74fc6294e34c3e58fe1553044a9e8e Mon Sep 17 00:00:00 2001 From: musilto9 Date: Sun, 12 Apr 2020 17:11:30 +0200 Subject: [PATCH] changed drawing of elements --- src/main/java/Game.java | 3 +- .../ruscz/game/gameOfProd/Cells/Block.java | 11 +-- .../ruscz/game/gameOfProd/Cells/Cell.java | 2 + .../ruscz/game/gameOfProd/Cells/DoorCell.java | 4 +- .../gameOfProd/Cells/EventMoveToCell.java | 11 +-- .../gameOfProd/Cells/InteractionCell.java | 4 +- .../java/ruscz/game/gameOfProd/Cells/Npc.java | 4 +- .../ruscz/game/gameOfProd/Cells/Person.java | 71 +++++++++------ .../game/gameOfProd/Cells/TriggerCell.java | 4 +- .../game/gameOfProd/Image/ImagePerson.java | 25 +++--- .../java/ruscz/game/gameOfProd/Map/Map.java | 88 +++++-------------- .../ruscz/game/gameOfProd/Map/MapManager.java | 8 +- .../ruscz/game/gameOfProd/Windows/Camera.java | 2 +- .../gameOfProd/Windows/WindowOfFreeMove.java | 78 +++++++++++----- .../game/gameOfProd/Windows/WindowOfMenu.java | 29 +----- src/main/resources/maps/office-tileset.txt | 4 + src/main/resources/maps/office.txt | 6 +- src/main/resources/maps/openspace.txt | 4 +- src/main/resources/save/savedGame/person.txt | 6 +- 19 files changed, 169 insertions(+), 195 deletions(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 1611396..eec15b2 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -27,7 +27,6 @@ public class Game extends JFrame { //tohle spustí na začátku menu add(menu); - menu.start(); //tohle spustí na začátku hru // add(freeMove); @@ -41,6 +40,8 @@ public class Game extends JFrame { setVisible(true); getContentPane().setBackground(Color.BLACK); setExtendedState(MAXIMIZED_BOTH); + getContentPane().getComponent(0).setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - (WINDOW_WIDTH * CELL_SIZE)) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - (WINDOW_HEIGHT * CELL_SIZE)) / 2); + getContentPane().getComponent(0).setSize(WINDOW_WIDTH * CELL_SIZE, WINDOW_HEIGHT * CELL_SIZE); } public Game game() {return this;} diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Block.java b/src/main/java/ruscz/game/gameOfProd/Cells/Block.java index 0cdf7b9..d6fbf90 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Block.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Block.java @@ -9,10 +9,6 @@ public class Block extends Cell { private ImageCell imageCell; private boolean paint; - public Block() { - super(-1, -1, WindowOfFreeMove.CELL_SIZE, Color.BLUE); - } - public Block(int x, int y, ImageCell imageCell, boolean paint) { super(x, y, WindowOfFreeMove.CELL_SIZE, Color.BLUE); this.imageCell = imageCell; @@ -20,15 +16,14 @@ public class Block extends Cell { } public boolean isInBlock(int x, int y) { - return (this. - getX() == x) && (this.getY() == y); + return (this.getX() == x) && (this.getY() == y); } @Override public void paint(Graphics2D g) { super.paint(g); if (paint) - g.drawImage(imageCell.getImagesOfTiles().get(imageCell.getImageFromCellMap("BLOCK")), getX() * WindowOfFreeMove.CELL_SIZE, - getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); + g.drawImage(imageCell.getImagesOfTiles().get(imageCell.getImageFromCellMap("BLOCK")), getX() * getSize(), + getY() * getSize(), getSize(), getSize(), null); } } \ No newline at end of file diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Cell.java b/src/main/java/ruscz/game/gameOfProd/Cells/Cell.java index 6a5bb8d..f230b03 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Cell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Cell.java @@ -30,6 +30,8 @@ public class Cell { return y; } + public int getSize() { return size; } + public void paint(Graphics2D g) { g.setColor(color); } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java index b86ee54..dab4df4 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java @@ -27,8 +27,8 @@ public class DoorCell extends InteractionCell { @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); + g.drawImage(super.getImageCell().getImagesOfTiles().get(super.getImageCell().getImageFromCellMap("DOOR") + open), getX() * getSize(), + getY() * getSize(), getSize(), getSize(), null); } public boolean isOpen() { diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java index 875a852..f42d289 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java @@ -16,13 +16,6 @@ public class EventMoveToCell extends Cell { return id; } - public EventMoveToCell(int id, int directionOut, int x, int y) { - super(x, y, WindowOfFreeMove.CELL_SIZE, Color.green); - this.id = id; - this.directionOut = directionOut; - this.map = new Map(WindowOfFreeMove.CANVAS_HEIGHT, WindowOfFreeMove.CANVAS_WIDTH,false); - } - public EventMoveToCell(int id, int directionOut, int x, int y, Map map, WindowOfFreeMove window, boolean paint){ super(x,y, WindowOfFreeMove.CELL_SIZE, Color.green); this.id = id; @@ -47,8 +40,8 @@ public class EventMoveToCell extends Cell { public void paint(Graphics2D g) { super.paint(g); if (paint) - g.drawImage(window.getMapManager().getActualMap().getImageCell().getImagesOfTiles().get(window.getMapManager().getActualMap().getImageCell().getImageFromCellMap("MOVETO")), getX() * WindowOfFreeMove.CELL_SIZE, - getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); + g.drawImage(window.getMapManager().getActualMap().getImageCell().getImagesOfTiles().get(window.getMapManager().getActualMap().getImageCell().getImageFromCellMap("MOVETO")), getX() * getSize(), + getY() * getSize(), getSize(), getSize(), null); // g.drawString(Integer.toString(getId()), getX()* WindowOfFreeMove.CELL_SIZE, getY()* WindowOfFreeMove.CELL_SIZE); } } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index 36fcf5f..82714c5 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -120,8 +120,8 @@ public class InteractionCell extends Cell { public void paint(Graphics2D g) { super.paint(g); if (paint) - g.drawImage(imageCell.getImagesOfTiles().get(imageCell.getImageFromCellMap("EVENT")), getX() * WindowOfFreeMove.CELL_SIZE, - getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); + g.drawImage(imageCell.getImagesOfTiles().get(imageCell.getImageFromCellMap("EVENT")), getX() * getSize(), + getY() * getSize(), getSize(), getSize(), null); } public ImageCell getImageCell() { diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java index bb89fea..887a5ee 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java @@ -71,7 +71,7 @@ public class Npc extends Person { } catch (IOException e) { e.printStackTrace(); } - g.drawImage(image, getX() * WindowOfFreeMove.CELL_SIZE, - getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); + g.drawImage(image, getX() * getSize(), + getY() * getSize(), getSize(), getSize(), null); } } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java index a3782bc..3c4955d 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java @@ -14,7 +14,7 @@ public class Person extends Cell { private int directionMoveLast; private boolean isMoving; private static boolean isInEvent; - private int size; + private int distanceOfAnimation; public Map getMap() { return map; @@ -34,7 +34,7 @@ public class Person extends Cell { this.map = map; this.directionSight = 3; this.isMoving = false; - this.size = WindowOfFreeMove.CELL_SIZE; + this.distanceOfAnimation = WindowOfFreeMove.CELL_SIZE; } public Person(int x, int y, Map map) { @@ -43,7 +43,7 @@ public class Person extends Cell { this.directionSight = 3; this.isMoving = false; this.map = map; - this.size = WindowOfFreeMove.CELL_SIZE; + this.distanceOfAnimation = WindowOfFreeMove.CELL_SIZE; } public void setDirectionMove(int directionMove) { @@ -190,7 +190,7 @@ public class Person extends Cell { public void stopPerson(){ directionMove = 0; directionMoveLast = 0; - size = 0; + distanceOfAnimation = 0; isMoving = false; } @@ -201,7 +201,7 @@ public class Person extends Cell { @Override public void paint(Graphics2D g) { super.paint(g); - if (size == 0) { + if (distanceOfAnimation == 0) { isMoving = false; } if (isMoving) { @@ -219,16 +219,18 @@ public class Person extends Cell { animateMove(g, 0); break; } - if (size > 0 && isMoving) { - size -= 2; + if (distanceOfAnimation > 0 && isMoving) { + distanceOfAnimation -= 2; } else { isMoving = false; } } else { - size = WindowOfFreeMove.CELL_SIZE; - g.drawImage(imagePerson.getImagesOfDirection()[directionSight + 4], getX() * WindowOfFreeMove.CELL_SIZE, - getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); + distanceOfAnimation = getSize(); +// g.drawImage(imagePerson.getImagesOfDirection()[directionSight + 4], getX() * getSize(), +// getY() * getSize(), getSize(), getSize(), null); + g.drawImage(imagePerson.getImagesOfDirection()[directionSight + 4], getX() * getSize(), + getY() * getSize() - (getSize() * 3/5), getSize(), getSize() * 3/2, null); } } @@ -237,30 +239,43 @@ public class Person extends Cell { int Ysize = 0; switch (direction) { case 0: - Ysize -= size; + Ysize -= distanceOfAnimation; break; case 1: - Xsize = size; + Xsize = distanceOfAnimation; break; case 2: - Ysize = size; + Ysize = distanceOfAnimation; break; case 3: - Xsize -= size; + Xsize -= distanceOfAnimation; break; } - if (size > WindowOfFreeMove.CELL_SIZE * 3 / 4) { - g.drawImage(imagePerson.getImagesOfDirection()[direction], getX() * WindowOfFreeMove.CELL_SIZE + Xsize, - getY() * WindowOfFreeMove.CELL_SIZE + Ysize, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); - } else if (size > WindowOfFreeMove.CELL_SIZE / 2) { - g.drawImage(imagePerson.getImagesOfDirection()[direction + 4], getX() * WindowOfFreeMove.CELL_SIZE + Xsize, - getY() * WindowOfFreeMove.CELL_SIZE + Ysize, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); - } else if (size > WindowOfFreeMove.CELL_SIZE / 4) { - g.drawImage(imagePerson.getImagesOfDirection()[direction + 8], getX() * WindowOfFreeMove.CELL_SIZE + Xsize, - getY() * WindowOfFreeMove.CELL_SIZE + Ysize, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); +// if (distanceOfAnimation > getSize() * 3 / 4) { +// g.drawImage(imagePerson.getImagesOfDirection()[direction], getX() * getSize() + Xsize, +// getY() * getSize() + Ysize, getSize(), getSize(), null); +// } else if (distanceOfAnimation > getSize() / 2) { +// g.drawImage(imagePerson.getImagesOfDirection()[direction + 4], getX() * getSize() + Xsize, +// getY() * getSize() + Ysize, getSize(), getSize(), null); +// } else if (distanceOfAnimation > getSize() / 4) { +// g.drawImage(imagePerson.getImagesOfDirection()[direction + 8], getX() * getSize() + Xsize, +// getY() * getSize() + Ysize, getSize(), getSize(), null); +// } else{ +// g.drawImage(imagePerson.getImagesOfDirection()[direction + 4], getX() * getSize() + Xsize, +// getY() * getSize() + Ysize, getSize(), getSize(), null); +// } + if (distanceOfAnimation > getSize() * 3 / 4) { + g.drawImage(imagePerson.getImagesOfDirection()[direction], getX() * getSize() + Xsize, + getY() * getSize() + Ysize - (getSize() * 3/5), getSize(), getSize() * 3/2, null); + } else if (distanceOfAnimation > getSize() / 2) { + g.drawImage(imagePerson.getImagesOfDirection()[direction + 4], getX() * getSize() + Xsize, + getY() * getSize() + Ysize - (getSize() * 3/5), getSize(), getSize() * 3/2, null); + } else if (distanceOfAnimation > getSize() / 4) { + g.drawImage(imagePerson.getImagesOfDirection()[direction + 8], getX() * getSize() + Xsize, + getY() * getSize() + Ysize - (getSize() * 3/5), getSize(), getSize() * 3/2, null); } else{ - g.drawImage(imagePerson.getImagesOfDirection()[direction + 4], getX() * WindowOfFreeMove.CELL_SIZE + Xsize, - getY() * WindowOfFreeMove.CELL_SIZE + Ysize, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); + g.drawImage(imagePerson.getImagesOfDirection()[direction + 4], getX() * getSize() + Xsize, + getY() * getSize() + Ysize - (getSize() * 3/5), getSize(), getSize() * 3/2, null); } } @@ -272,11 +287,11 @@ public class Person extends Cell { this.isMoving = isMoving; } - public void setSize(int size) { - this.size = size; + public void setDistance(int distance) { + this.distanceOfAnimation = distance; } - public int getSize() { return size; } + public int getDistance() { return distanceOfAnimation; } public int getDirectionMoveLast() {return directionMoveLast; } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java index cdf0d0d..9a62280 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java @@ -23,8 +23,8 @@ public class TriggerCell extends InteractionCell { @Override public void paint(Graphics2D g) { super.paint(g); - g.drawImage(super.getImageCell().getImagesOfTiles().get(super.getImageCell().getImageFromCellMap("TRIGGER")), getX() * WindowOfFreeMove.CELL_SIZE, - getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); + g.drawImage(super.getImageCell().getImagesOfTiles().get(super.getImageCell().getImageFromCellMap("TRIGGER")), getX() * getSize(), + getY() * getSize(), getSize(), getSize(), null); } public boolean getActive() { diff --git a/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java b/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java index 4f3fac1..93396a7 100644 --- a/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java +++ b/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java @@ -25,7 +25,8 @@ public class ImagePerson { for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { BufferedImage img = image.getSubimage(subimageWidth * i, subimageHeight * j, subimageWidth, subimageHeight); - imagesOfDirection[count] = resize(img); +// imagesOfDirection[count] = resize(img); + imagesOfDirection[count] = img; count++; } } @@ -48,24 +49,24 @@ public class ImagePerson { public BufferedImage resize(BufferedImage img) { Image tmp; - if (subimageWidth > WindowOfFreeMove.CELL_SIZE) { - int newHeight = subimageHeight * WindowOfFreeMove.CELL_SIZE / subimageWidth; - tmp = img.getScaledInstance(WindowOfFreeMove.CELL_SIZE, newHeight, Image.SCALE_SMOOTH); + if (subimageWidth > WindowOfFreeMove.CELL_SIZE * 2) { + int newHeight = subimageHeight * WindowOfFreeMove.CELL_SIZE * 2 / subimageWidth; + tmp = img.getScaledInstance(WindowOfFreeMove.CELL_SIZE * 2, newHeight, Image.SCALE_SMOOTH); } - else if (subimageHeight > WindowOfFreeMove.CELL_SIZE) { - int newWidth = subimageWidth * WindowOfFreeMove.CELL_SIZE / subimageHeight; - tmp = img.getScaledInstance(newWidth, WindowOfFreeMove.CELL_SIZE, Image.SCALE_SMOOTH); + else if (subimageHeight > WindowOfFreeMove.CELL_SIZE * 2) { + int newWidth = subimageWidth * WindowOfFreeMove.CELL_SIZE * 2 / subimageHeight; + tmp = img.getScaledInstance(newWidth, WindowOfFreeMove.CELL_SIZE * 2, Image.SCALE_SMOOTH); } - else if (subimageWidth < WindowOfFreeMove.CELL_SIZE && subimageHeight < WindowOfFreeMove.CELL_SIZE) { - int newWidth = subimageWidth * WindowOfFreeMove.CELL_SIZE / subimageHeight; - tmp = img.getScaledInstance(newWidth, WindowOfFreeMove.CELL_SIZE, Image.SCALE_SMOOTH); + else if (subimageWidth < WindowOfFreeMove.CELL_SIZE && subimageHeight < (WindowOfFreeMove.CELL_SIZE * 2)) { + int newWidth = subimageWidth * WindowOfFreeMove.CELL_SIZE * 2 / subimageHeight; + tmp = img.getScaledInstance(newWidth, (WindowOfFreeMove.CELL_SIZE * 2), Image.SCALE_SMOOTH); } else { tmp = img.getScaledInstance(subimageWidth, subimageHeight, Image.SCALE_SMOOTH); } - BufferedImage dimg = new BufferedImage(WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, BufferedImage.TYPE_INT_ARGB); + BufferedImage dimg = new BufferedImage(WindowOfFreeMove.CELL_SIZE * 2, WindowOfFreeMove.CELL_SIZE * 2, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = dimg.createGraphics(); - g2d.drawImage(tmp, (WindowOfFreeMove.CELL_SIZE - tmp.getWidth(null)) / 2, (WindowOfFreeMove.CELL_SIZE - tmp.getHeight(null)) / 2, null); + g2d.drawImage(tmp, (WindowOfFreeMove.CELL_SIZE * 2 - tmp.getWidth(null)) / 2, (WindowOfFreeMove.CELL_SIZE * 2 - tmp.getHeight(null)) / 2, null); g2d.dispose(); return dimg; diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index 9a20d97..7328e9d 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -23,67 +23,9 @@ public class Map { private int idExit; private ImageCell imageCell; private int[] canvasSize; - private WindowOfFreeMove window; private static Scanner scanner; - public Map(int height, int width) { - name = "Spawn"; - idExit = 0; - mapArray = new TypeOfCell[height][width]; - moveToCells = new LinkedList<>(); - interactionCells = new LinkedList<>(); - triggerCells = new LinkedList<>(); - doorCells = new LinkedList<>(); - npcs = new LinkedList<>(); - block = new LinkedList<>(); - imageCell = new ImageCell(); - - TypeOfCell type; - type = TypeOfCell.EMPTY; - - for (int i = 0; i < mapArray.length; i++) { - for (int j = 0; j < mapArray[0].length; j++) { - mapArray[0][j] = type; - mapArray[mapArray.length - 1][j] = type; - } - mapArray[i][0] = type; - mapArray[i][mapArray.length - 1] = type; - } - - person = new Person(this); - } - - public Map(int height, int width, Boolean isBlocked) { - name = "Spawn"; - idExit = 0; - moveToCells = new LinkedList<>(); - block = new LinkedList<>(); - interactionCells = new LinkedList<>(); - triggerCells = new LinkedList<>(); - doorCells = new LinkedList<>(); - mapArray = new TypeOfCell[height][width]; - npcs = new LinkedList<>(); - imageCell = new ImageCell(); - - TypeOfCell type; - if (isBlocked) - type = TypeOfCell.BLOCK; - else - type = TypeOfCell.EMPTY; - - for (int i = 0; i < mapArray.length / 2; i++) { - for (int j = 0; j < mapArray[0].length / 2; j++) { - mapArray[0][j] = type; - mapArray[mapArray.length - 1][j] = type; - } - mapArray[i][0] = type; - mapArray[i][mapArray[0].length - 1] = type; - } - person = new Person(this); - canvasSize = new int[2]; - } - public Map(TypeOfCell[][] mapArray) { idExit = 0; moveToCells = new LinkedList<>(); @@ -118,7 +60,6 @@ public class Map { map.setName(name); map.npcs = new LinkedList<>(); map.getImageCell().readMapFile(name); - LinkedList listOfMoveToCells = new LinkedList<>(); map.canvasSize[0] = Integer.parseInt(size[0]); map.canvasSize[1] = Integer.parseInt(size[1]); int y = 0; @@ -137,7 +78,7 @@ public class Map { String data = scanner.nextLine(); String[] line = data.split(" "); for (int x = 0; x < Integer.parseInt(size[0]); x++) { - TypeOfCell cellType = null; + TypeOfCell cellType; if (line[x].equals("BLOCK") || line[x].equals("block")) { cellType = TypeOfCell.BLOCK; map.getMapArray()[x][y] = cellType; @@ -149,20 +90,17 @@ public class Map { cellType = TypeOfCell.EMPTY; map.getMapArray()[x][y] = cellType; } else if (line[x].contains("INTER") || line[x].contains("inter")) { - ImageCell imageCell = new ImageCell(); String[] event = line[x].split(","); if (line[x].contains("INTER")) map.addInteractionEvent(new InteractionCell(x, y, event[1], new Dialog(window.getDialogBar()), map.getImageCell(), window, true)); else map.addInteractionEvent(new InteractionCell(x, y, event[1], new Dialog(window.getDialogBar()), map.getImageCell(), window, false)); } else if (line[x].contains("TRIGGER")) { - ImageCell imageCell = new ImageCell(); String[] trigger = line[x].split(","); 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)); @@ -338,7 +276,7 @@ public class Map { for (EventMoveToCell cell : moveToCells) if (x == cell.getX() && y == cell.getY()) return cell; - return moveToCells.getFirst(); + return null; } public InteractionCell findInteractionByXY(int x, int y, int directionSight) { @@ -359,14 +297,21 @@ public class Map { for (InteractionCell cell : interactionCells) if (x == cell.getX() && y == cell.getY()) return cell; - return interactionCells.getFirst(); + return null; + } + + public InteractionCell findInteractionByXY(int x, int y) { + for (InteractionCell cell : interactionCells) + if (x == cell.getX() && y == cell.getY()) + return cell; + return null; } public TriggerCell findTriggerByXY(int x, int y) { for (TriggerCell cell : triggerCells) if (x == cell.getX() && y == cell.getY()) return cell; - return triggerCells.getFirst(); + return null; } public DoorCell findDoorByXY(int x, int y, int directionSight) { @@ -387,13 +332,20 @@ public class Map { for (DoorCell cell : doorCells) if (x == cell.getX() && y == cell.getY()) return cell; - return doorCells.getFirst(); + return null; } public DoorCell findDoorByXY(int x, int y) { for (DoorCell cell : doorCells) if (x == cell.getX() && y == cell.getY()) return cell; - return doorCells.getFirst(); + return null; + } + + public Block findBlockByXY(int x, int y) { + for (Block cell : block) + if (x == cell.getX() && y == cell.getY()) + return cell; + return null; } } diff --git a/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java b/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java index a35b89f..d1447ec 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java @@ -74,28 +74,28 @@ public class MapManager { actualMap.getPerson().set(cell.getX(), cell.getY() - 1); actualMap.getPerson().setIsMoving(true); actualMap.getPerson().setDirectionMoveLast(WindowOfFreeMove.KEY_UP); - actualMap.getPerson().setSize(CELL_SIZE); + actualMap.getPerson().setDistance(CELL_SIZE); actualMap.getPerson().setDirectionSight(2); break; case 2: actualMap.getPerson().set(cell.getX() + 1, cell.getY()); actualMap.getPerson().setIsMoving(true); actualMap.getPerson().setDirectionMoveLast(WindowOfFreeMove.KEY_RIGHT); - actualMap.getPerson().setSize(CELL_SIZE); + actualMap.getPerson().setDistance(CELL_SIZE); actualMap.getPerson().setDirectionSight(3); break; case 3: actualMap.getPerson().set(cell.getX(), cell.getY() + 1); actualMap.getPerson().setIsMoving(true); actualMap.getPerson().setDirectionMoveLast(WindowOfFreeMove.KEY_DOWN); - actualMap.getPerson().setSize(CELL_SIZE); + actualMap.getPerson().setDistance(CELL_SIZE); actualMap.getPerson().setDirectionSight(0); break; case 4: actualMap.getPerson().set(cell.getX() - 1, cell.getY()); actualMap.getPerson().setIsMoving(true); actualMap.getPerson().setDirectionMoveLast(WindowOfFreeMove.KEY_LEFT); - actualMap.getPerson().setSize(CELL_SIZE); + actualMap.getPerson().setDistance(CELL_SIZE); actualMap.getPerson().setDirectionSight(1); break; default: diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java b/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java index b497866..f4bdb38 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java @@ -35,7 +35,7 @@ public class Camera { int cameraOffsetX = (-1) * CELL_SIZE * (window.getMapManager().getActualMap().getPerson().getX() - WINDOW_WIDTH / 2); int cameraOffsetY = (-1) * CELL_SIZE * (window.getMapManager().getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2); int direction = window.getMapManager().getActualMap().getPerson().getDirectionMoveLast(); - int size = (-1) * window.getMapManager().getActualMap().getPerson().getSize(); + int size = (-1) * window.getMapManager().getActualMap().getPerson().getDistance(); int Ysize = 0; int Xsize = 0; switch (direction) { diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index ae908fe..9b068d7 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -183,36 +183,70 @@ public class WindowOfFreeMove extends JLayeredPane { public class Canvas extends JPanel { @Override +// public void paint(Graphics g) { +// if (isReadyToPaint) { +// super.paint(g); +// Graphics2D g2D = (Graphics2D) g; +// g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, +// RenderingHints.VALUE_ANTIALIAS_ON); +// for (int i = 0; i < mapManager.getActualMap().getCanvasSize()[0]; i++) { +// for (int j = 0; j < mapManager.getActualMap().getCanvasSize()[1]; j++) { +// mapManager.getActualMap().getImageCell().paintBackground(g2D, i, j); +// } +// } +// for (Cell cell : mapManager.getActualMap().getMoveToCells()) { +// cell.paint(g2D); +// } +// for (Cell cell : mapManager.getActualMap().getBlocks()) { +// cell.paint(g2D); +// } +// 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); +// } +// for (int i = 0; i < mapManager.getActualMap().getCanvasSize()[0]; i++) { +// for (int j = 0; j < mapManager.getActualMap().getCanvasSize()[1]; j++) { +// mapManager.getActualMap().getImageCell().paintForeground(g2D, i, j); +// } +// } +// mapManager.getActualMap().getPerson().paint(g2D); +// } +// } + public void paint(Graphics g) { if (isReadyToPaint) { super.paint(g); Graphics2D g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - for (int i = 0; i < mapManager.getActualMap().getCanvasSize()[0]; i++) { - for (int j = 0; j < mapManager.getActualMap().getCanvasSize()[1]; j++) { - mapManager.getActualMap().getImageCell().paintBackground(g2D, i, j); + for (int i = 0; i < mapManager.getActualMap().getCanvasSize()[1]; i++) { + for (int j = 0; j < mapManager.getActualMap().getCanvasSize()[0]; j++) { + mapManager.getActualMap().getImageCell().paintBackground(g2D, j, i); + } + for (Cell cell : mapManager.getActualMap().getMoveToCells()) { + if (cell.getY() == i) cell.paint(g2D); + } + for (Cell cell : mapManager.getActualMap().getBlocks()) { + if (cell.getY() == i) cell.paint(g2D); + } + if (mapManager.getActualMap().getPerson().getY() == i && mapManager.getActualMap().getPerson().getDirectionMoveLast() != KEY_UP) mapManager.getActualMap().getPerson().paint(g2D); + for (Cell cell : mapManager.getActualMap().getInteractionEventCells()) { + if (cell.getY() == i) cell.paint(g2D); + } + if (mapManager.getActualMap().getPerson().getY() == (i-1) && mapManager.getActualMap().getPerson().getDirectionMoveLast() == KEY_UP) mapManager.getActualMap().getPerson().paint(g2D); + for (Cell cell : mapManager.getActualMap().getDoorCells()) { + if (cell.getY() == i) cell.paint(g2D); + } + for (Person person : mapManager.getActualMap().getNpcs()) { + if (person.getY() == i) person.paint(g2D); } - } - for (Cell cell : mapManager.getActualMap().getMoveToCells()) { - cell.paint(g2D); - } - mapManager.getActualMap().getPerson().paint(g2D); - for (Cell cell : mapManager.getActualMap().getBlocks()) { - cell.paint(g2D); - } - 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); - } - for (int i = 0; i < mapManager.getActualMap().getCanvasSize()[0]; i++) { for (int j = 0; j < mapManager.getActualMap().getCanvasSize()[1]; j++) { - mapManager.getActualMap().getImageCell().paintForeground(g2D, i, j); + mapManager.getActualMap().getImageCell().paintForeground(g2D, j, i); } } } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java index d2877ac..d93f601 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java @@ -11,9 +11,6 @@ public class WindowOfMenu extends JLayeredPane { public static final int WINDOW_HEIGHT = 13; public static final int CELL_SIZE = 50; - private static final int KEY_FULLSCREEN = 115; - private static final int KEY_ESCAPE = 27; - private JFrame game; private WindowOfFreeMove freeMove; private JButton startNewGame; @@ -27,7 +24,6 @@ public class WindowOfMenu extends JLayeredPane { startNewGame = new JButton("START NEW GAME"); //startNewGame.setFocusable(false); startNewGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 -70,200,30); - startNewGame.setActionCommand("startNewGame"); startNewGame.addActionListener(actionEvent -> { cleanUp(); game.add(freeMove); @@ -38,7 +34,6 @@ public class WindowOfMenu extends JLayeredPane { loadSavedGame = new JButton("LOAD SAVED GAME"); //loadSavedGame.setFocusable(false); loadSavedGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2,200,30); - loadSavedGame.setActionCommand("loadSavedGame"); loadSavedGame.addActionListener(actionEvent -> { cleanUp(); game.add(freeMove); @@ -48,26 +43,12 @@ public class WindowOfMenu extends JLayeredPane { exitGame = new JButton("EXIT GAME"); exitGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 + 70,200,30); - exitGame.setActionCommand("exitGame"); exitGame.addActionListener(actionEvent -> game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING))); add(startNewGame); add(loadSavedGame); add(exitGame); - setVisible(false); } - - - public void start(){ - Timer timer = new Timer( 0, actionEvent -> { - setVisible(false); - centerContent(); - this.repaint(); - setVisible(true); - }); - timer.start(); - } - private void cleanUp() { setVisible(false); startNewGame.removeActionListener(startNewGame.getActionListeners()[0]); @@ -77,16 +58,8 @@ public class WindowOfMenu extends JLayeredPane { game.remove(this); menu().revalidate(); menu().repaint(); - freeMove.setCursor(freeMove.getToolkit().createCustomCursor( - new BufferedImage( 1, 1, BufferedImage.TYPE_INT_ARGB ), - new Point(), - null ) ); + freeMove.setCursor(freeMove.getToolkit().createCustomCursor(new BufferedImage( 1, 1, BufferedImage.TYPE_INT_ARGB ), new Point(), null )); } public WindowOfMenu menu() { return this; } - - public void centerContent() { - game.getComponents()[0].setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - (WINDOW_WIDTH * CELL_SIZE)) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - (WINDOW_HEIGHT * CELL_SIZE)) / 2); - game.getComponents()[0].setSize(WINDOW_WIDTH * CELL_SIZE, WINDOW_HEIGHT * CELL_SIZE); - } } diff --git a/src/main/resources/maps/office-tileset.txt b/src/main/resources/maps/office-tileset.txt index 79fd172..cc005af 100644 --- a/src/main/resources/maps/office-tileset.txt +++ b/src/main/resources/maps/office-tileset.txt @@ -7,10 +7,14 @@ 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 +6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 +6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 86 86 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 86 86 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 +6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 +6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 \ No newline at end of file diff --git a/src/main/resources/maps/office.txt b/src/main/resources/maps/office.txt index e53998e..2598b8b 100644 --- a/src/main/resources/maps/office.txt +++ b/src/main/resources/maps/office.txt @@ -1,13 +1,17 @@ -20 12 +20 16 +BLOCK BLOCK BLOCK BLOCK DOOR BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false 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 BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK +BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,1,2,openspace EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,1,2,openspace EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK +BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK 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 BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK +BLOCK BLOCK DOOR,locked,false 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 DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK \ No newline at end of file diff --git a/src/main/resources/maps/openspace.txt b/src/main/resources/maps/openspace.txt index 415a2e5..db2b795 100644 --- a/src/main/resources/maps/openspace.txt +++ b/src/main/resources/maps/openspace.txt @@ -19,10 +19,10 @@ BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,0,2,m1 EMPTY EMPTY EMPTY EMPTY 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 -BLOCK block EMPTY EMPTY EMPTY block EMPTY EMPTY block EMPTY EMPTY block EMPTY EMPTY EMPTY block EMPTY EMPTY block BLOCK +BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block EMPTY EMPTY EMPTY block EMPTY EMPTY block BLOCK BLOCK block block EMPTY block block EMPTY block block EMPTY EMPTY block block EMPTY block block EMPTY block 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 block EMPTY block EMPTY EMPTY EMPTY block EMPTY EMPTY EMPTY block EMPTY block EMPTY EMPTY EMPTY block block +BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block EMPTY block EMPTY EMPTY EMPTY block block BLOCK block block EMPTY block block EMPTY block block EMPTY EMPTY block block EMPTY block block EMPTY block block 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 diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index ee5b150..d826f54 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -1,5 +1,5 @@ - m1 - 1 - 7 + openspace + 8 + 15 \ No newline at end of file