-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapGenerator.java
More file actions
74 lines (61 loc) · 2.48 KB
/
Copy pathMapGenerator.java
File metadata and controls
74 lines (61 loc) · 2.48 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
package brickBreacker;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class MapGenerator {
public int map[][];
public int brickWidth;
public int brickHeight;
// Example texture for the bricks (optional)
private BufferedImage brickTexture;
public MapGenerator(int row, int col) {
map = new int[row][col];
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[0].length; j++) {
map[i][j] = 1;
}
}
brickWidth = 540 / col;
brickHeight = 150 / row;
// Load or create a brick texture if desired (optional)
// brickTexture = loadTexture("/resources/brickTexture.png");
}
public void draw(Graphics2D g) {
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[0].length; j++) {
if (map[i][j] > 0) {
// Set brick position
int brickX = j * brickWidth + 80;
int brickY = i * brickHeight + 50;
// Create a gradient effect for the brick
GradientPaint gradient = new GradientPaint(brickX, brickY, Color.BLUE, brickX + brickWidth, brickY + brickHeight, Color.CYAN);
g.setPaint(gradient);
g.fillRect(brickX, brickY, brickWidth, brickHeight);
// Optionally, draw a texture on the brick
if (brickTexture != null) {
TexturePaint texture = new TexturePaint(brickTexture, new Rectangle(brickX, brickY, brickWidth, brickHeight));
g.setPaint(texture);
g.fillRect(brickX, brickY, brickWidth, brickHeight);
}
// Draw brick border
g.setStroke(new BasicStroke(3));
g.setColor(Color.BLACK);
g.drawRect(brickX, brickY, brickWidth, brickHeight);
}
}
}
}
public void setBrickValue(int value, int row, int col) {
map[row][col] = value;
}
// Method to load a texture (optional)
private BufferedImage loadTexture(String path) {
try {
return ImageIO.read(getClass().getResource(path));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}