Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 997c3d5

Browse files
committed
refactor(assets): update paddle and brick textures; adjust related factories and enums
1 parent 066df51 commit 997c3d5

16 files changed

Lines changed: 78 additions & 82 deletions

File tree

src/main/java/com/github/codestorm/bounceverse/AssetsPath.java

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22

33
import com.github.codestorm.bounceverse.typing.enums.BrickType;
44
import com.google.common.collect.ImmutableList;
5-
65
import javafx.scene.paint.Color;
7-
86
import org.jspecify.annotations.NonNull;
9-
107
import java.util.*;
118

129
/**
13-
*
14-
*
1510
* <h1>{@link AssetsPath}</h1>
1611
*
17-
* Nơi lưu trữ các đường dẫn tới assets.
12+
* Nơi lưu trữ các đường dẫn tới assets (texture, âm thanh, video, v.v.).
1813
*/
1914
public final class AssetsPath {
2015

@@ -24,24 +19,20 @@ private AssetsPath() {
2419
private static final String ROOT = "/assets";
2520

2621
public static final class Video {
27-
2822
private Video() {
2923
}
3024

3125
private static final String ROOT = AssetsPath.ROOT + "/videos";
32-
33-
public static final String INTRO = "intro.mp4";
26+
public static final String INTRO = "/intro.mp4";
3427
}
3528

3629
public static final class Sounds {
37-
3830
private Sounds() {
3931
}
4032

4133
private static final String ROOT = AssetsPath.ROOT + "/sounds";
4234

4335
public static final class Music {
44-
4536
private Music() {
4637
}
4738

@@ -52,7 +43,6 @@ private Music() {
5243
}
5344

5445
public static final class SFX {
55-
5646
private SFX() {
5747
}
5848

@@ -82,13 +72,11 @@ private SFX() {
8272
public static final String WALL_HIT = ROOT + "/wall_hit.wav";
8373
public static final String WIN3 = ROOT + "/win3.wav";
8474

85-
public static final ImmutableList<@NonNull String> BRICK_HITS
86-
= ImmutableList.of(BRICK_HIT_1, BRICK_HIT_2);
75+
public static final ImmutableList<@NonNull String> BRICK_HITS = ImmutableList.of(BRICK_HIT_1, BRICK_HIT_2);
8776
}
8877
}
8978

9079
public static final class Textures {
91-
9280
private Textures() {
9381
}
9482

@@ -108,15 +96,15 @@ private Bricks() {
10896
"orange", new ColorAssets(Color.ORANGE),
10997
"pink", new ColorAssets(Color.PINK),
11098
"red", new ColorAssets(Color.RED),
111-
"yellow", new ColorAssets(Color.YELLOW)
112-
);
99+
"yellow", new ColorAssets(Color.YELLOW));
113100
}
114101

115102
public static final class ColorAssets {
116103

117104
private static final NavigableMap<Double, String> NORMAL = new TreeMap<>();
118105
private static final NavigableMap<Double, String> SHIELD = new TreeMap<>();
119106
private static final NavigableMap<Double, String> STRONG = new TreeMap<>();
107+
private static final NavigableMap<Double, String> KEY = new TreeMap<>();
120108

121109
private final Color color;
122110

@@ -139,27 +127,24 @@ private ColorAssets(Color color) {
139127
STRONG.put(2.0 / 3, "/strong.png");
140128
STRONG.put(1.0 / 3, "/strongFirstHit.png");
141129
STRONG.put(0.0, "/strongSecondHit.png");
130+
131+
// Key Brick
132+
KEY.put(0.0, "/keybrick.png");
142133
}
143134

144135
public String getColorName() {
145-
if (color.equals(Color.BLUE)) {
136+
if (color.equals(Color.BLUE))
146137
return "blue";
147-
}
148-
if (color.equals(Color.GREEN)) {
138+
if (color.equals(Color.GREEN))
149139
return "green";
150-
}
151-
if (color.equals(Color.ORANGE)) {
140+
if (color.equals(Color.ORANGE))
152141
return "orange";
153-
}
154-
if (color.equals(Color.PINK)) {
142+
if (color.equals(Color.PINK))
155143
return "pink";
156-
}
157-
if (color.equals(Color.RED)) {
144+
if (color.equals(Color.RED))
158145
return "red";
159-
}
160-
if (color.equals(Color.YELLOW)) {
146+
if (color.equals(Color.YELLOW))
161147
return "yellow";
162-
}
163148
throw new IllegalArgumentException("Unsupported color: " + color);
164149
}
165150

@@ -175,15 +160,12 @@ public String getRoot() {
175160
* @return Đường dẫn đến texture
176161
*/
177162
public String getTexture(BrickType brickType, double hpPercent) {
178-
var map = switch (brickType) {
179-
case NORMAL ->
180-
NORMAL;
181-
case SHIELD ->
182-
SHIELD;
183-
case STRONG ->
184-
STRONG;
185-
case EXPLODING, SPECIAL ->
186-
NORMAL; // dùng lại texture mặc định
163+
NavigableMap<Double, String> map = switch (brickType) {
164+
case NORMAL -> NORMAL;
165+
case SHIELD -> SHIELD;
166+
case STRONG -> STRONG;
167+
case KEY -> KEY;
168+
case EXPLODING -> NORMAL; // fallback dùng texture thường
187169
};
188170
return getRoot() + map.floorEntry(hpPercent).getValue();
189171
}
@@ -194,12 +176,10 @@ public Color color() {
194176

195177
@Override
196178
public boolean equals(Object obj) {
197-
if (obj == this) {
179+
if (obj == this)
198180
return true;
199-
}
200-
if (obj == null || obj.getClass() != this.getClass()) {
181+
if (obj == null || obj.getClass() != this.getClass())
201182
return false;
202-
}
203183
var that = (ColorAssets) obj;
204184
return Objects.equals(this.color, that.color);
205185
}
@@ -211,29 +191,27 @@ public int hashCode() {
211191

212192
@Override
213193
public String toString() {
214-
return "ColorAssets[" + "color=" + color + ']';
194+
return "ColorAssets[color=" + color + ']';
215195
}
216196
}
217197
}
218198

219-
public static final Map<Integer, String> NUMBERS =
220-
Map.of(
221-
0, "numbers/0.png",
222-
1, "numbers/1.png",
223-
2, "numbers/2.png",
224-
3, "numbers/3.png",
225-
4, "numbers/4.png",
226-
5, "numbers/5.png",
227-
6, "numbers/6.png",
228-
7, "numbers/7.png",
229-
8, "numbers/8.png",
230-
9, "numbers/9.png");
199+
public static final Map<Integer, String> NUMBERS = Map.of(
200+
0, "numbers/0.png",
201+
1, "numbers/1.png",
202+
2, "numbers/2.png",
203+
3, "numbers/3.png",
204+
4, "numbers/4.png",
205+
5, "numbers/5.png",
206+
6, "numbers/6.png",
207+
7, "numbers/7.png",
208+
8, "numbers/8.png",
209+
9, "numbers/9.png");
231210

232211
public static final String HEART = "/heart.png";
233212
}
234213

235214
public static final class Other {
236-
237215
private Other() {
238216
}
239217

src/main/java/com/github/codestorm/bounceverse/factory/entities/BrickFactory.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import javafx.geometry.Point2D;
2323
import javafx.geometry.Side;
2424

25+
import java.util.List;
26+
import java.util.Random;
27+
2528
/**
2629
* Factory sinh ra các loại gạch (Brick) trong trò chơi.
2730
*/
@@ -31,18 +34,23 @@ public final class BrickFactory extends EntityFactory {
3134
private static final int DEFAULT_HEIGHT = 30;
3235
private static final int DEFAULT_HP = 1;
3336

37+
private static final Random RANDOM = new Random();
38+
private static final List<String> COLORS = List.of("blue", "green", "orange", "pink", "red", "yellow");
39+
3440
@Override
3541
protected EntityBuilder getBuilder(SpawnData data) {
3642
int hp = ((Number) Utilities.Typing.getOr(data, "hp", DEFAULT_HP)).intValue();
3743
int width = ((Number) Utilities.Typing.getOr(data, "width", DEFAULT_WIDTH)).intValue();
3844
int height = ((Number) Utilities.Typing.getOr(data, "height", DEFAULT_HEIGHT)).intValue();
3945

40-
// 🔹 Không dùng "pos" nữa — tự tạo từ x, y
4146
Point2D pos = new Point2D(data.getX(), data.getY());
4247

43-
String colorKey = Utilities.Typing.getOr(data, "color", "blue");
48+
// 🔹 Nếu không truyền color, chọn random từ 6 màu
49+
String colorKey = Utilities.Typing.getOr(data, "color", COLORS.get(RANDOM.nextInt(COLORS.size())));
50+
4451
var colorAsset = AssetsPath.Textures.Bricks.COLORS.get(colorKey);
4552
if (colorAsset == null) {
53+
// fallback an toàn nếu không tồn tại
4654
colorAsset = AssetsPath.Textures.Bricks.COLORS.values().stream()
4755
.findFirst()
4856
.orElseThrow(() -> new IllegalStateException("No ColorAssets available for bricks"));
@@ -73,29 +81,23 @@ protected EntityBuilder getBuilder(SpawnData data) {
7381
.with(physics, new Attributes(), new HealthIntComponent(hp), new HealthDeath());
7482
}
7583

76-
/**
77-
* Gạch thường
78-
*/
84+
/** Gạch thường */
7985
@Spawns("normalBrick")
8086
public Entity newNormalBrick(SpawnData data) {
8187
data.put("type", BrickType.NORMAL);
8288
data.put("hp", (double) DEFAULT_HP);
8389
return getBuilder(data).buildAndAttach();
8490
}
8591

86-
/**
87-
* Gạch trâu (HP cao hơn)
88-
*/
92+
/** Gạch trâu (HP cao hơn) */
8993
@Spawns("strongBrick")
9094
public Entity newStrongBrick(SpawnData data) {
9195
data.put("type", BrickType.STRONG);
9296
data.put("hp", (double) (DEFAULT_HP + 2));
9397
return getBuilder(data).buildAndAttach();
9498
}
9599

96-
/**
97-
* Gạch có khiên bảo vệ 3 phía (chỉ phá từ trên xuống)
98-
*/
100+
/** Gạch có khiên bảo vệ 3 phía (chỉ phá từ trên xuống) */
99101
@Spawns("shieldBrick")
100102
public Entity newShieldBrick(SpawnData data) {
101103
data.put("type", BrickType.SHIELD);
@@ -104,25 +106,29 @@ public Entity newShieldBrick(SpawnData data) {
104106
return getBuilder(data).with(shield).buildAndAttach();
105107
}
106108

107-
/**
108-
* Gạch nổ — khi bị phá sẽ kích hoạt Explosion gây sát thương lan
109-
*/
109+
/** Gạch nổ — khi bị phá sẽ kích hoạt Explosion gây sát thương lan */
110110
@Spawns("explodingBrick")
111111
public Entity newExplodingBrick(SpawnData data) {
112112
data.put("type", BrickType.EXPLODING);
113113
data.put("hp", (double) DEFAULT_HP);
114-
var explosion = new Explosion(120); // bán kính 120 px
114+
var explosion = new Explosion(120);
115115
return getBuilder(data).with(explosion).buildAndAttach();
116116
}
117117

118118
/**
119-
* Gạch đặc biệt — rơi PowerUp khi bị phá
119+
* Gạch khóa (Key Brick) — loại đặc biệt rơi PowerUp khi bị phá
120120
*/
121-
@Spawns("specialBrick")
122-
public Entity newSpecialBrick(SpawnData data) {
123-
data.put("type", BrickType.SPECIAL);
121+
@Spawns("keyBrick")
122+
public Entity newKeyBrick(SpawnData data) {
123+
data.put("type", BrickType.KEY);
124124
data.put("hp", (double) DEFAULT_HP);
125+
126+
// 🔹 Gắn component Special để rơi power-up khi bị phá
125127
var special = new Special();
126-
return getBuilder(data).with(special).buildAndAttach();
128+
129+
return getBuilder(data)
130+
.with(special)
131+
.buildAndAttach();
127132
}
133+
128134
}

src/main/java/com/github/codestorm/bounceverse/systems/init/GameSystem.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,29 @@ public static void bricks() {
113113
var posY = startY + y * (brickHeight + spacingY);
114114

115115
String type;
116-
switch (y) {
117-
case 0 -> type = "shieldBrick"; // hàng đầu có khiên
118-
case 3 -> type = "strongBrick"; // hàng thứ 4 mạnh
119-
default -> type = "normalBrick";
116+
117+
// 🛡️ Hàng đầu tiên là shieldBrick
118+
if (y == 0) {
119+
type = "shieldBrick";
120+
}
121+
// 🔑 Hàng thứ 4 (index = 3) là keyBrick để test PowerUp
122+
else if (y == 3) {
123+
type = "keyBrick";
124+
}
125+
// 💣 Hàng cuối (index = 5) là explodingBrick để test nổ lan
126+
else if (y == 5) {
127+
type = "explodingBrick";
128+
}
129+
// 💎 Các hàng còn lại là gạch thường
130+
else {
131+
type = "normalBrick";
120132
}
121133

122134
FXGL.spawn(type, new SpawnData(posX, posY));
123135
}
124136
}
125137

126-
// Giữ lại màu nền động từ HEAD
138+
// Giữ lại logic nền động
127139
BackgroundColorManager.init(FXGL.getGameWorld().getEntitiesByType(EntityType.BRICK).size());
128140
}
129141

src/main/java/com/github/codestorm/bounceverse/typing/enums/BrickType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ public enum BrickType {
1212
STRONG,
1313
SHIELD,
1414
EXPLODING,
15-
SPECIAL
15+
KEY
1616
}

src/main/resources/assets/textures/bricks/orange/keybrick_02.png renamed to src/main/resources/assets/textures/bricks/orange/keybrick.png

File renamed without changes.

src/main/resources/assets/textures/paddle/expand/green/green04.png renamed to src/main/resources/assets/textures/paddle/expand/green/Green Expand Paddle.png

File renamed without changes.

src/main/resources/assets/textures/paddle/expand/pink/pink04.png renamed to src/main/resources/assets/textures/paddle/expand/pink/Pink Expand Paddle.png

File renamed without changes.

src/main/resources/assets/textures/paddle/expand/red/red04.png renamed to src/main/resources/assets/textures/paddle/expand/red/Red Expand Paddle.png

File renamed without changes.

src/main/resources/assets/textures/paddle/normal/blue/blue03.png renamed to src/main/resources/assets/textures/paddle/normal/blue/Blue Normal Paddle.png

File renamed without changes.

src/main/resources/assets/textures/paddle/normal/green/green03.png renamed to src/main/resources/assets/textures/paddle/normal/green/Green Normal Paddle.png

File renamed without changes.

0 commit comments

Comments
 (0)