Small fixes

This commit is contained in:
iryupnik 2020-03-02 20:37:50 +01:00
parent 961f5a3b0e
commit 05f2ac726d
4 changed files with 58 additions and 36 deletions

View File

@ -35,10 +35,25 @@ public class EventMoveToCell extends Cell {
public void moveToMap() {
WindowOfFreeMove.getMap().setIdExit(id);
WindowOfFreeMove.setMap(this.map);
WindowOfFreeMove.getMap().getPerson().setDirectionSight(idToDirectionSight());
WindowOfFreeMove.getMap().setIdExit(id);
WindowOfFreeMove.paintMapOnWindow();
}
private int idToDirectionSight(){
switch (directionOut){
case 1:
return 0;
case 2:
return 1;
case 3:
return 2;
case 4:
return 3;
}
return 0;
}
@Override
public void paint(Graphics2D g) {
super.paint(g);

View File

@ -1,4 +1,5 @@
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.io.IOException;
@ -26,7 +27,7 @@ public class ImagePerson {
throw new IllegalArgumentException();
for (int i = 0; i < animationOfMoving.length; i++){
animationOfMoving[i] = Toolkit.getDefaultToolkit().createImage(getClass().getResource(animationOfMovingNames[i]));
animationOfMoving[i] = new ImageIcon(getClass().getResource(animationOfMovingNames[i])).getImage();
}
}

View File

@ -22,13 +22,14 @@ public class Person extends Cell {
this.directionMove = directionMove;
}
public void setImagePerson(String name, Rectangle[] rectangles) {
this.imagePerson = new ImagePerson(name, rectangles);
public void setDirectionSight(int directionSight) {
if ((directionSight >= 0) && (directionSight <= 3))
this.directionSight = directionSight;
}
public void setAnimation(String[] names){
this.imagePerson.setAnimationOfMoving(names);
}
public void setImagePerson(String name, Rectangle[] rectangles) { this.imagePerson = new ImagePerson(name, rectangles); }
public void setAnimation(String[] names) { this.imagePerson.setAnimationOfMoving(names); }
public void move() {
int x = this.getX();
@ -79,21 +80,22 @@ public class Person extends Cell {
public void paint(Graphics2D g) {
super.paint(g);
if (directionMove == 0)
g.drawImage(imagePerson.getImagesOfDirection()[directionSight], getX()*WindowOfFreeMove.CELL_SIZE,
getY()*WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
else{
switch (directionMove){
g.drawImage(imagePerson.getImagesOfDirection()[directionSight], getX() * WindowOfFreeMove.CELL_SIZE,
getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
else {
switch (directionMove) {
case WindowOfFreeMove.KEY_LEFT:
g.drawImage(imagePerson.getAnimationOfMoving()[3], getX()*WindowOfFreeMove.CELL_SIZE, getY()*WindowOfFreeMove.CELL_SIZE, null);
g.drawImage(imagePerson.getAnimationOfMoving()[3], getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE,
WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
break;
case WindowOfFreeMove.KEY_RIGHT:
g.drawImage(imagePerson.getAnimationOfMoving()[1], getX()*WindowOfFreeMove.CELL_SIZE, getY()*WindowOfFreeMove.CELL_SIZE, null);
g.drawImage(imagePerson.getAnimationOfMoving()[1], getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, null);
break;
case WindowOfFreeMove.KEY_UP:
g.drawImage(imagePerson.getAnimationOfMoving()[0], getX()*WindowOfFreeMove.CELL_SIZE, getY()*WindowOfFreeMove.CELL_SIZE, null);
g.drawImage(imagePerson.getAnimationOfMoving()[0], getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, null);
break;
case WindowOfFreeMove.KEY_DOWN:
g.drawImage(imagePerson.getAnimationOfMoving()[2], getX()*WindowOfFreeMove.CELL_SIZE, getY()*WindowOfFreeMove.CELL_SIZE, null);
g.drawImage(imagePerson.getAnimationOfMoving()[2], getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, null);
break;
}
}

View File

@ -122,30 +122,34 @@ public class WindowOfFreeMove extends JFrame {
setMap(m1);
map.createMap();
// String s1 = "> Test";
// for (int i = 0; i < s1.length() + 1; i++) {
// lp.remove(dialogBar);
// final String text = s1.substring(0, i);
// JPanel jf = new JPanel() {
// Font f = new Font("Times New Roman", Font.ITALIC, 50);
//
// lp.remove(dialogBar);
// @Override
// public void paint(Graphics g) {
// super.paint(g);
// g.setColor(Color.green);
// g.setFont(f);
// g.drawString(text, 10, 50);
// }
// };
//
// jf.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT / 4);
// jf.setBackground(Color.BLACK);
// jf.setVisible(false);
//
// JPanel jf = new JPanel() {
// Font f = new Font("Times New Roman", Font.ITALIC, 50);
// setDialogBar(jf);
// dialogBar.setVisible(true);
//setCanPersonMove(false);
// lp.add(jf, JLayeredPane.POPUP_LAYER);
//
// @Override
// public void paint(Graphics g) {
// super.paint(g);
// g.setColor(Color.green);
// g.setFont(f);
// g.drawString("> Test", 10, 50);
// }
// };
//
// jf.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT / 4);
// jf.setBackground(Color.BLACK);
// jf.setVisible(false);
//
// setDialogBar(jf);
// dialogBar.setVisible(true);
//setCanPersonMove(false);
// lp.add(jf, JLayeredPane.POPUP_LAYER);
// sleep(300);
// }
while (true) {
map.getPerson().move();
@ -170,9 +174,9 @@ public class WindowOfFreeMove extends JFrame {
}
}
protected static void sleep() {
protected static void sleep(int i) {
try {
Thread.sleep(1000);
Thread.sleep(i);
} catch (InterruptedException e) {
e.printStackTrace();
}