-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoin.java
More file actions
115 lines (77 loc) · 2.37 KB
/
Coin.java
File metadata and controls
115 lines (77 loc) · 2.37 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.Image;
public class Coin {
private int XSIZE = 50; // width of the image
private int YSIZE = 50; // height of the image
private Animation animCoin;
private int x; // x-position of sprite
private int y; // y-position of sprite
private Player player;
int time, timeChange; // to control when the image is grayed
boolean originalImage, grayImage;
// Sprite Constructor
public Coin (Player player, int x, int y, double displayScale) {
this.x = x;
this.y = y;
this.player = player;
XSIZE = (int)(XSIZE*displayScale);
YSIZE = (int)(YSIZE*displayScale);
time = 0; // range is 0 to 10
timeChange = 1; // set to 1
originalImage = true;
grayImage = false;
Image coin1 = ImageManager.loadImage("images/object/coin/coin1.png");
Image coin2 = ImageManager.loadImage("images/object/coin/coin2.png");
Image coin3 = ImageManager.loadImage("images/object/coin/coin3.png");
animCoin = new Animation(true);
animCoin.addFrame(coin1, 100);
animCoin.addFrame(coin2, 100);
animCoin.addFrame(coin3, 100);
}
public void draw (Graphics2D g2, int offSetX) {
if (!animCoin.isStillActive()) {
return;
}
g2.drawImage(animCoin.getImage(), x + offSetX, y, XSIZE, YSIZE, null);
}
public void start() {
animCoin.start();
}
public void stop() {
animCoin.stop();
}
public boolean isActive(){
return animCoin.isStillActive();
}
public boolean collidesWithPlayer () {
Rectangle2D.Double myRect = getBoundingRectangle();
Rectangle2D.Double playerRect = player.getBoundingRectangle();
if (myRect.intersects(playerRect)) {
return true;
}
else
return false;
}
public Rectangle2D.Double getBoundingRectangle() {
return new Rectangle2D.Double (x, y, XSIZE, YSIZE);
}
public void update() {
if (!animCoin.isStillActive()) {
return;
}
animCoin.update();
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}