-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuy.java
More file actions
58 lines (50 loc) · 1.34 KB
/
Copy pathGuy.java
File metadata and controls
58 lines (50 loc) · 1.34 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
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
public class Guy {
private int x;
private int y;
private int dx;
private boolean good;
private BufferedImage img;
private int img_width, img_height;
public Guy( int x, int y, boolean good ){
this.x = x;
this.y = y;
this.good = good;
dx = -1*((int)(3*Math.random()+1));
if ( good ) {
try {
img = ImageIO.read(new File("/Users/mattc/IdeaProjects/Game/src/good.png"));
img_width = 18;
img_height = 18;
} catch (IOException e) {
System.out.println ( e );
}
} else {
try {
img = ImageIO.read(new File("/Users/mattc/IdeaProjects/Game/src/bad.png"));
img_width = 30;
img_height = 30;
} catch (IOException e) {
System.out.println ( e );
}
}
}
public void move(){
x += dx;
}
public int getX(){
return x;
}
public boolean isGood(){
return good;
}
public void draw( Graphics g ){
g.drawImage( img, x, y, null );
}
public Rectangle getShape(){
return new Rectangle( x, y, img_width, img_height );
}
}