<commit_before>const CollisionEngine = require('./helpers/collisionEngine')
const FireBlock = require('./fireBlock')

class Explosion {
  constructor(bombX, bombY, game) {
    this.bombX = bombX
    this.bombY = bombY
    this.width = 0
    this.height = 0
    this.game = game
    this.speed = 70
    this.collisions = new CollisionEngine()
  }

  get x() {
    let newX = parseInt(this.bombX)
    while(newX % 70 !== 0) {
      newX--
    }
    return newX
  }

  get y() {
    let newY = parseInt(this.bombY)
    while(newY % 70 !== 0) {
      newY--
    }
    return newY
  }

  fill() {
    this.game.context.fillRect(this.x, this.y, this.width, this.height)
  }

  clear() {
    this.game.context.clearRect(this.x, this.y, this.width, this.height)
  }

  fillPrimaryRect() {
    while(this.height < 70) {
      this.height += 35
      this.width += 35
    }
    const fb = new FireBlock(this.x, this.y, this.game)
    fb.draw('primarySprite')
    this.checkTopRect()
    this.checkLeftRect()
    this.checkRightRect()
    this.checkBottomRect()
    this.checkForDeadPlayers()
    setTimeout(this.clear.bind(this), 75)
  }

  checkForDeadPlayers() {
    const playerOne = this.game.firstPlayer
    const playerTwo = this.game.secondPlayer
    if (playerOne.alive === false)  {
      this.game.endGame('Player Two')
    } else if (playerTwo.alive === false) {
      this.game.endGame('Player One')
    }
  }

  checkForPlayers(x, y, width, height) {
    const playerOne = this.game.firstPlayer
    const playerTwo = this.game.secondPlayer
    if (((x <= playerOne.x) && (playerOne.x <= (x + width))) && ((y >= playerOne.y) && (playerOne.y <= (y + height)))) {
      playerOne.alive = false
    }
    if (((x <= playerTwo.x) && (playerTwo.x <= (x + width))) && ((y >= playerTwo.y) && (playerTwo.y <= (y + height)))) {
      playerTwo.alive = false
    }
  }

  checkTopRect() {
    if (this.y > 0) {
      const collidingBlocks = this.game.blocks.filter(this.collisions.blockAbove.bind(this))
      const breakableBlocks = this.game.breakableBlocks.filter(this.collisions.blockAbove.bind(this))
      /* removing blocks altogether instead of clearing the rectangle,
       * existing blocks are automatically rerendered on loop.
       * Game removes blocks in batches */
      this.game.removeBreakableBlocks(breakableBlocks)
      if (collidingBlocks.length === 0) {
        const fBlock = new FireBlock(this.x, this.y - this.speed, this.game)
        this.checkForPlayers(fBlock.x, fBlock.y, fBlock.width, fBlock.height)
        fBlock.draw('topSprite')
        setTimeout(fBlock.clear.bind(fBlock), 75)
      }
    }
    return this
  }

  checkLeftRect() {
    if (this.x > 0) {
      const collidingBlocks = this.game.blocks.filter(this.collisions.blockLeft.bind(this))
      const breakableBlocks = this.game.breakableBlocks.filter(this.collisions.blockLeft.bind(this))
      this.game.removeBreakableBlocks(breakableBlocks)
      if (collidingBlocks.length === 0) {
        const fBlock = new FireBlock(this.x - this.speed, this.y, this.game)<commit_msg>fix logic for explosions to kill players<commit_after>const CollisionEngine = require('./helpers/collisionEngine')
const FireBlock = require('./fireBlock')

class Explosion {
  constructor(bombX, bombY, game) {
    this.bombX = bombX
    this.bombY = bombY
    this.width = 0
    this.height = 0
    this.game = game
    this.speed = 70
    this.collisions = new CollisionEngine()
  }

  get x() {
    let newX = parseInt(this.bombX)
    while(newX % 70 !== 0) {
      newX--
    }
    return newX
  }

  get y() {
    let newY = parseInt(this.bombY)
    while(newY % 70 !== 0) {
      newY--
    }
    return newY
  }

  fill() {
    this.game.context.fillRect(this.x, this.y, this.width, this.height)
  }

  clear() {
    this.game.context.clearRect(this.x, this.y, this.width, this.height)
  }

  fillPrimaryRect() {
    while(this.height < 70) {
      this.height += 35
      this.width += 35
    }
    const fb = new FireBlock(this.x, this.y, this.game)
    fb.draw('primarySprite')
    this.checkTopRect()
    this.checkLeftRect()
    this.checkRightRect()
    this.checkBottomRect()
    this.checkForDeadPlayers()
    setTimeout(this.clear.bind(this), 75)
  }

  checkForDeadPlayers() {
    const playerOne = this.game.firstPlayer
    const playerTwo = this.game.secondPlayer
    if (playerOne.alive === false)  {
      this.game.endGame('Player Two')
    } else if (playerTwo.alive === false) {
      this.game.endGame('Player One')
    }
  }

  checkForPlayers(x, y, width, height) {
    const playerOne = this.game.firstPlayer
    const playerTwo = this.game.secondPlayer
    console.log(playerOne.x, playerOne.y, playerOne.width, playerOne.height, playerOne.alive)
    console.log(x, y, width, height)
    if (((x <= playerOne.x) && (playerOne.x <= (x + width))) && ((y <= playerOne.y) && (playerOne.y <= (y + height)))) {
      playerOne.alive = false
    }
    if (((x <= playerTwo.x) && (playerTwo.x <= (x + width))) && ((y <= playerTwo.y) && (playerTwo.y <= (y + height)))) {
      playerTwo.alive = false
    }
  }

  checkTopRect() {
    if (this.y > 0) {
      const collidingBlocks = this.game.blocks.filter(this.collisions.blockAbove.bind(this))
      const breakableBlocks = this.game.breakableBlocks.filter(this.collisions.blockAbove.bind(this))
      /* removing blocks altogether instead of clearing the rectangle,
       * existing blocks are automatically rerendered on loop.
       * Game removes blocks in batches */
      this.game.removeBreakableBlocks(breakableBlocks)
      if (collidingBlocks.length === 0) {
        const fBlock = new FireBlock(this.x, this.y - this.speed, this.game)
        this.checkForPlayers(fBlock.x, fBlock.y, fBlock.width, fBlock.height)
        fBlock.draw('topSprite')
        setTimeout(fBlock.clear.bind(fBlock), 75)
      }
    }
    return this
  }

  checkLeftRect() {
    if (this.x > 0) {
      const collidingBlocks = this.game.blocks.filter(this.collisions.blockLeft.bind(this))
      const breakableBlocks = this.game.breakableBlocks.filter(this.collisions.blockLeft.bind(this))
      this.game.removeBreakableBlocks(breakableBlocks)
      if (collidingBlocks.length === 0) {
        const fBlock = new FireBlock(this.x - this.speed, this.y, this.game)
{'fraction_non_alphanumeric': 0.13963104325699746, 'fraction_numerical': 0.007633587786259542, 'mean_word_length': 2.8277541083384055, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '300121', 'n_tokens_mistral': 2158, 'n_tokens_neox': 2077, 'n_words': 422}