/
Animation.java
executable file
·60 lines (45 loc) · 1.58 KB
/
Animation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Animation here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Animation extends Actor
{
private Field finalField;
private int currentWaypoint = 0;
private Field[] way;
private GameBoard gameBoard;
private GreenfootImage image;
private int flields;
public Animation(GameBoard gameBoard, Field startField, Field finalField, Field[] way){
this.gameBoard = gameBoard;
this.currentWaypoint = 0;
this.way = way;
this.finalField = finalField;
//Animation für Feld setzen:
System.out.println("4");
way[way.length-1].setAnimationInProgress(true);
gameBoard.setAnimationInProgress(true);
System.out.println("5");
image = startField.getImage();
this.setImage(image);
}
public void act()
{
// Prüfen ob aktuellen Wegpunkt erreicht:
if (this.getX() == way[currentWaypoint].getX() && this.getY() == way[currentWaypoint].getY()) {
currentWaypoint++;
}
try {
this.turnTowards(way[currentWaypoint].getX(), way[currentWaypoint].getY());
this.move(10);
} catch (ArrayIndexOutOfBoundsException ex) {
this.getWorld().removeObject(this);
System.out.println("3");
way[way.length-1].setAnimationInProgress(false);
System.out.println("2");
}
}
}