Enemy Cow

Hi! I am trying to make it so that if the star hits the cow, the star will bounce off of it and the score from collecting the dust is deducted by 40. When the star collides, it seems to collide hundreds of time instead of the one time I’m intending. How do I fix this?

Thank you!

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8" />
    <title> Wishing Star </title>
    <script src="//cdn.jsdelivr.net/npm/phaser@3.11.0/dist/phaser.js"></script>
    <style type="text/css">
        body {
            margin: 0;
        }
    </style>
</head>
<body>

<script type="text/javascript">

var config = {
    type: Phaser.AUTO,
    width: 1300,         //dimensions
    height: 600,
    physics: {
        default: 'arcade',
        arcade: {
            gravity: { y: 300 },
            debug: false
        }
    },
    scene: {
        preload: preload,
        create: create,
        update: update,
    }
};

var player;
var particles_;
var emitter_;
var cow_enemy_;
var dust;
var dust_spawn_area;
var score = 0;
var scoreText;
var cursors;

var game = new Phaser.Game(config);

function preload ()
{
    //background
    this.load.image('bg', 'assets/background.png');
    //sprites
    this.load.image('star', 'assets/sprites/peonay.png');
    this.load.image('stardust', 'assets/sprites/starDust.png');
    this.load.image('cow','assets/sprites/enemies/cow/chew2.png');
    //particles
    this.load.image('red','assets/particles/red.png');
    
}

function create ()
{
    //camera and world bounds
    this.cameras.main.setBounds(0, 0, 1000  , 1200 );
    this.physics.world.setBounds(220, 0, 850 , 1200);

    //adding the background
    this.add.image(250, 0, 'bg').setOrigin(0);

    particles_ = this.add.particles('red');

    //  Create an emitter by passing in a config object directly to the Particle Manager
    emitter_ = particles_.createEmitter({
    speed: 100,
    scale: { start: 0.5, end: 0 },
    //blendMode: 'ADD'
    });

    //adding the star as a sprite
    //x, y, key for spawn
    player = this.physics.add.sprite(650, 200, 'star');

    player.setCollideWorldBounds(true);

    player.setBounce(0.2);

    //enabling keyboard input
    cursors = this.input.keyboard.createCursorKeys();

    //This is how we get the camera to follow the player
    this.cameras.main.startFollow(player, true, 0.05, 0.05);

    //Get the particles to follow the player
    emitter_.startFollow(player);
    
    
    //  Create 10 sprites (they all start life at 0x0)
    //  added as a physics group to allow for overlap
    dust = this.physics.add.group(
       {
            key: 'stardust', 
            frameQuantity: 10,
            immovable: true,
            allowGravity: false 
        }
    );

    dust_spawn_area = new Phaser.Geom.Rectangle(250, 0, 750, 1200);

    //  Randomly position the sprites within the rectangle
    Phaser.Actions.RandomRectangle(dust.getChildren(), dust_spawn_area);

    //cow_enemy_ = this.physics.add.sprite(Phaser.Math.Between(220, 850),Phaser.Math.Between(0, 1200),'cow_enemy');
      cow_enemy_ = this.physics.add.group( 
                {
                    key: 'cow',
                    immovable: true,
                    allowGravity: false 
                    }
          ); 
    Phaser.Actions.RandomRectangle(cow_enemy_.getChildren(), dust_spawn_area);

    //  The score
    scoreText = this.add.text(16, 16, 'score: 0', { fontSize: '32px', fill: '#ffc0cb' });
    
    // If the player hits the dust, we call collectDust
    this.physics.add.overlap(player, dust, collectDust, null, this);

    //If the player hits a cow, we shake the camera, lose some dust, try for emit
    this.physics.add.collider(player, cow_enemy_, shake, null, this);




}

function update ()
{
    player.setVelocity(0);

    if (cursors.left.isDown)
    {
        player.setVelocityX(-500);
    }
    else if (cursors.right.isDown)
    {
        player.setVelocityX(500);
    }

    if (cursors.up.isDown)
    {
        player.setVelocityY(-500);
    }
    else if (cursors.down.isDown)
    {
        player.setVelocityY(500);
    }
}

function collectDust(player, dust){

    dust.disableBody(true, true);

    //  Add and update the score
    score += 10;
    scoreText.setText('Score: ' + score);
 
}

function shake(){
    this.cameras.main.shake(500);
    
    score-=40;

}




/*
    //activating world gravity in the y direction with the initial rate
    //game.physics.world.gravity.y = 60;
    //player.setGravity(0,1000);
    //player.body.setGravityY(12500);
    // player.body.setAllowGravity(true);
    //accelerateTo(player, 650 , 600 , 50, 200, 500);

*/

</script>

</body>
</html>