Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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));



/*
*
*
*
*
*/

run(() -> {
if (random(0, 100) < 20) {
double x = random(0, getAppWidth() - 80);
System.out.println("Spawning coin at x=" + x + ", y = 0");
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());
coinComponent = coin.getComponent(CoinComponent.class);


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!");
coinComponent.incrementCoin();
});
}

/**
Expand Down