-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvatar.java
More file actions
43 lines (38 loc) · 828 Bytes
/
Avatar.java
File metadata and controls
43 lines (38 loc) · 828 Bytes
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
import java.awt.*;
import java.util.ArrayList;
import java.awt.event.KeyEvent;
public class Avatar extends Sprite implements IAvatar
{
Avatar(Canvas p)
{
super(p);
}
protected void paint(Graphics2D g2d)
{
Point p = getLocation();
if (p != null) {
g2d.setColor(getColor());
g2d.draw(getBounds());
}
}
public void keyPressed(KeyEvent event)
{
int keyCode = event.getKeyCode();
if (keyCode == event.VK_LEFT)
{
m_location.x--;
}
if (keyCode == event.VK_RIGHT)
{
m_location.x++;
}
if (keyCode == event.VK_UP)
{
m_location.y--;
}
if (keyCode == event.VK_DOWN)
{
m_location.y++;
}
}
}