Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.codestorm.bounceverse;

import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.dsl.FXGL;
import com.github.codestorm.bounceverse.gameManager.GameManager;
import javafx.scene.paint.Color;

public class BounceVerseApp extends GameApplication {
private GameManager gameManager;

@Override
protected void initSettings(GameSettings settings) {
settings.setWidth(900);
settings.setHeight(600);
settings.setTitle("");
}

@Override
protected void initGame() {
gameManager = new GameManager();

FXGL.getGameScene().setBackgroundColor(Color.web("#2B2B2B"));
gameManager.spawnBricks();
}

public static void main(String[] args) {
launch(args);
}
}
85 changes: 0 additions & 85 deletions src/main/java/com/github/codestorm/bounceverse/brick/Brick.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.github.codestorm.bounceverse.brick;

import com.almasb.fxgl.entity.component.Component;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

/**
* Represents the core behavior and appearance of a brick in the game.
* <p>
* This component handles HP, color updates, and destruction logic.
*/
public class BrickComponent extends Component {
private final int width;
private final int height;
private final int initialHp;
private final Color baseColor;
private int hp;
private boolean destroyed;
private Rectangle view;

public BrickComponent(int width, int height, int hp, Color baseColor) {
this.width = width;
this.height = height;
this.hp = hp;
this.initialHp = hp;
this.baseColor = baseColor;
this.destroyed = false;
}

@Override
public void onAdded() {
// Create visual representation when added to the entity
view = new Rectangle(width, height);
view.setArcWidth(8);
view.setArcHeight(8);
// view.setStrokeWidth(1.5);
updateColor();
getEntity().getViewComponent().addChild(view);
}

/**
* Reduces the brick's HP by one when hit.
* If HP reaches zero, the brick is removed from the world.
*/
public void hit() {
if (!destroyed && hp > 0) {
hp--;
if (hp == 0) {
destroyed = true;
onDestroyed();
} else {
updateColor();
}
}
}

/**
* Updates the brick color based on remaining HP.
* The color becomes darker as HP decreases.
*/
private void updateColor() {
if (view == null)
return;
float ratio = (float) hp / initialHp;
Color dimmed = baseColor.deriveColor(0, 1, 0.6 + 0.4 * ratio, 1);
view.setFill(dimmed);
view.setStroke(Color.BLACK);
}

/**
* Handles destruction when the brick is fully broken.
* Removes the brick entity from the game world.
*/
protected void onDestroyed() {
getEntity().removeFromWorld();
}

/** Returns score gained by destroying the brick. */
public int getScore() {
return initialHp * 10;
}

public int getHp() {
return hp;
}

public int getWidth() {
return width;
}

public int getHeight() {
return height;
}

public boolean isDestroyed() {
return destroyed;
}

public void setDestroyed(boolean destroyed) {
this.destroyed = destroyed;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.github.codestorm.bounceverse.brick;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.EntityFactory;
import com.almasb.fxgl.entity.SpawnData;
import com.almasb.fxgl.entity.Spawns;
import com.almasb.fxgl.entity.components.CollidableComponent;
import com.github.codestorm.bounceverse.gameManager.BounceverseType;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

/**
* Factory class responsible for creating various types of brick entities used
* in the game.
*/
public class BrickFactory implements EntityFactory {

private static final int DEFAULT_WIDTH = 80;
private static final int DEFAULT_HEIGHT = 30;
private static final int DEFAULT_HP = 1;

/** Normal brick. */
@Spawns("normalBrick")
public Entity newNormalBrick(SpawnData data) {
return FXGL.entityBuilder(data)
.type(BounceverseType.BRICK)
.viewWithBBox(new Rectangle(DEFAULT_WIDTH, DEFAULT_HEIGHT, Color.LIGHTBLUE))
.with(new CollidableComponent(true))
.with(new BrickComponent(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_HP, Color.LIGHTBLUE))
.build();
}

/** Strong brick with higher HP. */
@Spawns("strongBrick")
public Entity newStrongBrick(SpawnData data) {
return FXGL.entityBuilder(data)
.type(BounceverseType.BRICK)
.viewWithBBox(new Rectangle(DEFAULT_WIDTH, DEFAULT_HEIGHT, Color.ORANGE))
.with(new CollidableComponent(true))
.with(new BrickComponent(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_HP * 3, Color.ORANGE))
.build();
}

/** Explosive brick that damages nearby bricks when destroyed. */
@Spawns("explodeBrick")
public Entity newExplodeBrick(SpawnData data) {
return FXGL.entityBuilder(data)
.type(BounceverseType.BRICK)
.viewWithBBox(new Rectangle(DEFAULT_WIDTH, DEFAULT_HEIGHT, Color.RED))
.with(new CollidableComponent(true))
.with(new ExplodeBrick(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_HP, Color.RED))
.build();
}

/** Protected brick with shield on one side. */
@Spawns("protectedBrick")
public Entity newProtectedBrick(SpawnData data) {
String shieldSide = data.get("shieldSide");

ProtectedBrick protectedBrick = new ProtectedBrick(
DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_HP, Color.WHITE, shieldSide);

Rectangle body = new Rectangle(DEFAULT_WIDTH, DEFAULT_HEIGHT);
body.setArcWidth(8);
body.setArcHeight(8);

Rectangle shield = null;
double thickness = 8;

switch (shieldSide.toLowerCase()) {
case "top" -> shield = new Rectangle(-1, -2, DEFAULT_WIDTH + 1, thickness);
case "bottom" -> shield = new Rectangle(-1, DEFAULT_HEIGHT - thickness + 2, DEFAULT_WIDTH + 2,
thickness);
case "left" -> shield = new Rectangle(-2, -1, thickness, DEFAULT_HEIGHT + 2);
case "right" -> shield = new Rectangle(DEFAULT_WIDTH - thickness + 2, -1, thickness,
DEFAULT_HEIGHT + 1);
}

if (shield != null)
shield.setFill(Color.GOLD);

Group view = (shield != null) ? new Group(body, shield) : new Group(body);

return FXGL.entityBuilder(data)
.type(BounceverseType.BRICK)
.viewWithBBox(view)
.with(new CollidableComponent(true))
.with(protectedBrick)
.build();
}
}

This file was deleted.

Loading
Loading