Small fixes
This commit is contained in:
parent
961f5a3b0e
commit
05f2ac726d
@ -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);
|
||||||
|
|||||||
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,30 +122,34 @@ 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);
|
||||||
|
// 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() {
|
// setDialogBar(jf);
|
||||||
// Font f = new Font("Times New Roman", Font.ITALIC, 50);
|
// dialogBar.setVisible(true);
|
||||||
|
//setCanPersonMove(false);
|
||||||
|
// lp.add(jf, JLayeredPane.POPUP_LAYER);
|
||||||
//
|
//
|
||||||
// @Override
|
// sleep(300);
|
||||||
// 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);
|
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user