How to do...

Hey there,
i’am absolutly new to Phaser3, my first project makes me sick lol.
i try to make a game where u just move left, right and shoot straight up, works pretty good.
my goal is to make a game where u start with ONE ball he jump around, if the player hit the ball, the ball should disappear and 2 new but smaller balls should join, until this point the game works, but then… the problems start, maybe u can help me a bit please…
it everytime called the wrong function… :smiley:

var config = {
type: Phaser.AUTO,
width: 1400,
height: 700,
physics: {
default: ‘arcade’,
arcade: {
gravity: { y: 300 },
debug: true
}
},
scene: {
preload: preload,
create: create,
update: update
}
};

var player;
var cursors;
var laserRed;
var laserBlue;
var score = 0;
var player_hp = 100;
var player_hp2 = 100;
var time;
var safetime;

var balls = {};

var LAZERBLUE;
var interval_blue = -10;

var LAZERRED;
var interval_red = -10;

var game = new Phaser.Game(config);

function preload ()
{
this.load.image(‘player’, ‘gfx/player.png’);
this.load.image(‘player2’, ‘gfx/player2.png’);
this.load.image(‘ball’, ‘gfx/ball_green.png’);
this.load.image(‘ball_75’, ‘gfx/ball_yellow.png’);
this.load.image(‘ball_50’, ‘gfx/ball_red.png’);
this.load.image(‘laserRed’, ‘gfx/laser_red.png’);
this.load.image(‘laserBlue’, ‘gfx/laser_blue.png’);

this.load.image('bg', 'gfx/bg.png');
//this.cameras.main.backgroundColor = Phaser.Display.Color.HexStringToColor("#fff");

}

function create ()
{
this.add.image(0, 0, ‘bg’).setScale(2);

player = this.physics.add.sprite(400, 600, 'player');
player.setCollideWorldBounds(true);
player.setGravity = true;

player2 = this.physics.add.sprite(600, 600, 'player2');
player2.setCollideWorldBounds(true);
player2.setGravity = true;

balls = this.physics.add.group({
		immovable: false,
		allowGravity: true,
	});

laserBlue = this.physics.add.group({
		immovable: true,
		allowGravity: false,
		setCollideWorldBounds: false
	});

laserRed = this.physics.add.group({
		immovable: true,
		allowGravity: false,
		setCollideWorldBounds: false
	});


this.physics.add.collider(laserRed, balls, hitBall);
this.physics.add.collider(laserBlue, balls, hitBall);

this.physics.add.overlap(balls, player, ballHitPlayer, null, this);
this.physics.add.overlap(balls, player2, ballHitPlayer2, null, this);

this.physics.add.collider(balls);

this.physics.add.overlap(player, player2);

cursors = this.input.keyboard.createCursorKeys();
AKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.A);
DKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D);
WKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.W);

scoreText = this.add.text(650, 8, 'score: 0', { fontSize: '12px', fill: '#fff' });
hpPlayer = this.add.text(8, 8, 'HP Player 1: 100', { fontSize: '12px', fill: '#fff' });
hpPlayer2 = this.add.text(1275, 8, 'HP Player 2: 100', { fontSize: '12px', fill: '#fff' });

ball = balls.create(700, 200, 'ball');
ball.setCollideWorldBounds(true);
ball.setBounce(1);
ball.setCircle(150);
ball.setVelocityX(500);

}

function update ()
{
/*
time = this.time.now;
safetime = time;
safetime = safetime + 1000;
*/

if (cursors.left.isDown)
{
    player.setVelocityX(-160);

} else if (cursors.right.isDown)
{
    player.setVelocityX(160);

} else {
    player.setVelocityX(0);
}
if (cursors.up.isDown)
{
	player1_shoot();
} else {
	interval_blue = -1;
}

if (AKey.isDown)
{
    player2.setVelocityX(-160);

} else if(DKey.isDown)
{
	player2.setVelocityX(160);
} else {
	player2.setVelocityX(0);
}
if (WKey.isDown)
{
    player2_shoot();
} else {
	interval_red = -1;
}


var troll =  balls.countActive(true);
console.log(troll);

}

function hitBall(laserRed, laserBlue)
{

ball.destroy();
laserRed.destroy();
createBall75();

}

function hitBall_75(laserRed, laserBlue)
{
ball.destroy();
laserRed.destroy();

}

function createBall75(laserRed, laserBlue)
{
var ballX = ball.x;
var ballY = ball.y;

	ball[1] = balls.create(ballX, ballY, 'ball_75').setScale(0.75);
	ball[1].setCollideWorldBounds(true);
	ball[1].setBounce(1);
	ball[1].setCircle(150);
	
	ball[2] = balls.create(ballX, ballY, 'ball_75').setScale(0.75);
	ball[2].setCollideWorldBounds(true);
	ball[2].setBounce(1);
	ball[2].setCircle(150);
	
		if(ballY < 300)
		{
			ball[1].setVelocityY(0);
			ball[1].setVelocityX(-250);
			ball[2].setVelocityY(0);
			ball[2].setVelocityX(250);
		} else {
			ball[1].setVelocityY(-350);
			ball[1].setVelocityX(-250);
			ball[2].setVelocityY(-350);
			ball[2].setVelocityX(250);
		}

}

function player1_shoot()
{
if(interval_blue < 0)
{
LAZERBLUE = laserBlue.create(player.x, player.y - 10, ‘laserBlue’);
LAZERBLUE.setCollideWorldBounds(false);
LAZERBLUE.setVelocityY(-750);

}

speed_blue = 40;
interval_blue += 1;
	
if(interval_blue > speed_blue)
{
	LAZERBLUE = laserBlue.create(player.x, player.y - 10, 'laserBlue');
	LAZERBLUE.setCollideWorldBounds(false);
	LAZERBLUE.setVelocityY(-750);
	interval_blue = 0;

}

}

function player2_shoot()
{

if(interval_red < 0)
{
	LAZERBLUE = laserRed.create(player2.x, player2.y - 10, 'laserRed');
	LAZERBLUE.setCollideWorldBounds(false);
	LAZERBLUE.setVelocityY(-750);
}

speed_red = 40;
interval_red += 1;
	
if(interval_red > speed_red)
{
	LAZERBLUE = laserRed.create(player2.x, player2.y - 10, 'laserRed');
	LAZERBLUE.setCollideWorldBounds(false);
	LAZERBLUE.setVelocityY(-750);
	interval_red = 0;
}

}

function ballHitPlayer()
{
if(player_hp > 0)
{
player_hp -= 1;
hpPlayer.setText('HP Player 1: ’ + player_hp);
} else {
this.physics.pause();
}

}

function ballHitPlayer2()
{
if(player_hp2 > 0)
{
player_hp2 -= 1;
hpPlayer2.setText('HP Player 2: ’ + player_hp2);
} else {
this.physics.pause();
}
}

What’s the problem?