-
Notifications
You must be signed in to change notification settings - Fork 0
coin functionality added #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,8 @@ public class DinosaurController { | |||||||||||||||||||||||||||||||||||||||||||||||||
| private Entity score; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| private Entity life; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| private Entity bomb; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| private Entity coin; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| private CoinComponent coinComponent; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Summary : | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty Comment BlockEmpty comment block provides no documentation value and clutters code. Should contain meaningful description of coin spawning logic or be removed entirely. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| run(() -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (random(0, 100) < 20) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| double x = random(0, getAppWidth() - 80); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+101
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Random Generation InefficiencyTwo separate random() calls per spawn cycle creates unnecessary overhead. Single random value could determine both spawn decision and position reducing computational cost. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Spawning coin at x=" + x + ", y = 0"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Console Spam PerformanceDebug 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
Comment on lines
+102
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug Output RemovalConsole 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug Code PresentDebug print statements left in production code create console noise and potential performance overhead. Should be removed or replaced with proper logging framework. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| 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()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove Debug CodeDebug print statement left in production code clutters console output. Should be removed or replaced with proper logging framework for maintainable debugging. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug Output RemovalDebug print statement in initialization code should be removed for production. Console output adds unnecessary overhead and clutters logs. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug Code PresentDebug print statements left in production code create console noise and potential performance overhead. Should be removed or replaced with proper logging framework. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| coinComponent = coin.getComponent(CoinComponent.class); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Component Initialization RaceCoinComponent retrieved immediately after entity spawn without validation. Component may not be attached yet causing null reference in collision handlers. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| bomb.addComponent(new BombComponent()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Summary : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Detect the collision between the game elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug Output RemovalDebug output in collision handler executes frequently during gameplay. Console I/O in hot path degrades performance and should be removed from production builds. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug Code PresentDebug print statements left in production code create console noise and potential performance overhead. Should be removed or replaced with proper logging framework. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| coinComponent.incrementCoin(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null Pointer RiskCoinComponent accessed without null check after entity spawning. If coin entity creation fails or component missing, NullPointerException crashes game during collision detection. Commitable Suggestion
Suggested change
Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Global State CouplingCollision handler modifies global coinComponent instead of collision participant's component. Creates tight coupling between UI display and collision logic. Breaks single responsibility principle. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null Pointer RiskCoinComponent accessed without null check after collision. If coin entity lacks CoinComponent, NullPointerException crashes game. Component retrieval can fail during entity lifecycle transitions. Commitable Suggestion
Suggested change
Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Component Reference MismatchGlobal coinComponent references UI display entity while collision handler receives different coin pickup entity. Increment affects wrong component causing display/logic desynchronization. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null Pointer RiskCoinComponent accessed without null check after collision. If coin entity lacks CoinComponent, NullPointerException crashes game during collision handling. Commitable Suggestion
Suggested change
Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null Pointer RiskCoinComponent accessed without null check in collision handler. If coin entity lacks component, NullPointerException crashes game during collision detection. Commitable Suggestion
Suggested change
Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null Pointer RiskCoinComponent accessed without null check in collision handler. If coin entity lacks CoinComponent, NullPointerException crashes game during collision processing. Commitable Suggestion
Suggested change
Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
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.
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