-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChicken.java
56 lines (49 loc) · 1.2 KB
/
Chicken.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
import java.io.File;
import java.net.URL;
import java.awt.*;
import javax.imageio.ImageIO;
public class Chicken extends MovingThing
{
private int speed;
private Image image;
public Chicken(int x, int y, int w, int h, Color c, int s) {
super(x, y, w, h);
speed = s;
c = Color.WHITE;
try
{
URL url = getClass().getResourse("chicken.png");
image = ImageIO.read(url);
}
catch (Exception e)
{
System.out.println("Error loading chicken image");
}
}
public void setSpeed(int s) {
speed = s;
}
public int getSpeed() {
return speed;
}
public void move(String direction) {
if (direction.equals("LEFT")) {
setX(getX() - speed);
}
if (direction.equals("RIGHT")) {
setX(getX() + speed);
}
if (direction.equals("UP")) {
setY(getY() - speed);
}
if (direction.equals("DOWN")) {
setY(getY() + speed);
}
}
public void draw(Graphics window) {
window.drawImage(image, getX(), getY(), getWidth(), getHeight(), null);
}
public String toString() {
return super.toString() + getSpeed();
}
}