Skip to content
Closed
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
Expand Up @@ -28,6 +28,8 @@ public class DinosaurController {
private Entity score;
private Entity life;
private Entity bomb;
private Entity coin;
private CoinComponent coinComponent;

/**
* Summary :
Expand Down Expand Up @@ -72,12 +74,12 @@ public void initInput() {

public void initGame() {
getGameWorld().addEntityFactory(new GameEntityFactory());
spawn("background", 0, 0);
spawn("background", 0, 0);

player = spawn("player", getAppCenter().getX() - 45, getAppHeight() - 200);

FXGL.play(GameConstants.BACKGROUND_SOUND);

/*
* At each second that passes, we have 2 out of 3 chances of spawning a green
* dinosaur
Expand All @@ -87,16 +89,35 @@ public void initGame() {
if (random(0, 2) < 2)
spawn("greenDino", random(0, getAppWidth() - 80), -50);
}, seconds(0.75));



/*
*
*
*
*
*/
Comment on lines +93 to +98
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Empty Comments

Empty comment block provides no documentation value and clutters codebase. Should be removed or populated with meaningful documentation describing coin spawning logic.

Standards
  • Clean Code
  • Documentation Standards

Comment on lines +93 to +98
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty Comment Block

Empty comment block provides no documentation value and clutters code. Should contain meaningful description of coin spawning logic or be removed entirely.

Standards
  • Clean Code
  • Documentation Standards


run(() -> {
if (random(0, 100) < 20) {
double x = random(0, getAppWidth() - 80);
Comment on lines +101 to +102
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random Generation Inefficiency

Two separate random() calls per spawn cycle creates unnecessary overhead. Single random value could determine both spawn decision and position reducing computational cost.

Standards
  • ISO-25010 Resource Utilization
  • Algorithm Optimization

System.out.println("Spawning coin at x=" + x + ", y = 0");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console Spam Performance

Debug output in production game loop executes every second with 20% probability. Console I/O operations block execution thread causing frame drops and performance degradation.

Standards
  • ISO-25010 Time Behaviour
  • Production Code Standards

Comment on lines +102 to +103
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug Output Removal

Console output in game loop creates I/O overhead during runtime. Debug statements should be removed from production code. Repeated printing impacts frame rate performance.

Standards
  • Clean Code
  • Production Readiness

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug Code Present

Debug print statements left in production code create console noise and potential performance overhead. Should be removed or replaced with proper logging framework.

Standards
  • Clean Code
  • Production Readiness

spawn("coin", x, 0);
}
}, seconds(1.0));


score = spawn("Score", getAppCenter().getX() - 270, getAppCenter().getY() - 320);
life = spawn("Life", getAppCenter().getX() - 260, getAppCenter().getY() - 250);
bomb = spawn("Bomb", getAppCenter().getX() - 260, getAppCenter().getY() - 180);

coin = spawn("Coins", getAppCenter().getX() - 260, getAppCenter().getY() - 120);
System.out.println("Coins at : " + coin.getPosition());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Debug Code

Debug print statement left in production code clutters console output. Should be removed or replaced with proper logging framework for maintainable debugging.

Standards
  • Clean Code
  • Production Readiness

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug Output Removal

Debug print statement in initialization code should be removed for production. Console output adds unnecessary overhead and clutters logs.

Standards
  • Clean Code
  • Production Readiness

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug Code Present

Debug print statements left in production code create console noise and potential performance overhead. Should be removed or replaced with proper logging framework.

Standards
  • Clean Code
  • Production Readiness

coinComponent = coin.getComponent(CoinComponent.class);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Component Initialization Race

CoinComponent retrieved immediately after entity spawn without validation. Component may not be attached yet causing null reference in collision handlers.

Standards
  • ISO-25010 Maturity
  • Component Lifecycle Management



bomb.addComponent(new BombComponent());
}


