forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCactus.java
More file actions
37 lines (31 loc) · 1.29 KB
/
Cactus.java
File metadata and controls
37 lines (31 loc) · 1.29 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
package Dino_Game_java;
import java.awt.Rectangle;
// Represents a Cactus entity
class Cactus {
private int x, y, h, p; // x, y position, height, thickness parameter
// Assuming p relates to width calculation. Need a clear definition.
// For simplicity, let's define a width.
private int width;
public Cactus(int x, int y, int h, int p) {
this.x = x;
this.y = y; // y is typically the top-left corner for rendering
this.h = h;
this.p = p;
// Approximate width based on draw() method in original code (p*2 for central part)
// and draw2() which adds more parts. This needs refinement based on exact drawing.
this.width = p * 6; // A rough estimate for collision
}
public void move(int deltaX) {
this.x += deltaX;
}
public int getX() { return x; }
public int getY() { return y; }
public int getH() { return h; }
public int getP() { return p; }
public int getWidth() { return width; } // For collision detection
public Rectangle getBounds() {
// Bounds for collision. Assuming x,y is top-left of the main central pillar.
// The actual drawn shape is more complex. This is a simplification.
return new Rectangle(x, y, p * 2, h); // Central part of main cactus segment
}
}