forked from anesmemisevic/worlds-hardest-game
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCoin.java
70 lines (51 loc) · 1.57 KB
/
Coin.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
64
65
66
67
68
69
70
package wh.game;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.imageio.stream.FileImageInputStream;
public class Coin extends Rectangle {
private final int x;
private final int y;
private final int width;
private final int height;
private boolean isCollected = false;
private BufferedImage coing;
private final SpriteSheet sheet;
private int currentSprite;
private int spriteChanger = 0;
public Coin(int x, int y, int width, int height){
setBounds(x,y,width,height);
this.x = x;
this.y = y;
this.width = width;
this.height = height;
//Getting sprite image
try {
coing = ImageIO.read(new FileImageInputStream(new File("src/wh/game/resource/images/Coin.png")));
} catch (IOException e) {
e.printStackTrace();
}
//Converting image to sprite sheet
sheet = new SpriteSheet(coing);
}
public void drawCoin(Graphics g){
//Determine the change speed of sprites
if (spriteChanger%7==0) {
currentSprite += 32;
spriteChanger = 0;
}
g.drawImage(sheet.getSprite(currentSprite, 0, 32, 32), this.x, this.y, 16, 16, null);
if (currentSprite==224) {
currentSprite = 32;
}
spriteChanger++;
}
public void setCollected(boolean collected) {
isCollected = collected;
}
public boolean isCollected() {
return isCollected;
}
}