changed drawing of elements

This commit is contained in:
musilto9 2020-04-12 17:11:30 +02:00
parent 4a18642f0c
commit 5d2555b91b
19 changed files with 169 additions and 195 deletions

View File

@ -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;}

View File

@ -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);
}
}

View File

@ -30,6 +30,8 @@ public class Cell {
return y;
}
public int getSize() { return size; }
public void paint(Graphics2D g) {
g.setColor(color);
}

View File

@ -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() {

View File

@ -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);
}
}

View File

@ -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() {

View File

@ -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);
}
}

View File

@ -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; }

View File

@ -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() {

View File

@ -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;

View File

@ -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<String[]> 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;
}
}

View File

@ -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:

View File

@ -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) {

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -7,6 +7,8 @@
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6 6 6 6 6 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
@ -14,3 +16,5 @@
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,5 @@
<location>
<map>m1</map>
<x>1</x>
<y>7</y>
<map>openspace</map>
<x>8</x>
<y>15</y>
</location>