-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTile.java
82 lines (67 loc) · 1.91 KB
/
Tile.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
71
72
73
74
75
76
77
78
79
80
81
82
import java.awt.*;
public class Tile extends Parallelogram {
//TILE STATIC INFO
static final int WIDTH = 35;
static final int HEIGHT = 35;
class Splotch {
private int side;
private int x;
private int y;
Color color;
public Splotch(int blockX, int blockY, boolean breakable) {
this.side = (int)(Math.random() * Tile.WIDTH / 3) + 2;
this.x = blockX + (int)(Math.random() * Tile.WIDTH / 1.4);
this.y = blockY + (int)(Math.random() * Tile.HEIGHT / 1.4);
if (!breakable) {
this.color = new Color(194, 153, 93, 128);
} else {
this.color = new Color(255, 138, 115, 128);
}
}
public void render(Graphics2D ctx) {
ctx.setColor(this.color);
Rectangle body = new Rectangle(this.x, this.y, this.side, this.side);
ctx.draw(body);
ctx.fill(body);
}
}
int x;
int y;
int centerX;
int centerY;
boolean breakable;
TileInfo info;
Color color;
Splotch[] splotches = new Splotch[2];
public Tile(int x, int y, boolean breakable, TileInfo info) {
super(x, y, Tile.WIDTH, Tile.HEIGHT, 0);
this.x = x;
this.y = y;
this.centerX = this.x + Tile.WIDTH / 2;
this.centerY = this.y + Tile.HEIGHT / 2;
this.breakable = breakable;
this.info = info;
if (!this.breakable) {
this.color = Color.decode("#967748");
} else {
this.color = Color.decode("#B54B44");
}
for (int i = 0; i < this.splotches.length; i++) {
this.splotches[i] = new Splotch(this.x, this.y, this.breakable);
}
}
public void renderShadow(Graphics2D ctx) {
ctx.setColor(WanshotView.SHADOW);
Rectangle shadow = new Rectangle(this.x - 8, this.y + (Tile.HEIGHT / 5), Tile.WIDTH, Tile.HEIGHT);
ctx.fill(shadow);
}
public void render(Graphics2D ctx) {
ctx.setColor(this.color);
Rectangle body = new Rectangle(this.x, this.y, Tile.WIDTH, Tile.HEIGHT);
ctx.draw(body);
ctx.fill(body);
for (int i = 0; i < this.splotches.length; i++) {
this.splotches[i].render(ctx);
}
}
}