¿ Dónde esta el error ?
var config = {
  type: Phaser.AUTO,
  width: 800,
  height: 600,
  physics: {
    default: 'arcade',
    arcade: {
      gravity: {y: 0},
      debug: false
    }
  },
  
  scene: {
    preload: preload,
    create: create,
    update: update
  }
};

// Creación del juego
var game = new Phaser.Game(config);

// Variables globales
var cursors;

// Control 1 jugador
var player1Keys = {
  left: Phaser.Input.Keyboard.KeyCodes.LEFT,
  right: Phaser.Input.Keyboard.KeyCodes.RIGHT,
  up: Phaser.Input.Keyboard.KeyCodes.UP,
  down: Phaser.Input.Keyboard.KeyCodes.DOWN,
  turbo: Phaser.Input.Keyboard.KeyCodes.SPACE
};

// Control 2 jugador
var player2Keys = {
  left: Phaser.Input.Keyboard.KeyCodes.A,
  right: Phaser.Input.Keyboard.KeyCodes.D,
  up: Phaser.Input.Keyboard.KeyCodes.W,
  down: Phaser.Input.Keyboard.KeyCodes.S,
  turbo: Phaser.Input.Keyboard.KeyCodes.SHIFT
};

var player1Score = 0;
var player2Score = 0;

var player1TurboTime = 0;
var player2TurboTime = 0;

var player1LastPlaceTime = 0;
var player2LastPlaceTime = false;

var LastPlace1 = false;
var player2LastPlace = false;

var player1Turbo = false;
var player2Turbo = false;

var player1TurboDuration = 10000;
var player2TurboDuration = 10000;
var player1TurboCooldown = 10000;
var player2TurboCooldown = 10000;

var player1MaxHealth = 100;
var player2MaxHealth = 100;
var Health1 = player1MaxHealth;
var player2Health = player2MaxHealth;
var player1DamageMultiplier = 1;
var player2DamageMultiplier = 1;
var player1SpeedMultiplier = 1;
var player2SpeedMultiplier = 1;
var player1LastLapTime = 0;
var player2LastLapTime = 0;
var player1LapCount = 0;
var Finished1 = false;
var player2Finished = false;
var raceFinished = false;
var raceTimeLimit = 180000;
var raceStartTime = 0;
var raceTimeRemaining = 0;
var raceRanking = [];
var carSpeed = 200;
var carTurboSpeed = 400;
var carMaxSpeed = 400;
var carAcceleration = 100;
var carDeceleration = 100;
var carTurnSpeed = 300;
var carTurboDuration = 10000;
var carTurboCooldown = 10000;
var carMaxHealth = 100;
var carDamageMultiplier = 1;
var carSpeedMultiplier = 1;
var carLastLapTime = 0;
var carLapCount = 0;
var carFinished = false;
var carLastPlaceTime = 0;
var carLastPlace = false;
var carTurbo = false;
var carTurboTime = 0;
 
// Creación del circuito
function create() {
  // Crear el circuito
  this.add.image(400, 300, 'background');
  this.physics.world.setBounds(0, 0, 800, 600);
  this.add.image(400, 300, 'track');

  // Crear los obstáculos
  var obstacles = this.physics.add.staticGroup();
// Eje              X    Y
  obstacles.create(200, 200, 'obstacle');
// Eje              X    Y
  obstacles.create(600, 400, 'obstacle');

  // Crear los elementos decorativos
// Eje            X    Y
  this.add.image(100, 100, 'tree');
  this.add.image(700, 500, 'tree');

  // Crear los coches
  player1 = this.physics.add.sprite(100, 300, 'car1');
  player1.setCollideWorldBounds(true);
  player1.setMaxVelocity(carMaxSpeed);
  player1.setDrag(carDeceleration);
  player1.setData('health', player1MaxHealth);
  player1.setData('damageMultiplier', player1DamageMultiplier);
  player1.setData('speedMultiplier', player1SpeedMultiplier);

  player2 = this.physics.add.sprite(700, 300, 'car2');
  player2.setCollideWorldBounds(true);
  player2.setMaxVelocity(carMaxSpeed);
  player2.setDrag(carDeceleration);
  player2.setData('health', player2MaxHealth);
  player2.setData('damageMultiplier', player2DamageMultiplier);
  player2.setData('speedMultiplier', player2SpeedMultiplier);

  // Detección de colisiones
  this.physics.add.collider(player1, player2, function () {
    if (player1Turbo) {
      player2.setData('health', player2.getData('health') - 20 * player1.getData('damageMultiplier'));
    } else {
      player2.setData('health', player2.getData('health') - 10 * player1.getData('damageMultiplier'));
    }

    if (player2.getData('health') <= 0) {
      player2.disableBody(true, true);
      player1Score += 1;
    }
  });

  this.physics.add.collider(player1, obstacles, function () {
    player1.setData('health', player1.getData('health') - 10);

    if (player1.getData('health') <= 0) {
      player1.disableBody(true, true);
      player2Score += 1;
    }
  });
}
 
