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
Add and refactor Systems, Core #15
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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 was deleted.
Oops, something went wrong.
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,54 @@ | ||
| name: Spotless CI | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
| types: [ opened, ready_for_review, reopened ] | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| check: | ||
| runs-on: ubuntu-latest | ||
| if: "github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]')" | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - name: Setup JDK | ||
| uses: actions/setup-java@v5 | ||
| with: | ||
| distribution: oracle | ||
| java-version: 24 | ||
| cache: gradle | ||
| - name: Run Spotless check | ||
| run: | | ||
| chmod +x gradlew | ||
| ./gradlew spotlessCheck | ||
|
|
||
| apply: | ||
| runs-on: ubuntu-latest | ||
| needs: check | ||
| if: needs.check.result == 'failure' | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - name: Setup JDK | ||
| uses: actions/setup-java@v5 | ||
| with: | ||
| distribution: oracle | ||
| java-version: 24 | ||
| cache: gradle | ||
| - name: Run Spotless apply | ||
| run: | | ||
| chmod +x gradlew | ||
| ./gradlew spotlessApply | ||
| - name: Commit and Push | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add -A | ||
| git commit -m "[skip ci] Apply automatic code formatting" | ||
| git push |
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
145 changes: 11 additions & 134 deletions
145
src/main/java/com/github/codestorm/bounceverse/Bounceverse.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 |
|---|---|---|
| @@ -1,176 +1,53 @@ | ||
| package com.github.codestorm.bounceverse; | ||
|
|
||
| import com.almasb.fxgl.app.ApplicationMode; | ||
| import com.almasb.fxgl.app.GameApplication; | ||
| import com.almasb.fxgl.app.GameSettings; | ||
| import com.almasb.fxgl.dsl.FXGL; | ||
| import com.almasb.fxgl.input.UserAction; | ||
| import com.github.codestorm.bounceverse.components.properties.Velocity; | ||
| import com.github.codestorm.bounceverse.data.types.EntityType; | ||
| import com.github.codestorm.bounceverse.factory.BrickFactory; | ||
| import com.github.codestorm.bounceverse.factory.BulletFactory; | ||
| import com.github.codestorm.bounceverse.factory.PaddleFactory; | ||
| import com.github.codestorm.bounceverse.factory.SceneFactory; | ||
| import com.github.codestorm.bounceverse.factory.WallFactory; | ||
| import com.github.codestorm.bounceverse.systems.LaunchOption; | ||
| import com.github.codestorm.bounceverse.systems.physics.CollisionSystem; | ||
| import com.github.codestorm.bounceverse.core.*; | ||
| import com.github.codestorm.bounceverse.core.systems.*; | ||
| import java.io.IOException; | ||
| import java.util.Properties; | ||
| import javafx.scene.input.KeyCode; | ||
| import javafx.scene.paint.Color; | ||
|
|
||
| /** | ||
| * | ||
| * | ||
| * <h1>{@link Bounceverse}</h1> | ||
| * | ||
| * Phần Hệ thống Chương trình chính của game, nơi mà mọi thứ bắt đầu... | ||
| * Phần Hệ thống Chương trình chính của game, nơi mà mọi thứ bắt đầu từ {@link #main(String[])}... | ||
| * | ||
| * <p><i>Game {@link Bounceverse} được lấy cảm hứng từ game Arkanoid nổi tiếng, nơi người chơi điều | ||
| * khiển một thanh để đỡ bóng và phá vỡ các viên gạch. Mục tiêu của game là phá vỡ tất cả các viên | ||
| * gạch và dành được điểm số cao nhất. Nhưng liệu mọi thứ chỉ đơn giản như vậy?</i> | ||
| */ | ||
| public final class Bounceverse extends GameApplication { | ||
| private static LaunchOption launchOption; | ||
|
|
||
| /** | ||
| * Cấu hình game. | ||
| * | ||
| * <p>Sử dụng {@link #loadConfigs()} để load các config. | ||
| */ | ||
| private static final class Configs { | ||
| private static final String ROOT = "/configs/"; | ||
|
|
||
| /** Cấu hình game bên trong hệ thống game. */ | ||
| private static final class System { | ||
| public static Properties settings; | ||
|
|
||
| private System() {} | ||
| } | ||
|
|
||
| /** Cấu hình game bên ngoài hệ thống game. */ | ||
| private static final class Options { | ||
| public static Properties DEFAULT; // Cấu hình mặc định của trò chơi | ||
|
|
||
| private Options() {} | ||
| } | ||
|
|
||
| /** | ||
| * Load game configs. | ||
| * | ||
| * @throws IOException if an error occurred when reading from the input stream. | ||
| */ | ||
| public static void loadConfigs() throws IOException { | ||
| Options.DEFAULT = Utils.IO.loadProperties(ROOT + "default.properties"); | ||
| System.settings = Utils.IO.loadProperties(ROOT + "system/settings.properties"); | ||
| } | ||
|
|
||
| private Configs() {} | ||
| } | ||
|
|
||
| @Override | ||
| protected void initSettings(GameSettings settings) { | ||
| protected void initSettings(com.almasb.fxgl.app.GameSettings settings) { | ||
| try { | ||
| Configs.loadConfigs(); | ||
| SettingsManager.load(settings); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| // Basic | ||
| settings.setTitle(Configs.System.settings.getProperty("settings.name")); | ||
| settings.setVersion(Configs.System.settings.getProperty("settings.version")); | ||
| settings.setCredits(Utils.IO.readTextFile("credits.txt")); | ||
| settings.setApplicationMode( | ||
| Boolean.parseBoolean(Configs.System.settings.getProperty("settings.devMode")) | ||
| ? ApplicationMode.DEVELOPER | ||
| : (launchOption.isDebug()) | ||
| ? ApplicationMode.DEBUG | ||
| : ApplicationMode.RELEASE); | ||
|
|
||
| // Display | ||
| settings.setWidth(Integer.parseInt(Configs.Options.DEFAULT.getProperty("width"))); | ||
| settings.setHeight(Integer.parseInt(Configs.Options.DEFAULT.getProperty("height"))); | ||
| settings.setFullScreenAllowed(true); | ||
|
|
||
| // In-app | ||
| settings.setSceneFactory(new SceneFactory()); | ||
| settings.setMainMenuEnabled(true); | ||
| settings.setIntroEnabled(true); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initGame() { | ||
| FXGL.getGameWorld().addEntityFactory(new BrickFactory()); | ||
| FXGL.getGameWorld().addEntityFactory(new BulletFactory()); | ||
| FXGL.getGameWorld().addEntityFactory(new PaddleFactory()); | ||
| FXGL.getGameWorld().addEntityFactory(new WallFactory()); | ||
|
|
||
| // Spawn walls. | ||
| FXGL.spawn("wallLeft"); | ||
| FXGL.spawn("wallRight"); | ||
| FXGL.spawn("wallTop"); | ||
|
|
||
| // Spawn paddle | ||
| double px = FXGL.getAppWidth() / 2.0 - 60; | ||
| double py = FXGL.getAppHeight() - 40; | ||
| FXGL.spawn("paddle", px, py); | ||
|
|
||
| FXGL.spawn("normalBrick", 100, 100); | ||
| FXGL.spawn("normalBrick", 200, 200); | ||
| GameSystem.getInstance().apply(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initInput() { | ||
| FXGL.getInput() | ||
| .addAction( | ||
| new UserAction("Move Left") { | ||
| @Override | ||
| protected void onActionBegin() { | ||
| FXGL.getGameWorld() | ||
| .getEntitiesByType(EntityType.PADDLE) | ||
| .forEach(e -> e.getComponent(Velocity.class).left()); | ||
| } | ||
|
|
||
| @Override | ||
| protected void onActionEnd() { | ||
| FXGL.getGameWorld() | ||
| .getEntitiesByType(EntityType.PADDLE) | ||
| .forEach(e -> e.getComponent(Velocity.class).stop()); | ||
| } | ||
| }, | ||
| KeyCode.LEFT); | ||
|
|
||
| FXGL.getInput() | ||
| .addAction( | ||
| new UserAction("Move Right") { | ||
| @Override | ||
| protected void onActionBegin() { | ||
| FXGL.getGameWorld() | ||
| .getEntitiesByType(EntityType.PADDLE) | ||
| .forEach(e -> e.getComponent(Velocity.class).right()); | ||
| } | ||
|
|
||
| @Override | ||
| protected void onActionEnd() { | ||
| FXGL.getGameWorld() | ||
| .getEntitiesByType(EntityType.PADDLE) | ||
| .forEach(e -> e.getComponent(Velocity.class).stop()); | ||
| } | ||
| }, | ||
| KeyCode.RIGHT); | ||
| InputSystem.getInstance().apply(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initPhysics() { | ||
| CollisionSystem.getInstance().apply(); | ||
| PhysicSystem.getInstance().apply(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initUI() { | ||
| FXGL.getGameScene().setBackgroundColor(Color.web("#2B2B2B")); | ||
| UISystem.getInstance().apply(); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| launchOption = new LaunchOption(args); | ||
| static void main(String[] args) { | ||
| LaunchOptions.load(args); | ||
| launch(args); | ||
| } | ||
| } | ||
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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/github/codestorm/bounceverse/core/LaunchOptions.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,33 @@ | ||
| package com.github.codestorm.bounceverse.core; | ||
|
|
||
| import com.github.codestorm.bounceverse.Utils; | ||
|
|
||
| /** | ||
| * | ||
| * | ||
| * <h1>{@link LaunchOptions}</h1> | ||
| * | ||
| * Các tùy chọn khi khởi động được áp dụng trong game. | ||
| * | ||
| * <p>Sử dụng {@link #load(String...)} để tải các options. | ||
| */ | ||
| public final class LaunchOptions { | ||
| private static boolean debug = false; | ||
|
|
||
| /** | ||
| * Tải các launch options từ Command-line Arguments. | ||
| * | ||
| * @param args Command-Line Arguments - được truyền vào từ hàm {@code main()} | ||
| */ | ||
| public static void load(String... args) { | ||
| final var map = Utils.IO.parseArgs(args, null, null); | ||
|
|
||
| debug = Boolean.parseBoolean(map.getOrDefault("debug", "false")); | ||
| } | ||
|
|
||
| public static boolean isDebug() { | ||
| return debug; | ||
| } | ||
|
|
||
| private LaunchOptions() {} | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.