package ruscz.game.gameOfProd.Cells; import ruscz.game.gameOfProd.Map.Map; import ruscz.game.gameOfProd.Map.MapManager; import ruscz.game.gameOfProd.Scripts.Direction; import ruscz.game.gameOfProd.Scripts.PathFinder; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; public class Npc extends Person { private MapManager mapManager; public Npc(int x, int y, Map map, MapManager mapManager) { super(x, y, map); this.mapManager = mapManager; setColor(Color.cyan); } public void move(int endX, int endY) { PathFinder pathFinder = new PathFinder(getMap()); for (Direction direction: pathFinder.getWayWithCollision(getX(), getY(), endX, endY)){ WindowOfFreeMove.sleep(500); switch (direction){ case UP: moveUp(); break; case DOWN: moveDown(); break; case LEFT: moveLeft(); break; case RIGHT: moveRight(); break; } mapManager.repaintCanvas(); } } private void moveUp() { int y = getY() - 1; set(getX(), y); } private void moveDown() { int y = getY() + 1; set(getX(), y); } private void moveLeft() { int x = getX() - 1; set(x, getY()); } private void moveRight() { int x = getX() + 1; set(x, getY()); } @Override public void paint(Graphics2D g) { BufferedImage image = null; try { image = ImageIO.read(new File("src/main/resources/characters/Fox/foxi.gif")); } catch (IOException e) { e.printStackTrace(); } g.drawImage(image, getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); } }