// Lógica del juego
function update(time, delta) {
  // Controlar la dirección de los coches
  if (cursors.left.isDown) {
    player1.setAngularVelocity(-carTurnSpeed);
  } else if (cursors.right.isDown) {
    player1.setAngularVelocity(carTurnSpeed);
  } else {
    player1.setAngularVelocity(0);
  }

  if (cursors.up.isDown) {
    player1.setAcceleration(carAcceleration * player1.getData('speedMultiplier'));
  } else {
    player1.setAcceleration(0);
  }

  if (cursors.down.isDown) {
    player1.setAcceleration(-carAcceleration * player1.getData('speedMultiplier'));
  }

  if (Phaser.Input.Keyboard.JustDown(cursors.turbo) && player1TurboTime <= 0) {
    player1Turbo = true;
    player1TurboTime = player1TurboDuration;
    player1.setVelocityX(player1.body.velocity.x * carTurboSpeed / carSpeed);
    player1.setVelocityY(player1.body.velocity.y * carTurboSpeed / carSpeed);
  }


  // Establecer el límite de tiempo

  if (raceTimeRemaining <= 0) {
    raceFinished = true;
  } else {
    raceTimeRemaining = raceTimeLimit - (time - raceStartTime);
  }

  // Controlar el uso del turbo especial
  if (player1TurboTime > 0) {
    player1TurboTime -= delta;
  } else {
    player1Turbo = false;
  }

  // Mostrar la imagen con el ranking de los coches al final de la carrera
  if (raceFinished) {
    if (!player1Finished) {
      player1Finished = true;
      player1LastPlaceTime = time;
      raceRanking.push(player1);
    }

    if (!player2Finished) {
      player2Finished = true;
      player2LastPlaceTime = time;
      raceRanking.push(player2);
    }

    if (raceRanking.length == 2) {
      if (raceRanking[0] == player1) {
        player1Score += 2;
      } else {
        player2Score += 2;
      }
    } else if (raceRanking.length == 1) {
      if (raceRanking[0] == player1) {
        player1Score += 3;
      } else {
        player2Score += 3;
      }
    }

    this.add.image(400, 300, 'ranking');
    this.add.text(300, 200, 'Player 1: ' + player1Score, {font: '32px Arial', fill: '#ffffff'});
    this.add.text(300, 250, 'Player 2: ' + player2Score, {font: '32px Arial', fill: '#ffffff'});

    // Actualizar los puntos de los jugadores
    localStorage.setItem('player1Score', player1Score);
    localStorage.setItem('player2Score', player2Score);

    // ...

    // Establecer el límite de tiempo
    if (raceTimeRemaining <= 0) {
      raceFinished = true;
    } else {
      raceTimeRemaining = raceTimeLimit - (time - raceStartTime);
    }

    // Controlar el uso del turbo especial
    if (player1TurboTime > 0) {
      player1TurboTime -= delta;
    } else {
      player1Turbo = false;
    }
  }
}

// Menú principal
var mainMenu = new Phaser.Class({
  Extends: Phaser.Scene,

  initialize: function () {
    Phaser.Scene.call(this, {key: 'mainMenu'});
  },

  preload: function () {
    this.load.image('title', 'assets/title.jpeg');
    this.load.image('playButton', 'assets/playButton.jpeg');
  },

  create: function () {
    this.add.image(400, 300, 'title');

    var playButton = this.add.image(400, 400, 'playButton');
    playButton.setInteractive();
    playButton.on('pointerdown', function () {
      this.scene.start('game');
    }, this);
  }
});

