-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZombieFactory.java
More file actions
41 lines (36 loc) · 1.21 KB
/
ZombieFactory.java
File metadata and controls
41 lines (36 loc) · 1.21 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
package lab13;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
public class ZombieFactory implements SpriteFactory{
private static ZombieFactory instance;
BufferedImage tape;
private ZombieFactory() {
try{
tape = ImageIO.read(getClass().getResource("\\resources\\walkingdead.png"));//new DrawPanel(Main.class.getResource("\\resources\\walkingdead.png"), );
}catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Failed to load zombie sprite sheet");
}
}
public Sprite newSprite(int x,int y){
double scale = ( Math.random() * (2. - 0.2) + 0.2 );// wylosuj liczbę z zakresu 0.2 do 2.0
try {
return new Zombie(x, y, scale, tape);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static ZombieFactory getInstance() {
if (instance == null) {
synchronized (ZombieFactory.class) {
if (instance == null) {
instance = new ZombieFactory();
}
}
}
return instance;
}
}