import { Sprite } from './entity.js';
import { GRACE_BEAT, LANE_COLORS, getPixelsPerBeat } from './config.js';
import { sndCombobreak } from './main.js';

let PIXELS_PER_BEAT = getPixelsPerBeat();

export class Note extends Sprite {
  constructor(lane, beat) {
    super((width - 300)/ 2 + (lane * 75) + 4, 0)
    this.lane = lane;
    this.beat = beat;
    this.symbol = Symbol();

    this.pressed = false;
  }

  draw(curBeat) {
    strokeWeight(2);
    stroke(6);
    fill(LANE_COLORS[this.lane])
    rect(this.x, this.y, 68, 16) // 20

    let initialPos = ((height - 40) - 20 / 2)
    this.y = initialPos - (PIXELS_PER_BEAT * (this.beat - curBeat))

    if(this.beat + GRACE_BEAT < curBeat) {
      // remove note from array
      this.remove();
      if(!this.pressed) {
        // sndIncorrect.play();
        if(window.gameScreen.score.combo > 4) {
          sndCombobreak.play();
        }
        window.gameScreen.score.combo = 0;
      }
    }
  }

  remove() {
    window.gameScreen.notes.splice(window.gameScreen.notes.findIndex(n => n.symbol == this.symbol), 1);
  }
}