// Escena del juego
var gameScene = new Phaser.Class({
  Extends: Phaser.Scene,

  initialize: function () {
    Phaser.Scene.call(this, {key: 'game'});
  },

  preload: function () {
    // Cargar las imágenes de los coches y los obstáculos
    this.load.image('car1', 'assets/car1.png');
    this.load.image('car2', 'assets/car2.png');
    this.load.image('obstacle', 'assets/obstacle.png');

    // Cargar la imagen de fondo
    this.load.image('background', 'assets/background.png');

    // Cargar la fuente de texto
    this.load.bitmapFont('font', 'assets/font.png', 'assets/font.fnt');
  },

  create: function () {
    // Crear el fondo
    this.add.image(400, 300, 'background');

    // Crear los coches
    player1 = this.physics.add.sprite(100, 300, 'car1');
    player2 = this.physics.add.sprite(100, 400, 'car2');

    // Configurar los coches
    player1.setData('health', 100);
    player1.setData('speedMultiplier', 1);
    player1.setData('damageMultiplier', 1);

    player2.setData('health', 100);
    player2.setData('speedMultiplier', 1);
    player2.setData('damageMultiplier', 1);

    // Crear los obstáculos
    obstacles = this.physics.add.group();

    for (var i = 0; i < 5; i++) {
      var obstacle = obstacles.create(Phaser.Math.Between(200, 600), Phaser.Math.Between(100, 500), 'obstacle');
      obstacle.setCollideWorldBounds(true);
      obstacle.setBounce(1);
      obstacle.setVelocity(Phaser.Math.Between(-200, 200), Phaser.Math.Between(-200, 200));
    }

    // Crear las barras de salud de los coches
    player1HealthBar = this.add.graphics();
    player2HealthBar = this.add.graphics();

    // Crear el texto del tiempo restante de la carrera
    timeText = this.add.bitmapText(10, 10, 'font', 'Time: 60', 24);

    // Iniciar la carrera
    raceStartTime = this.time.now;
    raceTimeLimit = 60000;
    raceTimeRemaining = raceTimeLimit;
    raceFinished = false;
    player1Finished = false;
    player2Finished = false;
    player1Score = 0;
    player2Score = 0;
    raceRanking = [];
    rankingShown = false;

    // Configurar las teclas de control
    cursors = this.input.keyboard.createCursorKeys();
  },

  update: function (time, delta) {
    // Lógica del juego
    if (!raceFinished) {
      // Actualizar el tiempo restante de la carrera
      raceTimeRemaining = raceTimeLimit - (time - raceStartTime);

      // Actualizar la velocidad de los coches
      if (cursors.turbo.isDown) {
        player1.setData('speedMultiplier', 2);
        player1Turbo = true;
      } else {
        player1.setData('speedMultiplier', 1);
        player1Turbo = false;
      }

      // Mover los coches
      if (cursors.up.isDown) {
        player1.setVelocityY(-200 * player1.getData('speedMultiplier'));
      } else if (cursors.down.isDown) {
        player1.setVelocityY(200 * player1.getData('speedMultiplier'));
      } else {
        player1.setVelocityY(0);
      }

      // Detección de colisiones
      this.physics.add.collider(player1, player2, function () {
        if (player1Turbo) {
          player2.setData('health', player2.getData('health') - 20 * player1.getData('damageMultiplier'));
        } else {
          player2.setData('health', player2.getData('health') - 10 * player1.getData('damageMultiplier'));
        }

        if (player2.getData('health') <= 0) {
          player2.disableBody(true, true);
          player1Score += 1;
        }
      });

      this.physics.add.collider(player1, obstacles, function () {
        player1.setData('health', player1.getData('health') - 10);

        if (player1.getData('health') <= 0) {
          player1.disableBody(true, true);
          player2Score += 1;
        }
      });

      // Actualizar la barra de salud de los coches
      player1HealthBar.clear();
      player1HealthBar.fillStyle(0xff0000, 1);
      player1HealthBar.fillRect(player1.x - 25, player1.y - 30, player1.getData('health'), 5);

      player2HealthBar.clear();
      player2HealthBar.fillStyle(0xff0000, 1);
      player2HealthBar.fillRect(player2.x - 25, player2.y - 30, player2.getData('health'), 5);

      // Actualizar el tiempo restante de la carrera en la pantalla
      timeText.setText('Time: ' + Math.floor(raceTimeRemaining / 1000));

      // Finalizar la carrera si se acaba el tiempo o si un coche llega a la meta
      if (raceTimeRemaining <= 0 || (player1.x >= 750 && !player1Finished)) {
        player1Finished = true;
        player1LastPlaceTime = time;
        raceRanking.push(player1);
      }

      if (raceTimeRemaining <= 0 || (player2.x >= 750 && !player2Finished)) {
        player2Finished = true;
        player2LastPlaceTime = time;
        raceRanking.push(player2);
      }

      if (player1Finished && player2Finished) {
        raceFinished = true;
      }
    } else {
      // Mostrar el ranking de los coches
      if (!rankingShown) {
        rankingShown = true;

        // Ordenar los coches por tiempo
        raceRanking.sort(function (a, b) {
          return aLastPlaceTime - bLastPlaceTime;
        });

        // Mostrar el ranking en la pantalla
        var rankingText = this.add.text(400, 300, 'Ranking:', {fontSize: '32px', fill: '#fff'});
        rankingText.setOrigin(0.5);

        for (var i = 0; i < raceRanking.length; i++) {
          var carText = this.add.text(400, 350 + i * 50, (i + 1) + '. Car ' + (raceRanking[i] == player1 ? '1' : '2'), {fontSize: '24px', fill: '#fff'});
          carText.setOrigin(0.5);
        }

        // Guardar la puntuación de los jugadores
        localStorage.setItem('player1Score', player1Score);
        localStorage.setItem('player2Score', player2Score);
      }
    }
  }
});
