From 75326f94377cbc1eedc4c4fd86c584a31f63ba30 Mon Sep 17 00:00:00 2001 From: iryupnik Date: Tue, 17 Mar 2020 21:34:18 +0100 Subject: [PATCH] Npc added --- src/main/java/ruscz/game/gameOfProd/Cells/Npc.java | 11 +++++++++++ src/main/java/ruscz/game/gameOfProd/Map/Map.java | 13 +++++++++++++ .../game/gameOfProd/Windows/WindowOfFreeMove.java | 11 +++++++---- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java index a1aa659..f456653 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java @@ -1,14 +1,19 @@ package ruscz.game.gameOfProd.Cells; import ruscz.game.gameOfProd.Map.Map; +import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; + +import java.awt.*; public class Npc extends Person { private int[] path; int x; int y; + Color color; public Npc(int x, int y, Map map) { super(x, y, map); + this.color = Color.cyan; } public void move(int endX, int endY) { @@ -46,4 +51,10 @@ public class Npc extends Person { set(x,y); } } + + @Override + public void paint(Graphics2D g) { + g.setColor(color); + g.fillOval(getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE); + } } diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index ae6acdf..04eb41a 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -20,6 +20,7 @@ public class Map { private LinkedList block; private LinkedList interactionCells; private LinkedList triggerCells; + private LinkedList npcs; private boolean isBlocked; private int idExit; private ImageCell imageCell; @@ -33,6 +34,7 @@ public class Map { moveToCells = new LinkedList(); interactionCells = new LinkedList(); triggerCells = new LinkedList(); + npcs = new LinkedList<>(); block = new LinkedList(); isBlocked = false; imageCell = new ImageCell(); @@ -63,6 +65,7 @@ public class Map { interactionCells = new LinkedList(); triggerCells = new LinkedList(); mapArray = new TypeOfCell[height][width]; + npcs = new LinkedList<>(); this.isBlocked = isBlocked; imageCell = new ImageCell(); @@ -92,6 +95,7 @@ public class Map { block = new LinkedList(); isBlocked = false; imageCell = new ImageCell(); + npcs = new LinkedList<>(); this.mapArray = mapArray; person = new Person(this); } @@ -114,6 +118,7 @@ public class Map { TypeOfCell[][] mapArray = new TypeOfCell[Integer.parseInt(size[0])][Integer.parseInt(size[1])]; Map map = new Map(mapArray); map.setName(name); + map.npcs = new LinkedList<>(); map.getImageCell().readMapFile(name + "-tileset"); LinkedList listOfMoveToCells = new LinkedList<>(); int y = 0; @@ -194,6 +199,14 @@ public class Map { triggerCells.add(triggerCell); } + public void setNpcs(Npc npc){ + npcs.add(npc); + } + + public LinkedList getNpcs(){ + return npcs; + } + public void setName(String name) { this.name = name; } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index 56e06fd..028b39b 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -1,9 +1,6 @@ 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.Cells.*; import ruscz.game.gameOfProd.Dialog.Dialog; import ruscz.game.gameOfProd.Dialog.DialogBar; import ruscz.game.gameOfProd.Map.Map; @@ -186,6 +183,9 @@ public class WindowOfFreeMove extends JFrame { m4.linkMaps(m4, this); m5.linkMaps(m5, this); + Npc npc = new Npc(1,1,m5); + m5.setNpcs(npc); + map = new MapPainter(mapLinkedList, canvas); setMap(m5); @@ -230,6 +230,9 @@ public class WindowOfFreeMove extends JFrame { for (Cell cell : map.getActualMap().getInteractionEventCells()) { cell.paint(g2D); } + for (Person person: map.getActualMap().getNpcs()){ + person.paint(g2D); + } } } }