import { Physics } from 'phaser';
import { SUPER_JUMP_VELOCITY } from '../config/game.config.js';

export class Spring extends Physics.Arcade.Sprite {
  constructor(scene, x, y) {
    super(scene, x, y, 'spring');
    scene.add.existing(this);
    scene.physics.add.existing(this, true);

    this.setScale(1);
    this.body.setSize(20, 32);
    this.consumed = false;
  }

  onPlayerTouch(player) {
    if (this.consumed) return false;
    this.consumed = true;
    player.jump(SUPER_JUMP_VELOCITY, true);
    this.scene.tweens.add({
      targets: this,
      scaleY: 1.6,
      duration: 80,
      yoyo: true,
      ease: 'Quad.easeOut',
      onComplete: () => this.destroy(),
    });
    return true;
  }
}
