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