forked from pratyushmp/code_opensource_2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprite.java
More file actions
80 lines (66 loc) · 1.37 KB
/
Sprite.java
File metadata and controls
80 lines (66 loc) · 1.37 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.awt.*;
public class Sprite
{
private Image image;
private Rectangle rect;
private Point motion;
public Sprite()
{
this.image = null;
this.rect = new Rectangle(0, 0, 0, 0);
this.motion = new Point(0, 0);
}
public void setImage(Image image)
{
this.image = image;
this.rect.width = image.getWidth(null);
this.rect.height = image.getHeight(null);
}
public void setPosition(int x, int y)
{
this.rect.x = x;
this.rect.y = y;
}
public Rectangle getRect()
{
return this.rect;
}
public int getX()
{
return this.rect.x;
}
public int getY()
{
return this.rect.y;
}
public int getWidth()
{
return this.rect.width;
}
public int getHeight()
{
return this.rect.height;
}
public void setMotion(int dx, int dy)
{
this.motion.x = dx;
this.motion.y = dy;
}
public int getDX()
{
return this.motion.x;
}
public int getDY()
{
return this.motion.y;
}
public void drawOn(Graphics g)
{
g.drawImage(this.image, this.rect.x, this.rect.y, null);
}
public void clocktick()
{
this.rect.x += this.motion.x;
this.rect.y += this.motion.y;
}
}