-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectible.java
More file actions
81 lines (66 loc) · 2.04 KB
/
Copy pathCollectible.java
File metadata and controls
81 lines (66 loc) · 2.04 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
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
// Collectible game entities that can be picked up by the player.
public class Collectible {
private int x;
private int y;
private int width;
private int height;
private boolean collected;
private int screenX;
private int screenY;
// Animated sprite for coin animation
private AnimatedSprite animatedSprite;
// Constructor for collectibles
public Collectible(int xPos, int yPos, int w, int h, AnimatedSprite animSprite) {
x = xPos;
y = yPos;
width = w;
height = h;
collected = false;
animatedSprite = animSprite;
}
public void updateScreenPosition(int cameraX, int cameraY) {
screenX = x - cameraX;
screenY = y - cameraY;
// Update animated sprite position if present
if (animatedSprite != null) {
animatedSprite.updateScreenPosition(cameraX, cameraY);
}
}
// Update animation for collectibles
public void update() {
if (animatedSprite != null) {
animatedSprite.update();
}
}
public void draw(Graphics2D g2) {
if (collected) return;
// Only draw if visible on screen
if (screenX + width > 0 && screenX < 800 &&
screenY + height > 0 && screenY < 600) {
if (animatedSprite != null) {
animatedSprite.draw(g2);
} else {
// Draw placeholder
g2.setColor(java.awt.Color.YELLOW);
g2.fillOval(screenX, screenY, width, height);
}
}
}
public Rectangle2D.Double getBoundingRectangle() {
return new Rectangle2D.Double(x, y, width, height);
}
public boolean isCollected() {
return collected;
}
public void collect() {
collected = true;
}
public int getScreenX() {
return screenX;
}
public int getScreenY() {
return screenY;
}
}