Small fixes
This commit is contained in:
parent
92d11b869f
commit
5269320951
@ -1,5 +1,5 @@
|
||||
public class Game {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
public static void main(String[] args) {
|
||||
new WindowOfFreeMove().start(); }
|
||||
}
|
||||
|
||||
|
||||
@ -121,23 +121,23 @@ public class Map {
|
||||
switch (cell.getDirectionOut()) {
|
||||
case 1:
|
||||
person.set(cell.getX(), cell.getY() - 1);
|
||||
person.directionMoveLast = 0;
|
||||
person.directionSight = 2;
|
||||
person.setDirectionMoveLast(0);
|
||||
person.setDirectionSight(2);
|
||||
break;
|
||||
case 2:
|
||||
person.set(cell.getX() + 1, cell.getY());
|
||||
person.directionMoveLast = 0;
|
||||
person.directionSight = 3;
|
||||
person.setDirectionMoveLast(0);
|
||||
person.setDirectionSight(3);
|
||||
break;
|
||||
case 3:
|
||||
person.set(cell.getX(), cell.getY() + 1);
|
||||
person.directionMoveLast = 0;
|
||||
person.directionSight = 0;
|
||||
person.setDirectionMoveLast(0);
|
||||
person.setDirectionSight(0);
|
||||
break;
|
||||
case 4:
|
||||
person.set(cell.getX() - 1, cell.getY());
|
||||
person.directionMoveLast = 0;
|
||||
person.directionSight = 1;
|
||||
person.setDirectionMoveLast(0);
|
||||
person.setDirectionSight(1);
|
||||
break;
|
||||
default:
|
||||
person.set(-1, -1);
|
||||
|
||||
@ -4,20 +4,30 @@ import java.awt.*;
|
||||
public class Person extends Cell {
|
||||
private ImagePerson imagePerson;
|
||||
private int directionMove;
|
||||
public int directionSight;
|
||||
public int directionMoveLast;
|
||||
boolean ready = true;
|
||||
private int directionSight;
|
||||
private int directionMoveLast;
|
||||
private boolean ready;
|
||||
|
||||
public void setDirectionMoveLast(int directionMoveLast) {
|
||||
this.directionMoveLast = directionMoveLast;
|
||||
}
|
||||
|
||||
public void setDirectionSight(int directionSight) {
|
||||
this.directionSight = directionSight;
|
||||
}
|
||||
|
||||
public Person() {
|
||||
super(-1, -1, WindowOfFreeMove.CELL_SIZE, Color.RED);
|
||||
this.directionMove = 0;
|
||||
this.directionSight = 3;
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
public Person(int x, int y) {
|
||||
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.RED);
|
||||
this.directionMove = 0;
|
||||
this.directionSight = 3;
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
public void setDirectionMove(int directionMove) {
|
||||
@ -29,7 +39,7 @@ public class Person extends Cell {
|
||||
this.imagePerson = new ImagePerson(name, rectangles);
|
||||
}
|
||||
|
||||
public void setAnimation(String[] names){
|
||||
public void setAnimation(String[] names) {
|
||||
this.imagePerson.setAnimationOfMoving(names);
|
||||
}
|
||||
|
||||
@ -71,8 +81,7 @@ public class Person extends Cell {
|
||||
imagePerson.getAnimationOfMoving()[2].flush();
|
||||
imagePerson.getAnimationOfMoving()[3].flush();
|
||||
ready = true;
|
||||
}
|
||||
else if (directionMove != 0 && WindowOfFreeMove.getMap().isBusyCell(x, y)) {
|
||||
} else if (directionMove != 0 && WindowOfFreeMove.getMap().isBusyCell(x, y)) {
|
||||
directionMoveLast = 0;
|
||||
}
|
||||
directionMove = 0;
|
||||
@ -94,22 +103,22 @@ public class Person extends Cell {
|
||||
@Override
|
||||
public void paint(Graphics2D g) {
|
||||
super.paint(g);
|
||||
switch (directionMoveLast){
|
||||
switch (directionMoveLast) {
|
||||
case 0:
|
||||
g.drawImage(imagePerson.getImagesOfDirection()[directionSight], getX() * WindowOfFreeMove.CELL_SIZE,
|
||||
getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
|
||||
break;
|
||||
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, null);
|
||||
break;
|
||||
case WindowOfFreeMove.KEY_RIGHT:
|
||||
g.drawImage(imagePerson.getAnimationOfMoving()[1], (getX()-1)*WindowOfFreeMove.CELL_SIZE, getY()*WindowOfFreeMove.CELL_SIZE, null);
|
||||
g.drawImage(imagePerson.getAnimationOfMoving()[1], (getX() - 1) * 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()-1)*WindowOfFreeMove.CELL_SIZE, null);
|
||||
g.drawImage(imagePerson.getAnimationOfMoving()[2], getX() * WindowOfFreeMove.CELL_SIZE, (getY() - 1) * WindowOfFreeMove.CELL_SIZE, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ public class WindowOfFreeMove extends JFrame {
|
||||
}
|
||||
|
||||
|
||||
public void start() throws InterruptedException {
|
||||
public void start() {
|
||||
String[] strings = {"main-walk-up-long.gif", "main-walk-right-long.gif", "main-walk-down-long.gif", "main-walk-left-long.gif"};
|
||||
Rectangle[] rec = new Rectangle[4];
|
||||
for (int i = 0; i < rec.length; i++){
|
||||
@ -151,7 +151,7 @@ public class WindowOfFreeMove extends JFrame {
|
||||
// lp.add(jf, JLayeredPane.POPUP_LAYER);
|
||||
|
||||
while (true) {
|
||||
Thread.sleep(1);
|
||||
//Thread.sleep();
|
||||
map.getPerson().move();
|
||||
canvas.repaint();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user