This repository was archived by the owner on Dec 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Merged
PowerUp Base #22
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...java/com/github/codestorm/bounceverse/components/properties/powerup/PowerUpContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.github.codestorm.bounceverse.components.properties.powerup; | ||
|
|
||
| import com.almasb.fxgl.entity.Entity; | ||
| import com.almasb.fxgl.entity.component.Component; | ||
| import com.almasb.fxgl.entity.component.CoreComponent; | ||
| import com.github.codestorm.bounceverse.Utilities; | ||
| import com.github.codestorm.bounceverse.components.properties.Property; | ||
| import com.github.codestorm.bounceverse.typing.annotations.ForEntity; | ||
| import com.github.codestorm.bounceverse.typing.enums.EntityType; | ||
| import com.google.common.collect.MutableClassToInstanceMap; | ||
| import java.util.Map; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| /** | ||
| * | ||
| * | ||
| * <h1>{@link PowerUpContainer}</h1> | ||
| * | ||
| * Giống như một cái túi, nơi lưu trữ {@link Component} bên trong {@link Entity} và không kích hoạt | ||
| * logic của các component đó. | ||
| */ | ||
| @ForEntity({EntityType.POWER_UP}) | ||
| @CoreComponent | ||
| public final class PowerUpContainer extends Property { | ||
| private MutableClassToInstanceMap<Component> container = MutableClassToInstanceMap.create(); | ||
|
|
||
| /** | ||
| * Gán trực tiếp các {@link Component} lên trên {@link Entity}. | ||
| * | ||
| * @param entity Entity. | ||
| */ | ||
| public void addTo(Entity entity) { | ||
| for (var entry : container.entrySet()) { | ||
| final var component = entry.getValue(); | ||
| // TODO: Gán việc kiểm tra trên chính Entity/Component thay vì thủ tục ntn | ||
| Utilities.Compatibility.throwIfNotCompatible((EntityType) entity.getType(), component); | ||
| entity.addComponent(entry.getValue()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Thêm các {@link Component} vào {@link #container}. | ||
| * | ||
| * @param components Các component | ||
| * @see MutableClassToInstanceMap#putAll(Map) | ||
| */ | ||
| public void put(@NotNull Component... components) { | ||
| for (var component : components) { | ||
| container.put(component.getClass(), component); | ||
| } | ||
| } | ||
|
|
||
| public PowerUpContainer(Component... components) { | ||
| put(components); | ||
| } | ||
|
|
||
| public MutableClassToInstanceMap<Component> getContainer() { | ||
| return container; | ||
| } | ||
|
|
||
| public void setContainer(MutableClassToInstanceMap<Component> container) { | ||
| this.container = container; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/github/codestorm/bounceverse/factory/entities/PowerUpFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.github.codestorm.bounceverse.factory.entities; | ||
|
|
||
| import com.almasb.fxgl.dsl.FXGL; | ||
| import com.almasb.fxgl.entity.Entity; | ||
| import com.almasb.fxgl.entity.EntityFactory; | ||
| import com.almasb.fxgl.entity.component.Component; | ||
| import com.almasb.fxgl.physics.BoundingShape; | ||
| import com.almasb.fxgl.physics.HitBox; | ||
| import com.almasb.fxgl.physics.PhysicsComponent; | ||
| import com.almasb.fxgl.texture.Texture; | ||
| import com.github.codestorm.bounceverse.components.properties.powerup.PowerUpContainer; | ||
| import com.github.codestorm.bounceverse.typing.enums.DirectionUnit; | ||
| import com.github.codestorm.bounceverse.typing.enums.EntityType; | ||
| import javafx.geometry.Point2D; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| /** | ||
| * | ||
| * | ||
| * <h1>{@link PowerUpFactory}</h1> | ||
| * | ||
| * Factory để tạo các entity loại {@link EntityType#POWER_UP} trong trò chơi. | ||
| * | ||
| * @see EntityFactory | ||
| */ | ||
| public final class PowerUpFactory implements EntityFactory { | ||
| public static final double DEFAULT_RADIUS = 10; | ||
| public static final double DEFAULT_SPEED = 10; | ||
|
|
||
| /** | ||
| * Tạo mới một PowerUp. Đây là một "abstract" method. | ||
| * | ||
| * @param pos Vị trí | ||
| * @param has Những gì PowerUp này sẽ cung cấp | ||
| * @return Entity PowerUp | ||
| */ | ||
| private Entity newPowerUp(Point2D pos, Texture texture, Component... has) { | ||
| final var hitbox = new HitBox(BoundingShape.circle(DEFAULT_RADIUS)); | ||
|
|
||
| return FXGL.entityBuilder() | ||
| .type(EntityType.POWER_UP) | ||
| .bbox(hitbox) | ||
| .at(pos) | ||
| .view(texture) | ||
| .collidable() | ||
| .with(getPhysicsComponent(), new PowerUpContainer(has)) | ||
| .buildAndAttach(); | ||
| } | ||
|
|
||
| @NotNull private static PhysicsComponent getPhysicsComponent() { | ||
| final var velocity = DirectionUnit.DOWN.getVector().mul(DEFAULT_SPEED); | ||
|
|
||
| var physics = new PhysicsComponent(); | ||
| physics.setOnPhysicsInitialized( | ||
| () -> { | ||
| physics.setLinearVelocity(velocity.toPoint2D()); | ||
| physics.setAngularVelocity(0); | ||
| physics.getBody().setFixedRotation(true); | ||
| physics.getBody().setLinearDamping(0f); | ||
| physics.getBody().setAngularDamping(0f); | ||
| }); | ||
| return physics; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding required constructors to the abstract class
UndoableBehavioris a breaking change that requires all subclasses to define explicit constructors. Consider providing a default no-arg constructor or documenting this breaking change.