Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ name: Build Bytecode
on:
push:
pull_request:
types: [ opened, ready_for_review, reopened ]

permissions:
contents: read

jobs:
build:
if: "github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/linting.yml

This file was deleted.

54 changes: 54 additions & 0 deletions .github/workflows/spotlessCheck.yml
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'com.github.almasb:fxgl:21.1'
implementation 'com.google.guava:guava:33.5.0-jre'
implementation 'com.moandjiezana.toml:toml4j:0.7.2'
}

application {
Expand Down
145 changes: 11 additions & 134 deletions src/main/java/com/github/codestorm/bounceverse/Bounceverse.java
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);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/github/codestorm/bounceverse/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static final class IO {
public static Properties loadProperties(String path) throws IOException {
InputStream fileStream = IO.class.getResourceAsStream(path);
if (fileStream == null) {
throw new IOException("Cannot open InputStream in" + path);
throw new IOException("Cannot open InputStream on " + path);
}

Properties prop = new Properties();
Expand Down Expand Up @@ -92,7 +92,7 @@ public static final class Time {
*
* @see ActiveCooldown
*/
public static class Cooldown {
public static final class Cooldown {
/** Đại diện cooldown hiện tại. Giống như một wrapper của {@link TimerAction}. */
public final class ActiveCooldown {
private TimerAction waiter = null;
Expand Down
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() {}
}
Loading
Loading