Spawning objects near you

Hi,

So for school, we’re assigned to change the phaser tutorial a bit. So right now, each time you collect the 12 stars, a bomb spawns. I made a pretty big map (2000,600) and want to have multiple stars in it. And each time you collect one, a bomb spawns in a radius arround you. How could I do that?

This is the code from the tutorial that has to be changed:

if (stars.countActive(true) === 0)
{
// A new batch of stars to collect
stars.children.iterate(function (child) {

        child.enableBody(true, child.x, 0, true, true);

    });

    var x = (player.x < 400) ? Phaser.Math.Between(400, 800) : Phaser.Math.Between(0, 400);

    var bomb = bombs.create(x, 16, 'bomb');
    bomb.setBounce(1);
    bomb.setCollideWorldBounds(true);
    bomb.setVelocity(Phaser.Math.Between(-200, 200), 20);
    bomb.allowGravity = false;

}

Start by extracting a new function:

function createBomb (x, y) {
  var bomb = bombs.create(x, y, 'bomb');
  // etc. …
}

Then modify collectStar(). You can find the player’s position in player.

Don’t enitrely know what you mean after the etc. part and modifying collectstar, would you mind typing it more out? I’m still trying to learn phaser and my other classmates don’t understand it as well and our teacher lets us figure it out