Newer
Older
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
package lab;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
public class Dragon {
private static final int SIZE_OF_DRAGON = 50;
private final World world;
private Point2D position;
private final Point2D velocity;
private final Point2D dimension;
private final Image image;
public Dragon(World world, Point2D position, Point2D velocity) {
this(world, position, velocity, new Point2D(SIZE_OF_DRAGON, SIZE_OF_DRAGON));
}
public Dragon(World world, Point2D position, Point2D velocity, Point2D dimension) {
this.world = world;
this.position = position;
this.velocity = velocity;
this.dimension = dimension;
this.image = Constants.DRAGON_IMAGE;
}
public void draw(GraphicsContext gc) {
Point2D p = world.getCanvasPoint(position);
gc.drawImage(image, p.getX(), p.getY(), dimension.getX(), dimension.getY());
}
public void simulate(double deltaT) {
position = position.add(velocity.multiply(deltaT));
}
}