-
Notifications
You must be signed in to change notification settings - Fork 0
coin functionality added #7
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
base: main
Are you sure you want to change the base?
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 with no content violates organization guideline against commented code in codebases. This creates visual noise and reduces code readability without providing any documentation value. Standards
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. π οΈ Refactor suggestion | π Major Remove the empty comment block. The comment block contains no useful information and serves no purpose. Apply this diff to remove the empty comment block: - /*
- *
- *
- *
- *
- */
-
run(() -> {π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| run(() -> { | ||||||||||||||||||||||||||||||
| if (random(0, 100) < 20) { | ||||||||||||||||||||||||||||||
|
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. Magic Number UsageHardcoded probability value 20 violates organization guideline against variable hardcoding. Magic numbers reduce maintainability and make game balance adjustments difficult without code changes. Standards
|
||||||||||||||||||||||||||||||
| double x = random(0, getAppWidth() - 80); | ||||||||||||||||||||||||||||||
| 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. 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 RemovalDebug print statement should be removed from production code. Console output in game loop can impact performance and creates unnecessary log noise in production environments. 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. 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 RemovalDebug print statement should be removed from production code. Console output during initialization creates unnecessary log entries and violates clean code practices. 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. The
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Comment on lines
+112
to
+115
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. π§© Analysis chainVerify entity type naming consistency. The code spawns an entity named "Coins" (plural, capitalized) at Line 112, but the collision handler references
Also, consider using a logger instead of Run the following script to verify the entity types and factory definitions: π Script executed: #!/bin/bash
# Description: Check for coin-related entity definitions in GameEntityFactory and EntityType enum
# Search for entity type definitions
echo "=== Searching for EntityType.COIN enum definition ==="
ast-grep --pattern 'enum EntityType {
$$$
}'
echo -e "\n=== Searching for coin entity factory methods ==="
rg -nP --type=java -C3 'spawn\w*\("(?i)coins?"\)|@Spawns\("(?i)coins?"\)'
echo -e "\n=== Searching for EntityType references ==="
rg -nP --type=java 'EntityType\.COIN'Length of output: 313 π Script executed: #!/bin/bash
# Locate EntityType.java
echo "=== Locating EntityType.java ==="
fd EntityType.java -t f
# Inspect EntityType enum for COIN
echo -e "\n=== Inspecting EntityType enum for COIN ==="
sed -n '1,200p' "$(fd EntityType.java -t f)" | grep -n 'enum EntityType' -A50 || echo "EntityType enum not found or no COIN entry"
# Locate GameEntityFactory.java
echo -e "\n=== Locating GameEntityFactory.java ==="
fd GameEntityFactory.java -t f
# Inspect GameEntityFactory for coin spawn definitions
echo -e "\n=== Searching in GameEntityFactory for 'coin' ==="
grep -RIn 'coin' "$(fd GameEntityFactory.java -t f)"Length of output: 411 Add missing
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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. 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 RemovalDebug print statement should be removed from production code. Console output in collision detection can impact game performance and creates unnecessary log noise. Standards
|
||||||||||||||||||||||||||||||
| coinComponent.incrementCoin(); | ||||||||||||||||||||||||||||||
|
Comment on lines
+148
to
+152
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. Suggestion: Avoid shadowing the class field
Suggested change
Why Change? βThe improved code makes two small, local changes:
These changes compile in the existing context (no new imports or API usage). The code references (onCollisionBegin, EntityType, FXGL, GameConstants, coinComponent) already exist in the class/diff. The guard is conservative and safe: if coinComponent is always initialized in initGame (as shown in the PR), this is a no-op; if not, it prevents a runtime crash. There is no change in control flow or behavior except the added safety and logging, so it won't break production. Assumptions:
Given the above, the suggestion is syntactically correct, executable, and does not introduce bugs. |
||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
Comment on lines
+148
to
+153
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. π§© Analysis chainMissing constant GameConstants.COIN_GAIN causes compilation failure. Line 149 references Additionally, consider using a logger instead of Add the missing constant to public static final String COIN_GAIN = "coinGain.wav";Ensure the corresponding sound file exists in the assets directory. Run the following script to verify: π Script executed: #!/bin/bash
# Description: Check if COIN_GAIN constant exists and verify sound file
echo "=== Checking for COIN_GAIN constant in GameConstants ==="
rg -nP --type=java 'COIN_GAIN\s*='
echo -e "\n=== Checking for coin-related sound files ==="
fd -e wav -i coinLength of output: 103 Add missing constant, asset, and replace println with logger
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
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.
This large, empty comment block appears to be a leftover from development and adds unnecessary clutter to the code. It should be removed for better readability.