/**
* Summary :
* Detect the collision between the game elements.
Expand Down Expand Up @@ -124,6 +145,12 @@ public void initPhysics() {
System.out.println("You touched a dino !");
damagePlayer();
});
onCollisionBegin(EntityType.PLAYER, EntityType.COIN, (player, coin) -> {
FXGL.play(GameConstants.COIN_GAIN);
coin.removeFromWorld();
System.out.println("You touched a coin!");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug Output Removal

Debug output in collision handler executes frequently during gameplay. Console I/O in hot path degrades performance and should be removed from production builds.

Standards
  • Clean Code
  • Hot Path Optimization

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug Code Present

Debug print statements left in production code create console noise and potential performance overhead. Should be removed or replaced with proper logging framework.

Standards
  • Clean Code
  • Production Readiness

coinComponent.incrementCoin();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null Pointer Risk

CoinComponent accessed without null check after entity spawning. If coin entity creation fails or component missing, NullPointerException crashes game during collision detection.

            if (coinComponent != null) {
                coinComponent.incrementCoin();
            } else {
                System.err.println("Warning: CoinComponent is null, unable to increment coin");
            }
Commitable Suggestion
Suggested change
coinComponent.incrementCoin();
if (coinComponent != null) {
coinComponent.incrementCoin();
} else {
System.err.println("Warning: CoinComponent is null, unable to increment coin");
}
Standards
  • ISO-25010 Fault Tolerance
  • Defensive Programming

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global State Coupling

Collision handler modifies global coinComponent instead of collision participant's component. Creates tight coupling between UI display and collision logic. Breaks single responsibility principle.

Standards
  • SOLID-SRP
  • Clean Code
  • Low Coupling

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null Pointer Risk

CoinComponent accessed without null check after collision. If coin entity lacks CoinComponent, NullPointerException crashes game. Component retrieval can fail during entity lifecycle transitions.

            if (coinComponent != null) {
                coinComponent.incrementCoin();
            } else {
                System.out.println("Warning: CoinComponent not available");
            }
Commitable Suggestion
Suggested change
coinComponent.incrementCoin();
if (coinComponent != null) {
coinComponent.incrementCoin();
} else {
System.out.println("Warning: CoinComponent not available");
}
Standards
  • ISO-25010 Fault Tolerance
  • Defensive Programming

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Component Reference Mismatch

Global coinComponent references UI display entity while collision handler receives different coin pickup entity. Increment affects wrong component causing display/logic desynchronization.

Standards
  • Object Reference Integrity
  • Component Lifecycle Management

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null Pointer Risk

CoinComponent accessed without null check after collision. If coin entity lacks CoinComponent, NullPointerException crashes game during collision handling.

            if (coinComponent != null) {
                coinComponent.incrementCoin();
            }
Commitable Suggestion
Suggested change
coinComponent.incrementCoin();
if (coinComponent != null) {
coinComponent.incrementCoin();
}
Standards
  • ISO-25010 Fault Tolerance
  • Java Exception Handling

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null Pointer Risk

CoinComponent accessed without null check in collision handler. If coin entity lacks component, NullPointerException crashes game during collision detection.

            if (coinComponent != null) {
                coinComponent.incrementCoin();
            }
Commitable Suggestion
Suggested change
coinComponent.incrementCoin();
if (coinComponent != null) {
coinComponent.incrementCoin();
}
Standards
  • ISO-25010 Fault Tolerance
  • Defensive Programming

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null Pointer Risk

CoinComponent accessed without null check in collision handler. If coin entity lacks CoinComponent, NullPointerException crashes game during collision processing.

            if (coinComponent != null) {
                coinComponent.incrementCoin();
            }
Commitable Suggestion
Suggested change
coinComponent.incrementCoin();
if (coinComponent != null) {
coinComponent.incrementCoin();
}
Standards
  • ISO-25010 Fault Tolerance
  • Defensive Programming

});
}

/**
Expand Down