code clean-up
This commit is contained in:
parent
5e4d1f572f
commit
d8eef8e8c1
@ -32,6 +32,5 @@ public class Cell {
|
|||||||
|
|
||||||
public void paint(Graphics2D g) {
|
public void paint(Graphics2D g) {
|
||||||
g.setColor(color);
|
g.setColor(color);
|
||||||
// g.fillOval(x*size, y*size, size, size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,10 +33,9 @@ public class EventMoveToCell extends Cell {
|
|||||||
public int getDirectionOut() { return directionOut; }
|
public int getDirectionOut() { return directionOut; }
|
||||||
|
|
||||||
public void moveToMap() {
|
public void moveToMap() {
|
||||||
//window.getMap().getPerson().stopPerson();
|
window.getMapManager().getActualMap().setIdExit(id);
|
||||||
window.getMapPainter().getActualMap().setIdExit(id);
|
window.setMapManager(this.map);
|
||||||
window.setMapPainter(this.map);
|
window.getMapManager().getActualMap().setIdExit(id);
|
||||||
window.getMapPainter().getActualMap().setIdExit(id);
|
|
||||||
window.paintMapOnWindow();
|
window.paintMapOnWindow();
|
||||||
window.repaintCanvas();
|
window.repaintCanvas();
|
||||||
window.setCanPersonMove(true);
|
window.setCanPersonMove(true);
|
||||||
@ -45,7 +44,7 @@ public class EventMoveToCell extends Cell {
|
|||||||
@Override
|
@Override
|
||||||
public void paint(Graphics2D g) {
|
public void paint(Graphics2D g) {
|
||||||
super.paint(g);
|
super.paint(g);
|
||||||
g.drawImage(window.getMapPainter().getActualMap().getImageCell().getImagesOfTiles().get(277), getX() * WindowOfFreeMove.CELL_SIZE,
|
g.drawImage(window.getMapManager().getActualMap().getImageCell().getImagesOfTiles().get(277), getX() * WindowOfFreeMove.CELL_SIZE,
|
||||||
getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
|
getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
|
||||||
g.drawString(Integer.toString(getId()), getX()* WindowOfFreeMove.CELL_SIZE, getY()* WindowOfFreeMove.CELL_SIZE);
|
g.drawString(Integer.toString(getId()), getX()* WindowOfFreeMove.CELL_SIZE, getY()* WindowOfFreeMove.CELL_SIZE);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,6 @@ package ruscz.game.gameOfProd.Cells;
|
|||||||
import ruscz.game.gameOfProd.Dialog.Dialog;
|
import ruscz.game.gameOfProd.Dialog.Dialog;
|
||||||
import ruscz.game.gameOfProd.Image.ImageCell;
|
import ruscz.game.gameOfProd.Image.ImageCell;
|
||||||
import ruscz.game.gameOfProd.Image.ImageDialog;
|
import ruscz.game.gameOfProd.Image.ImageDialog;
|
||||||
import ruscz.game.gameOfProd.Map.Map;
|
|
||||||
import ruscz.game.gameOfProd.Map.MapPainter;
|
|
||||||
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -12,8 +10,6 @@ import java.io.File;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import static ruscz.game.gameOfProd.Windows.WindowOfFreeMove.*;
|
|
||||||
|
|
||||||
public class InteractionCell extends Cell {
|
public class InteractionCell extends Cell {
|
||||||
private String message;
|
private String message;
|
||||||
private ruscz.game.gameOfProd.Dialog.Dialog dialog;
|
private ruscz.game.gameOfProd.Dialog.Dialog dialog;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package ruscz.game.gameOfProd.Cells;
|
package ruscz.game.gameOfProd.Cells;
|
||||||
|
|
||||||
import ruscz.game.gameOfProd.Map.Map;
|
import ruscz.game.gameOfProd.Map.Map;
|
||||||
import ruscz.game.gameOfProd.Map.MapPainter;
|
import ruscz.game.gameOfProd.Map.MapManager;
|
||||||
import ruscz.game.gameOfProd.Scripts.Direction;
|
import ruscz.game.gameOfProd.Scripts.Direction;
|
||||||
import ruscz.game.gameOfProd.Scripts.PathFinder;
|
import ruscz.game.gameOfProd.Scripts.PathFinder;
|
||||||
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
@ -9,11 +9,11 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class Npc extends Person {
|
public class Npc extends Person {
|
||||||
private MapPainter mapPainter;
|
private MapManager mapManager;
|
||||||
|
|
||||||
public Npc(int x, int y, Map map, MapPainter mapPainter) {
|
public Npc(int x, int y, Map map, MapManager mapManager) {
|
||||||
super(x, y, map);
|
super(x, y, map);
|
||||||
this.mapPainter = mapPainter;
|
this.mapManager = mapManager;
|
||||||
setColor(Color.cyan);
|
setColor(Color.cyan);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ public class Npc extends Person {
|
|||||||
moveRight();
|
moveRight();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mapPainter.repaintCanvas();
|
mapManager.repaintCanvas();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,8 +14,6 @@ public class ImagePerson {
|
|||||||
private BufferedImage[] imagesOfDirection;
|
private BufferedImage[] imagesOfDirection;
|
||||||
private int subimageWidth;
|
private int subimageWidth;
|
||||||
private int subimageHeight;
|
private int subimageHeight;
|
||||||
private Dimension imgSize = new Dimension(subimageWidth, subimageHeight);
|
|
||||||
private Dimension boundary = new Dimension(WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE);
|
|
||||||
|
|
||||||
public void setAllImagesOfDirection(Rectangle[] rectangles){
|
public void setAllImagesOfDirection(Rectangle[] rectangles){
|
||||||
imagesOfDirection = new BufferedImage[12];
|
imagesOfDirection = new BufferedImage[12];
|
||||||
|
|||||||
@ -5,10 +5,8 @@ import ruscz.game.gameOfProd.Dialog.Dialog;
|
|||||||
import ruscz.game.gameOfProd.Image.ImageCell;
|
import ruscz.game.gameOfProd.Image.ImageCell;
|
||||||
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
|||||||
@ -10,12 +10,12 @@ import java.util.LinkedList;
|
|||||||
|
|
||||||
import static ruscz.game.gameOfProd.Windows.WindowOfFreeMove.*;
|
import static ruscz.game.gameOfProd.Windows.WindowOfFreeMove.*;
|
||||||
|
|
||||||
public class MapPainter {
|
public class MapManager {
|
||||||
private WindowOfFreeMove.Canvas canvas;
|
private WindowOfFreeMove.Canvas canvas;
|
||||||
private LinkedList<Map> maps;
|
private LinkedList<Map> maps;
|
||||||
private Map actualMap;
|
private Map actualMap;
|
||||||
|
|
||||||
public MapPainter(LinkedList<Map> maps, WindowOfFreeMove.Canvas canvas) {
|
public MapManager(LinkedList<Map> maps, WindowOfFreeMove.Canvas canvas) {
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
this.maps = maps;
|
this.maps = maps;
|
||||||
}
|
}
|
||||||
@ -32,10 +32,10 @@ public class Camera {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void moveBoundCamera() {
|
public void moveBoundCamera() {
|
||||||
int cameraOffsetX = (-1) * CELL_SIZE * (window.getMapPainter().getActualMap().getPerson().getX() - WINDOW_WIDTH / 2);
|
int cameraOffsetX = (-1) * CELL_SIZE * (window.getMapManager().getActualMap().getPerson().getX() - WINDOW_WIDTH / 2);
|
||||||
int cameraOffsetY = (-1) * CELL_SIZE * (window.getMapPainter().getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2);
|
int cameraOffsetY = (-1) * CELL_SIZE * (window.getMapManager().getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2);
|
||||||
int direction = window.getMapPainter().getActualMap().getPerson().getDirectionMoveLast();
|
int direction = window.getMapManager().getActualMap().getPerson().getDirectionMoveLast();
|
||||||
int size = (-1) * window.getMapPainter().getActualMap().getPerson().getSize();
|
int size = (-1) * window.getMapManager().getActualMap().getPerson().getSize();
|
||||||
int Ysize = 0;
|
int Ysize = 0;
|
||||||
int Xsize = 0;
|
int Xsize = 0;
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
@ -52,7 +52,7 @@ public class Camera {
|
|||||||
Ysize -= size;
|
Ysize -= size;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!window.getMapPainter().getActualMap().getPerson().getIsMoving()) {
|
if (!window.getMapManager().getActualMap().getPerson().getIsMoving()) {
|
||||||
Xsize = 0;
|
Xsize = 0;
|
||||||
Ysize = 0;
|
Ysize = 0;
|
||||||
}
|
}
|
||||||
@ -123,8 +123,8 @@ public class Camera {
|
|||||||
|
|
||||||
public void returnFreeCamera() {
|
public void returnFreeCamera() {
|
||||||
setCameraStart();
|
setCameraStart();
|
||||||
endX = (-1) * CELL_SIZE * (window.getMapPainter().getActualMap().getPerson().getX() - WINDOW_WIDTH / 2);
|
endX = (-1) * CELL_SIZE * (window.getMapManager().getActualMap().getPerson().getX() - WINDOW_WIDTH / 2);
|
||||||
endY = (-1) * CELL_SIZE * (window.getMapPainter().getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2);
|
endY = (-1) * CELL_SIZE * (window.getMapManager().getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2);
|
||||||
if (endX > 0) {
|
if (endX > 0) {
|
||||||
endX = 0;
|
endX = 0;
|
||||||
}
|
}
|
||||||
@ -141,15 +141,11 @@ public class Camera {
|
|||||||
isReturning = true;
|
isReturning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopCamera() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void boundCamera() {
|
public void boundCamera() {
|
||||||
isBound = true;
|
isBound = true;
|
||||||
isReturning = false;
|
isReturning = false;
|
||||||
window.setCanPersonMove(true);
|
window.setCanPersonMove(true);
|
||||||
window.getMapPainter().getActualMap().getPerson().setInEvent(false);
|
window.getMapManager().getActualMap().getPerson().setInEvent(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCameraStart() {
|
public void setCameraStart() {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package ruscz.game.gameOfProd.Windows;
|
|||||||
import ruscz.game.gameOfProd.Cells.*;
|
import ruscz.game.gameOfProd.Cells.*;
|
||||||
import ruscz.game.gameOfProd.Dialog.DialogBar;
|
import ruscz.game.gameOfProd.Dialog.DialogBar;
|
||||||
import ruscz.game.gameOfProd.Map.Map;
|
import ruscz.game.gameOfProd.Map.Map;
|
||||||
import ruscz.game.gameOfProd.Map.MapPainter;
|
import ruscz.game.gameOfProd.Map.MapManager;
|
||||||
import ruscz.game.gameOfProd.Sounds.MusicManager;
|
import ruscz.game.gameOfProd.Sounds.MusicManager;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -35,15 +35,15 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
|
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
private DialogBar dialogBar;
|
private DialogBar dialogBar;
|
||||||
private MapPainter mapPainter;
|
private MapManager mapManager;
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
private Timer inputTimer;
|
private Timer inputTimer;
|
||||||
private MusicManager musicManager;
|
private MusicManager musicManager;
|
||||||
|
|
||||||
private LinkedList<Map> mapLinkedList;
|
private LinkedList<Map> mapLinkedList;
|
||||||
|
|
||||||
public MapPainter getMapPainter() {
|
public MapManager getMapManager() {
|
||||||
return mapPainter;
|
return mapManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void repaintCanvas() {
|
public void repaintCanvas() {
|
||||||
@ -58,12 +58,12 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
WindowOfFreeMove.canPersonMove = canPersonMove;
|
WindowOfFreeMove.canPersonMove = canPersonMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMapPainter(Map mapPainter) {
|
public void setMapManager(Map mapManager) {
|
||||||
this.mapPainter.setMap(mapPainter);
|
this.mapManager.setMap(mapManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintMapOnWindow() {
|
public void paintMapOnWindow() {
|
||||||
this.mapPainter.createMap();
|
this.mapManager.createMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setNextMove(int nextMove) {
|
public static void setNextMove(int nextMove) {
|
||||||
@ -103,16 +103,16 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
dialogBar.setLayout(null);
|
dialogBar.setLayout(null);
|
||||||
|
|
||||||
inputTimer = new Timer(10, actionEvent -> {
|
inputTimer = new Timer(10, actionEvent -> {
|
||||||
if (!mapPainter.getActualMap().getPerson().getIsMoving() && canPersonMove && nextMove != KEY_EVENT) {
|
if (!mapManager.getActualMap().getPerson().getIsMoving() && canPersonMove && nextMove != KEY_EVENT) {
|
||||||
mapPainter.getActualMap().getPerson().setDirectionMove(nextMove);
|
mapManager.getActualMap().getPerson().setDirectionMove(nextMove);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addKeyListener(new KeyAdapter() {
|
addKeyListener(new KeyAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent e) {
|
public void keyTyped(KeyEvent e) {
|
||||||
if (!mapPainter.getActualMap().getPerson().getIsMoving() && canPersonMove || nextMove == KEY_EVENT) {
|
if (!mapManager.getActualMap().getPerson().getIsMoving() && canPersonMove || nextMove == KEY_EVENT) {
|
||||||
mapPainter.getActualMap().getPerson().setDirectionMove(nextMove);
|
mapManager.getActualMap().getPerson().setDirectionMove(nextMove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -138,10 +138,6 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
nextMove = e.getKeyCode();
|
nextMove = e.getKeyCode();
|
||||||
inputTimer.start();
|
inputTimer.start();
|
||||||
}
|
}
|
||||||
// if (canPersonMove && !map.getPerson().getIsMoving() && preventDoubleMove) {
|
|
||||||
// map.getPerson().setDirectionMove(e.getKeyCode());
|
|
||||||
// }
|
|
||||||
// preventDoubleMove = !map.getPerson().getIsMoving();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -214,27 +210,27 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
m5.linkMaps(m5, this);
|
m5.linkMaps(m5, this);
|
||||||
m6.linkMaps(m6, this);
|
m6.linkMaps(m6, this);
|
||||||
|
|
||||||
mapPainter = new MapPainter(mapLinkedList, canvas);
|
mapManager = new MapManager(mapLinkedList, canvas);
|
||||||
|
|
||||||
int startX = 1;
|
int startX = 1;
|
||||||
int startY = 1;
|
int startY = 1;
|
||||||
int endX = 8;
|
int endX = 8;
|
||||||
int endY = 8;
|
int endY = 8;
|
||||||
|
|
||||||
setMapPainter(m5);
|
setMapManager(m5);
|
||||||
|
|
||||||
camera.moveCamera();
|
camera.moveCamera();
|
||||||
mapPainter.createMap();
|
mapManager.createMap();
|
||||||
isReadyToPaint = true;
|
isReadyToPaint = true;
|
||||||
canvas.repaint();
|
canvas.repaint();
|
||||||
|
|
||||||
Npc npc2 = new Npc(startX, startY, m6, mapPainter);
|
Npc npc2 = new Npc(startX, startY, m6, mapManager);
|
||||||
m6.setNpcs(npc2);
|
m6.setNpcs(npc2);
|
||||||
|
|
||||||
musicManager = new MusicManager("Town1.wav");
|
musicManager = new MusicManager("Town1.wav");
|
||||||
musicManager.playMusic();
|
musicManager.playMusic();
|
||||||
Timer timer = new Timer(10, actionEvent -> {
|
Timer timer = new Timer(10, actionEvent -> {
|
||||||
mapPainter.getActualMap().getPerson().move();
|
mapManager.getActualMap().getPerson().move();
|
||||||
camera.moveCamera();
|
camera.moveCamera();
|
||||||
canvas.repaint();
|
canvas.repaint();
|
||||||
dialogBar.repaint();
|
dialogBar.repaint();
|
||||||
@ -255,22 +251,22 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
Graphics2D g2D = (Graphics2D) g;
|
Graphics2D g2D = (Graphics2D) g;
|
||||||
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
for (int i = 0; i < mapPainter.getActualMap().getCanvasSize()[0]; i++) {
|
for (int i = 0; i < mapManager.getActualMap().getCanvasSize()[0]; i++) {
|
||||||
for (int j = 0; j < mapPainter.getActualMap().getCanvasSize()[1]; j++) {
|
for (int j = 0; j < mapManager.getActualMap().getCanvasSize()[1]; j++) {
|
||||||
mapPainter.getActualMap().getImageCell().paintBackground(g2D, i, j);
|
mapManager.getActualMap().getImageCell().paintBackground(g2D, i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Cell cell : mapPainter.getActualMap().getMoveToCells()) {
|
for (Cell cell : mapManager.getActualMap().getMoveToCells()) {
|
||||||
cell.paint(g2D);
|
cell.paint(g2D);
|
||||||
}
|
}
|
||||||
mapPainter.getActualMap().getPerson().paint(g2D);
|
mapManager.getActualMap().getPerson().paint(g2D);
|
||||||
for (Cell cell : mapPainter.getActualMap().getBlocks()) {
|
for (Cell cell : mapManager.getActualMap().getBlocks()) {
|
||||||
cell.paint(g2D);
|
cell.paint(g2D);
|
||||||
}
|
}
|
||||||
for (Cell cell : mapPainter.getActualMap().getInteractionEventCells()) {
|
for (Cell cell : mapManager.getActualMap().getInteractionEventCells()) {
|
||||||
cell.paint(g2D);
|
cell.paint(g2D);
|
||||||
}
|
}
|
||||||
for (Person person : mapPainter.getActualMap().getNpcs()) {
|
for (Person person : mapManager.getActualMap().getNpcs()) {
|
||||||
person.paint(g2D);
|
person.paint(g2D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user