-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuSheep.java
63 lines (45 loc) · 1.12 KB
/
MenuSheep.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
57
58
59
60
61
62
63
package SaueSpillet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.util.Random;
import javax.swing.ImageIcon;
public class MenuSheep extends GameObject {
private int width = 16;
private int height = 16;
private Image sheepPic;
Random r = new Random();
int dir = 0;
public MenuSheep(int x, int y, ID id, Handler handler) {
super(x, y, id, handler);
loadpic();
dir = r.nextInt(3);
if (dir == 0) {
velX = 2;
velY = 6;
} else if (dir==1) {
velX = 6;
velY = 2;
} else if (dir ==2) {
velX = 1 + r.nextInt(7);
velY = 1 + r.nextInt(7);
}
}
public Rectangle getBounds() {
return new Rectangle((int) x,(int) y, width, height);
}
public void tick() {
x += velX;
y += velY;
if (y <= 0 || y >= Game.HEIGHT - 110)
velY *= -1;
if (x <= 0 || x >= Game.WIDTH - 100)
velX *= -1;
}
public void loadpic() {
sheepPic = new ImageIcon("C:\\Users\\Sjur\\tdt4100-2018-master\\git\\tdt4100-2018\\minegenkode\\GamepackRes\\sheep.png").getImage();
}
public void render(Graphics g) {
g.drawImage(sheepPic, (int) x, (int) y, null);
}
}