Add Paddle Components, refactor codebase and ci#10
Conversation
…Protected, Explode)
…, Bullet) with factory integration
a5a9815 to
a54ee1a
Compare
thnhmai06
left a comment
There was a problem hiding this comment.
need to update to new Component system
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 56 out of 69 changed files in this pull request and generated 8 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| public static void main(String[] args) { | ||
| launchOption = new LaunchOption(args); | ||
| static void main(String[] args) { |
There was a problem hiding this comment.
The main method must be public to be recognized by the JVM as the application entry point. Change to public static void main(String[] args).
| static void main(String[] args) { | |
| public static void main(String[] args) { |
| protected void onActionBegin() { | ||
| FXGL.getGameWorld() | ||
| .getEntitiesByType(EntityType.PADDLE) | ||
| .forEach(e -> e.getComponent(Velocity.class).left()); |
There was a problem hiding this comment.
Velocity has no left() method; this will not compile. Replace with setting the vector explicitly, e.g. e.getComponent(Velocity.class).setVector(new com.almasb.fxgl.core.math.Vec2(-400, 0)).
| protected void onActionBegin() { | ||
| FXGL.getGameWorld() | ||
| .getEntitiesByType(EntityType.PADDLE) | ||
| .forEach(e -> e.getComponent(Velocity.class).right()); |
There was a problem hiding this comment.
Velocity has no right() method; this will not compile. Replace with e.getComponent(Velocity.class).setVector(new com.almasb.fxgl.core.math.Vec2(400, 0)).
| .type(EntityType.BULLET) | ||
| .viewWithBBox(new Circle(4, Color.YELLOW)) | ||
| .with(new CollidableComponent(true)) | ||
| .with(new BulletVelocity(data.get("speed"), data.get("direction"))) |
There was a problem hiding this comment.
Constructor arguments do not match any BulletVelocity overload (expects Vec2, Point2D, or two doubles). Build a velocity vector from speed and direction, e.g. new BulletVelocity(((javafx.geometry.Point2D) data.get("direction")).multiply((Double) data.get("speed"))).
| protected void onCollision(Entity paddle, Entity wall) { | ||
| if (wall.hasComponent(Border.class)) { | ||
| var wallProp = wall.getComponent(Wall.class); | ||
| var move = paddle.getComponentOptional(Velocity.class); | ||
|
|
||
| move.ifPresent(m -> m.setVector(0)); | ||
|
|
||
| switch (wallProp.getSide()) { | ||
| case LEFT -> paddle.setX(wall.getRightX()); | ||
| case RIGHT -> paddle.setX(wall.getX() - paddle.getWidth()); | ||
| default -> | ||
| throw new IllegalArgumentException( | ||
| "Unexpected value: " + wallProp.getSide()); | ||
| } |
There was a problem hiding this comment.
Inconsistent component types and an invalid setter: checking Border.class then retrieving Wall.class is inconsistent, and setVector(0) is invalid (expects a Vec2). Use a single wall component type consistently (e.g., Wall.class) and stop the paddle with move.ifPresent(Velocity::stop) or setVector(new Vec2(0, 0)). Also ensure the correct Wall/Border class is imported.
| public static UserSetting getSetting() { | ||
| final var filepath = getFilepath(); | ||
| try { | ||
| final var file = new Toml().read(filepath.toString()); |
There was a problem hiding this comment.
Toml.read(String) reads TOML content, not a file path. Use a File when reading from disk: new Toml().read(new java.io.File(filepath.toUri())) to correctly load the user's settings file.
| final var file = new Toml().read(filepath.toString()); | |
| final var file = new Toml().read(new File(filepath.toUri())); |
src/main/java/com/github/codestorm/bounceverse/components/properties/brick/BrickShield.java
Outdated
Show resolved
Hide resolved
| double px = FXGL.getAppWidth() / 2.0 - 60; | ||
| double py = FXGL.getAppHeight() - 40; | ||
| FXGL.spawn("paddle", px, py); |
There was a problem hiding this comment.
[nitpick] Avoid magic numbers for centering the paddle; compute based on the spawned entity’s width, e.g., spawn the paddle first then setX(appWidth / 2.0 - paddle.getWidth() / 2.0).
| double px = FXGL.getAppWidth() / 2.0 - 60; | |
| double py = FXGL.getAppHeight() - 40; | |
| FXGL.spawn("paddle", px, py); | |
| double py = FXGL.getAppHeight() - 40; | |
| var paddle = FXGL.spawn("paddle", 0, py); | |
| paddle.setX(FXGL.getAppWidth() / 2.0 - paddle.getWidth() / 2.0); |
* [skip ci] refactor: replace `For*` interface with `Suitable*` annotation (remove `Tag` system) * [skip ci] chore: reformat code and optimize import * [skip ci] chore: update JAVA_LANGUAGE to 24_PREVIEW * [skip ci] refactor: Assign new `For*` annotation for components * [skip ci] fix: fix null ref on `Utils.Time.Cooldown#current`
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 68 out of 76 changed files in this pull request and generated 6 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| .type(EntityType.WALL) | ||
| .at(0, 0) | ||
| .viewWithBBox(new Rectangle(WALL_THICKNESS, FXGL.getAppHeight())) | ||
| .with(new Wall(Side.LEFT)) |
There was a problem hiding this comment.
The Wall class is referenced but the import statement and class definition are missing from this PR. This will cause a compilation error.
| @Override | ||
| protected void onCollision(Entity paddle, Entity wall) { | ||
| if (wall.hasComponent(Border.class)) { | ||
| var wallProp = wall.getComponent(Wall.class); |
There was a problem hiding this comment.
The Wall class is referenced but not imported. The import at line 8 references Wall from components.properties.wall.Border but here it's used as Wall.class without proper import.
| private final Vec2 vector; | ||
|
|
||
| UnitVelocity(double vx, double vy) { | ||
| this.vector = new Vec2(vx, vy).normalize(); |
There was a problem hiding this comment.
Normalizing a zero vector (0, 0) for STAND will produce NaN values. The STAND case should not call normalize() or should handle the zero vector specially.
| this.vector = new Vec2(vx, vy).normalize(); | |
| Vec2 v = new Vec2(vx, vy); | |
| this.vector = (vx == 0 && vy == 0) ? v : v.normalize(); |
| * | ||
| * @see Vec2 | ||
| */ | ||
| public class Velocity extends Component implements Property { |
There was a problem hiding this comment.
Missing convenience methods for common movement directions. Consider adding left(), right(), up(), down() methods to work with UnitVelocity enum, as these are referenced in InputSystem but not defined here.
| double leftX = entity.getCenter().getX() - halfWidth + 4; | ||
| double rightX = entity.getCenter().getX() + halfWidth - 8; |
There was a problem hiding this comment.
Magic numbers 4 and 8 are used for bullet spawn positions without explanation. These should be extracted as named constants (e.g., BULLET_OFFSET_LEFT, BULLET_OFFSET_RIGHT) or calculated based on bullet radius.
| * nên, một thuộc tính kiểu trong Entity như này là cần thiết. | ||
| * | ||
| * @see OptionalTag | ||
| * @see Optional |
Introduce Attack and Attributes classes to manage damage and defense mechanics for entities. The Attack class allows entities to inflict damage based on their attributes, while the Attributes class holds general property values like defense. This enhances gameplay dynamics by enabling combat interactions.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 72 out of 80 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| final var theirAttributes = obj.getComponentOptional(Attributes.class); | ||
| final var theirDefense = theirAttributes.map(Attributes::getDefense).orElse(0); | ||
|
|
||
| final var actualDamage = damage >= 0 ? Math.min(0, damage - theirDefense) : damage; |
There was a problem hiding this comment.
The damage calculation logic is incorrect. For positive damage, Math.min(0, damage - theirDefense) will always return a non-positive value (0 or negative), which means no damage will be dealt. This should be Math.max(0, damage - theirDefense) to ensure damage is reduced by defense but never goes below 0.
| final var actualDamage = damage >= 0 ? Math.min(0, damage - theirDefense) : damage; | |
| final var actualDamage = damage >= 0 ? Math.max(0, damage - theirDefense) : damage; |
| * @return {@code true} nếu đã thực thi, {@code false} nếu chưa | ||
| */ | ||
| public final boolean isActive() { | ||
| return current != null && current.isExpired() && modified != null; |
There was a problem hiding this comment.
The condition checks if current.isExpired() is true to determine if active, but this is inverted logic. An expired timer action means the behavior has completed, not that it's currently active. This should be !current.isExpired() to check if the timer is still running.
| return current != null && current.isExpired() && modified != null; | |
| return current != null && !current.isExpired() && modified != null; |
| * | ||
| * <h1>{@link CanExecute}</h1> | ||
| * | ||
| * Có thể thưc thi hành động nào đó. |
There was a problem hiding this comment.
Misspelled 'thực' as 'thưc' in Vietnamese comment.
| * Có thể thưc thi hành động nào đó. | |
| * Có thể thực thi hành động nào đó. |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 72 out of 80 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| * | ||
| * <h1>{@link CanExecute}</h1> | ||
| * | ||
| * Có thể thưc thi hành động nào đó. |
There was a problem hiding this comment.
Corrected spelling of 'thưc' to 'thực'.
| * Có thể thưc thi hành động nào đó. | |
| * Có thể thực thi hành động nào đó. |
| * <h1>{@link HeathDeath}</h1> | ||
| * | ||
| * Hành động chết <s>vì yêu :<</s> vì hết máu. <br> | ||
| * <b>Yêu cầu entity có {@link HealthIntComponent} trước.</b> | ||
| */ | ||
| @Required(HealthIntComponent.class) | ||
| @ForEntity({}) | ||
| public class HeathDeath extends Behavior { |
There was a problem hiding this comment.
The class name 'HeathDeath' is misspelled. It should be 'HealthDeath' (referring to death from health loss).
| * <h1>{@link HeathDeath}</h1> | |
| * | |
| * Hành động chết <s>vì yêu :<</s> vì hết máu. <br> | |
| * <b>Yêu cầu entity có {@link HealthIntComponent} trước.</b> | |
| */ | |
| @Required(HealthIntComponent.class) | |
| @ForEntity({}) | |
| public class HeathDeath extends Behavior { | |
| * <h1>{@link HealthDeath}</h1> | |
| * | |
| * Hành động chết <s>vì yêu :<</s> vì hết máu. <br> | |
| * <b>Yêu cầu entity có {@link HealthIntComponent} trước.</b> | |
| */ | |
| @Required(HealthIntComponent.class) | |
| @ForEntity({}) | |
| public class HealthDeath extends Behavior { |
Modified CI configuration to use startsWith instead of contains for detecting '[skip ci]' in commit messages, improving clarity and functionality.
Renamed `HeathDeath` to `HealthDeath` and fixed spelling in `CanExecute` documentation. These changes improve code readability and maintainability.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 72 out of 80 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/main/java/com/github/codestorm/bounceverse/components/properties/Shield.java
Show resolved
Hide resolved
* feat: Brick * feat(brick): add PowerBrick and update Brick, ExoplodeBrick, ProtectedBrick * docs(brick): add Javadoc for Brick, ExoplodeBrick, PowerBrick, ProtectedBrick * refactor(brick): remove NormalBrick and StrongBrick * feat(paddle): add ExpendPaddle, LaserPaddle, ShrinkPaddle and update Paddle * feat(paddle): add ExpendPaddle, LaserPaddle, ShrinkPaddle and update Paddle * refactor: remove brick and gameManager packages * feat(brick): refactor and document brick module (Factory, Component, Protected, Explode) * feat(game): add GameManager and BounceVerseApp for game initialization * feat(paddle): add PaddleComponent and variants (Expand, Shrink, Laser, Bullet) with factory integration * feat(brick): implement explosion logic and health management refactor * feat(components): add new paddle behaviors and properties (Bullet, Width); refactor brick to components structure * refactor: migrate paddle and bullet systems to new structure * refactor(paddle): adjust PaddleFactory, Shoot and Width property for move and scaling * feat(wall): add WallFactory and Wall components with Move property for paddle collision * feat(physics): handle paddle-wall collision in CollisionSystem * feat(data): add WALL entity type for collision system * feat(behavior): update BrickExplode logic for new collision handling * feat(paddle-wall): add Move component update and WallFactory with correct sides and spawn registration * (skip ci) refactor: rename components and update imports for consistency Refactored various components by renaming `BehaviorComponent` to `Behavior`, `OptionalTag` to `Optional`, and `PropertyComponent` to `Property`. Updated imports accordingly to maintain consistency across the codebase. * [skip ci] Add and refactor Systems, Core (#15) * [skip ci] feat(core): implement game systems and refactor initialization - Introduced GameSystem, InputSystem, PhysicSystem, and UISystem for better organization and modularity (applies game logic, input handling, physics, and UI settings). - Refactored Bounceverse to utilize new systems for initialization and configuration management. - Updated credits and settings files for improved user experience. * [skip ci] ci: update CI configuration for Spotless checks and builds - Rename linting.yml to spotlessCheck.yml for clarity - Add concurrency settings to optimize CI runs - Modify job conditions to skip CI based on commit messages - Implement automatic code formatting application on failure * [skip ci] feat(core): initialize Video instance in UserSetting Add a new Video instance to the UserSetting class to ensure proper initialization and avoid null references. This change enhances the reliability of video settings management. * [skip ci] refactor: rename spotlessCheck.yml to spotless.yml for consistency * [skip ci] chore: Remove log files * Replace `For*` interface tag by annotation (#16) * [skip ci] refactor: replace `For*` interface with `Suitable*` annotation (remove `Tag` system) * [skip ci] chore: reformat code and optimize import * [skip ci] chore: update JAVA_LANGUAGE to 24_PREVIEW * [skip ci] refactor: Assign new `For*` annotation for components * [skip ci] fix: fix null ref on `Utils.Time.Cooldown#current` * feat: add Attack and Attributes components for entity interactions Introduce Attack and Attributes classes to manage damage and defense mechanics for entities. The Attack class allows entities to inflict damage based on their attributes, while the Attributes class holds general property values like defense. This enhances gameplay dynamics by enabling combat interactions. * fix(paddle): fix freeze paddle * ci: update CI conditions to use startsWith for skip ci Modified CI configuration to use startsWith instead of contains for detecting '[skip ci]' in commit messages, improving clarity and functionality. * chore: correct spelling and rename classes for consistency Renamed `HeathDeath` to `HealthDeath` and fixed spelling in `CanExecute` documentation. These changes improve code readability and maintainability. --------- Co-authored-by: Mai Thành <62001770+thnhmai06@users.noreply.github.com>
* feat: Brick * feat(brick): add PowerBrick and update Brick, ExoplodeBrick, ProtectedBrick * docs(brick): add Javadoc for Brick, ExoplodeBrick, PowerBrick, ProtectedBrick * refactor(brick): remove NormalBrick and StrongBrick * feat(paddle): add ExpendPaddle, LaserPaddle, ShrinkPaddle and update Paddle * feat(paddle): add ExpendPaddle, LaserPaddle, ShrinkPaddle and update Paddle * refactor: remove brick and gameManager packages * feat(brick): refactor and document brick module (Factory, Component, Protected, Explode) * feat(game): add GameManager and BounceVerseApp for game initialization * feat(paddle): add PaddleComponent and variants (Expand, Shrink, Laser, Bullet) with factory integration * feat(brick): implement explosion logic and health management refactor * feat(components): add new paddle behaviors and properties (Bullet, Width); refactor brick to components structure * refactor: migrate paddle and bullet systems to new structure * refactor(paddle): adjust PaddleFactory, Shoot and Width property for move and scaling * feat(wall): add WallFactory and Wall components with Move property for paddle collision * feat(physics): handle paddle-wall collision in CollisionSystem * feat(data): add WALL entity type for collision system * feat(behavior): update BrickExplode logic for new collision handling * feat(paddle-wall): add Move component update and WallFactory with correct sides and spawn registration * (skip ci) refactor: rename components and update imports for consistency Refactored various components by renaming `BehaviorComponent` to `Behavior`, `OptionalTag` to `Optional`, and `PropertyComponent` to `Property`. Updated imports accordingly to maintain consistency across the codebase. * [skip ci] Add and refactor Systems, Core (#15) * [skip ci] feat(core): implement game systems and refactor initialization - Introduced GameSystem, InputSystem, PhysicSystem, and UISystem for better organization and modularity (applies game logic, input handling, physics, and UI settings). - Refactored Bounceverse to utilize new systems for initialization and configuration management. - Updated credits and settings files for improved user experience. * [skip ci] ci: update CI configuration for Spotless checks and builds - Rename linting.yml to spotlessCheck.yml for clarity - Add concurrency settings to optimize CI runs - Modify job conditions to skip CI based on commit messages - Implement automatic code formatting application on failure * [skip ci] feat(core): initialize Video instance in UserSetting Add a new Video instance to the UserSetting class to ensure proper initialization and avoid null references. This change enhances the reliability of video settings management. * [skip ci] refactor: rename spotlessCheck.yml to spotless.yml for consistency * [skip ci] chore: Remove log files * Replace `For*` interface tag by annotation (#16) * [skip ci] refactor: replace `For*` interface with `Suitable*` annotation (remove `Tag` system) * [skip ci] chore: reformat code and optimize import * [skip ci] chore: update JAVA_LANGUAGE to 24_PREVIEW * [skip ci] refactor: Assign new `For*` annotation for components * [skip ci] fix: fix null ref on `Utils.Time.Cooldown#current` * feat: add Attack and Attributes components for entity interactions Introduce Attack and Attributes classes to manage damage and defense mechanics for entities. The Attack class allows entities to inflict damage based on their attributes, while the Attributes class holds general property values like defense. This enhances gameplay dynamics by enabling combat interactions. * fix(paddle): fix freeze paddle * ci: update CI conditions to use startsWith for skip ci Modified CI configuration to use startsWith instead of contains for detecting '[skip ci]' in commit messages, improving clarity and functionality. * chore: correct spelling and rename classes for consistency Renamed `HeathDeath` to `HealthDeath` and fixed spelling in `CanExecute` documentation. These changes improve code readability and maintainability. --------- Co-authored-by: Mai Thành <62001770+thnhmai06@users.noreply.github.com>
🏓 Summary
This pull request introduces the Paddle module to the BounceVerse project, providing the core player-controlled paddle and its special variants.
🔧 Implemented Features
PaddleComponent: base paddle logic (movement, reset position)ExpandPaddle: larger paddle with increased widthShrinkPaddle: smaller paddle with reduced widthLaserPaddle: paddle that shoots bullets upwardPaddleFactory: registers all paddle entities for FXGL spawning