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() { public void moveToMap() {
WindowOfFreeMove.getMap().setIdExit(id); WindowOfFreeMove.getMap().setIdExit(id);
WindowOfFreeMove.setMap(this.map); WindowOfFreeMove.setMap(this.map);
WindowOfFreeMove.getMap().getPerson().setDirectionSight(idToDirectionSight());
WindowOfFreeMove.getMap().setIdExit(id); WindowOfFreeMove.getMap().setIdExit(id);
WindowOfFreeMove.paintMapOnWindow(); 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 @Override
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
super.paint(g); super.paint(g);

View File

@ -1,4 +1,5 @@
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.image.*; import java.awt.image.*;
import java.io.IOException; import java.io.IOException;
@ -26,7 +27,7 @@ public class ImagePerson {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
for (int i = 0; i < animationOfMoving.length; i++){ 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; this.directionMove = directionMove;
} }
public void setImagePerson(String name, Rectangle[] rectangles) { public void setDirectionSight(int directionSight) {
this.imagePerson = new ImagePerson(name, rectangles); if ((directionSight >= 0) && (directionSight <= 3))
this.directionSight = directionSight;
} }
public void setAnimation(String[] names){ public void setImagePerson(String name, Rectangle[] rectangles) { this.imagePerson = new ImagePerson(name, rectangles); }
this.imagePerson.setAnimationOfMoving(names);
} public void setAnimation(String[] names) { this.imagePerson.setAnimationOfMoving(names); }
public void move() { public void move() {
int x = this.getX(); int x = this.getX();
@ -79,21 +80,22 @@ public class Person extends Cell {
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
super.paint(g); super.paint(g);
if (directionMove == 0) if (directionMove == 0)
g.drawImage(imagePerson.getImagesOfDirection()[directionSight], getX()*WindowOfFreeMove.CELL_SIZE, g.drawImage(imagePerson.getImagesOfDirection()[directionSight], 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);
else{ else {
switch (directionMove){ switch (directionMove) {
case WindowOfFreeMove.KEY_LEFT: 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; break;
case WindowOfFreeMove.KEY_RIGHT: 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; break;
case WindowOfFreeMove.KEY_UP: 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; break;
case WindowOfFreeMove.KEY_DOWN: 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; break;
} }
} }

View File

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