<commit_before>/*eslint-disable*/
/* global global Phaser, keys, scale, w2, h2, groupPowers, borders, paused,
  totalTime, bmd, colisionMargin, gameOver, tempLabel, tempLabelText,
  pauseSprite, localStorage, mute, killSound, collectSound, colorHexDark */
/*eslint-enable*/
var OldPlayer = function (x, y, mode, game) {
  this.game = game
  this.mode = mode
  this.sprite = game.add.sprite(x, y, 'old_player')
  this.game.physics.enable(this.sprite, Phaser.Physics.ARCADE)

  this.direction = 1
  this.distance = 0
  this.maxDistance = 40
  this.angle = 0
  this.speed = 3

  this.x = x
  this.y = y
  this.key = keys[0]
  this.killTrail = false
  this.dead = false
  this.ready = false
  this.growth = 60
  this.lastTrailLength = 0
  this.keyText = null
  this.paused = false
  this.textTween = null
  this.trailArray = []
  this.showKeyTime = 0
  this.showOneKey = true
  this.touch = null
  this.orientation = null
  this.color = Phaser.Color.hexToColor('#FFFFFF')
}

OldPlayer.prototype = {
  create: function () {
    this.orientation = Math.abs(window.orientation) - 90 === 0 ? 'landscape' : 'portrait'
    this.sprite.anchor.setTo(0.5, 0.5)

    this.trail = this.game.make.sprite(0, 0, 'old_trail')
    this.trail.anchor.set(0.5)

    this.sprite.scale.set(scale)
    // this.sprite.body.setSize(20,20,0,0)
    this.lastTrailLength = this.growth

    // this.sprite.body.angularVelocity = this.direction*200*this.angularVelocity*this.speed*scale
    this.game.input.onDown.add(this.keyPressed, this)

    this.showKey()

    this.input = this.game.input.keyboard.addKey(this.key).onDown.add(this.keyPressed, this)
  },

  update: function () {
    if (!this.paused && paused) {
      this.paused = true
      this.pause()
    } else if (this.paused && !paused) {
      this.paused = false
      this.unpause()
    }

    if (this.showKeyTime <= totalTime && !this.dead && !paused) {
      this.showKey()
    }

    if (!this.paused) {
      this.sprite.angle = 90 * this.angle

      switch (this.angle) {
        case 0:
          this.sprite.x += this.speed
          break
        case 1:
          this.sprite.y += this.speed
          break
        case 2:
          this.sprite.x -= this.speed
          break
        case 3:
          this.sprite.y -= this.speed
          break
      }

      if (this.distance >= this.maxDistance) {
        this.distance = 0
        this.angle = this.angle + this.direction
        if (this.angle > 3) {
          this.angle = 0
        } else if (this.angle < 0) {
          this.angle = 3
        }
      } else {
        this.distance++
      }

      if (!this.sprite.alive) {
        this.kill()
      }

      var xx = Math.cos(this.sprite.rotation) * 18 * scale + this.sprite.x
      var yy = Math.sin(this.sprite.rotation) * 18 * scale + this.sprite.y

      if (!this.dead) {
        // Create trail
        trailPiece = {'x': this.sprite.x, 'y': this.sprite.y, 'n': 1}
        this.trailArray.push(trailPiece)
        bmd.draw(this.trail, this.sprite.x, this.sprite.y)
        // collision detection
        var collSize = 12 * scale
        for (var j = 0; j < this.trailArray.length; j++) {
          var curTrail = this.trailArray[j]
          if (curTrail && curTrail.x - collSize < xx && curTrail.x + collSize > xx &&
            curTrail.y - collSize < yy && curTrail.y + collSize > yy) {
            this.kill()
          }
        }
      }
      this.game.physics.arcade.overlap(this.sprite, groupPowers, this.collect, null, this)

      var trailPiece = null
      var ctx = bmd.context

      // erase trail from front
      if (this.dead && this.trailArray[0]) {
        trailPiece = this.trailArray.pop()
        ctx.clearRect(trailPiece.x - 9 * scale, trailPiece.y - 9 * scale, 18 * scale, 18 * scale)

        if (this.trailArray.length > 0) {
          trailPiece = this.trailArray[this.trailArray.length - 1]
          bmd.draw(this.trail, trailPiece.x, trailPiece.y)
        }
      }

      if (!this.killTrail && (this.trailArray.length >= (this.lastTrailLength + this.growth))) {
        this.killTrail = true
        this.lastTrailLength = this.trailArray.length
      }

      // erase trail from behind
      if (this.killTrail && this.trailArray[0]) {
        var nRemove = 1
        if (this.shrink) {
          if (this.trailArray.length <= this.shrinkSize) {
            this.shrink = false
          } else {
            nRemove = 4
          }
        }
        for (var i = 0; i < nRemove && this.trailArray.length > 0; i++) {
          trailPiece = this.trailArray.shift()
          ctx.clearRect(trailPiece.x - 9 * scale, trailPiece.y - 9 * scale, 18 * scale, 18 * scale)
        }

        if (this.trailArray.length > 0) {
          bmd.draw(this.trail, this.trailArray[0].x, this.trailArray[0].y)
        }
      }

      // Border's collisions
      if ((xx + colisionMargin * scale) <= borders[0]) {
        this.sprite.x = borders[1] - Math.cos(this.sprite.rotation) * 30 * scale
      } else if ((xx - colisionMargin * scale) >= borders[1]) {
        this.sprite.x = borders[0] - Math.cos(this.sprite.rotation) * 30 * scale
      }

      if ((yy + colisionMargin * scale) <= borders[2]) {
        this.sprite.y = borders[3] - Math.sin(this.sprite.rotation) * 30 * scale
      } else if ((yy - colisionMargin * scale) >= borders[3]) {
        this.sprite.y = borders[2] - Math.sin(this.sprite.rotation) * 30 * scale
      }
    }
  },

  keyPressed: function () {
    this.ready = true
    this.showOneKey = true
    this.showKeyTime = 2 + totalTime
    if (!this.dead) {
      if (this.direction === 1 && !gameOver && !paused) {
        this.direction = -1
        this.sprite.height *= -1
        this.distance = this.maxDistance
      } else if (!gameOver && !paused) {
        this.sprite.height *= -1
        this.direction = 1
        this.distance = this.maxDistance
      }
      if (this.keyText.alpha === 1) {
        this.textTween = this.game.add.tween(this.keyText).to({ alpha: 0 }, 2000, Phaser.Easing.Linear.None, true)

        this.game.add.tween(tempLabel).to({ alpha: 0 }, 2000, Phaser.Easing.Linear.None, true)
        this.game.add.tween(tempLabelText).to({ alpha: 0 }, 2000, Phaser.Easing.Linear.None, true)
      }
    }
  },

  click: function () {
    var x1 = w2 - 81<commit_msg>close #71<commit_after>/*eslint-disable*/
/* global global Phaser, keys, scale, w2, h2, groupPowers, borders, paused,
  totalTime, bmd, colisionMargin, gameOver, tempLabel, tempLabelText,
  pauseSprite, localStorage, mute, killSound, collectSound, colorHexDark */
/*eslint-enable*/
var OldPlayer = function (x, y, mode, game) {
  this.game = game
  this.mode = mode
  this.sprite = game.add.sprite(x, y, 'old_player')
  this.game.physics.enable(this.sprite, Phaser.Physics.ARCADE)

  this.direction = 1
  this.distance = 0
  this.maxDistance = 40
  this.angle = 0
  this.speed = 3

  this.x = x
  this.y = y
  this.key = keys[0]
  this.killTrail = false
  this.dead = false
  this.ready = false
  this.growth = 60
  this.lastTrailLength = 0
  this.keyText = null
  this.paused = false
  this.textTween = null
  this.trailArray = []
  this.showKeyTime = 0
  this.showOneKey = true
  this.touch = null
  this.orientation = null
  this.color = Phaser.Color.hexToColor('#FFFFFF')
}

OldPlayer.prototype = {
  create: function () {
    this.orientation = Math.abs(window.orientation) - 90 === 0 ? 'landscape' : 'portrait'
    this.sprite.anchor.setTo(0.5, 0.5)

    this.trail = this.game.make.sprite(0, 0, 'old_trail')
    this.trail.anchor.set(0.5)

    this.sprite.scale.set(scale)
    // this.sprite.body.setSize(20,20,0,0)
    this.lastTrailLength = this.growth

    // this.sprite.body.angularVelocity = this.direction*200*this.angularVelocity*this.speed*scale
    this.game.input.onDown.add(this.keyPressed, this)

    this.showKey()

    this.input = this.game.input.keyboard.addKey(this.key).onDown.add(this.keyPressed, this)
  },

  update: function () {
    if (!this.paused && paused) {
      this.paused = true
      this.pause()
    } else if (this.paused && !paused) {
      this.paused = false
      this.unpause()
    }

    if (this.showKeyTime <= totalTime && !this.dead && !paused) {
      this.showKey()
    }

    if (!this.paused) {
      this.sprite.angle = 90 * this.angle

      switch (this.angle) {
        case 0:
          this.sprite.x += this.speed
          break
        case 1:
          this.sprite.y += this.speed
          break
        case 2:
          this.sprite.x -= this.speed
          break
        case 3:
          this.sprite.y -= this.speed
          break
      }

      if (this.distance >= this.maxDistance) {
        this.distance = 0
        this.angle = this.angle + this.direction
        if (this.angle > 3) {
          this.angle = 0
        } else if (this.angle < 0) {
          this.angle = 3
        }
      } else {
        this.distance++
      }

      if (!this.sprite.alive) {
        this.kill()
      }

      var xx = Math.cos(this.sprite.rotation) * 18 * scale + this.sprite.x
      var yy = Math.sin(this.sprite.rotation) * 18 * scale + this.sprite.y

      if (!this.dead) {
        // Create trail
        trailPiece = {'x': this.sprite.x, 'y': this.sprite.y, 'n': 1}
        this.trailArray.push(trailPiece)
        bmd.draw(this.trail, this.sprite.x, this.sprite.y)
        // collision detection
        var collSize = 12 * scale
        for (var j = 0; j < this.trailArray.length; j++) {
          var curTrail = this.trailArray[j]
          if (curTrail && curTrail.x - collSize < xx && curTrail.x + collSize > xx &&
            curTrail.y - collSize < yy && curTrail.y + collSize > yy) {
            this.kill()
          }
        }
      }
      this.game.physics.arcade.overlap(this.sprite, groupPowers, this.collect, null, this)

      var trailPiece = null
      var ctx = bmd.context

      // erase trail from front
      if (this.dead && this.trailArray[0]) {
        trailPiece = this.trailArray.pop()
        ctx.clearRect(trailPiece.x - 9 * scale, trailPiece.y - 9 * scale, 18 * scale, 18 * scale)

        if (this.trailArray.length > 0) {
          trailPiece = this.trailArray[this.trailArray.length - 1]
          bmd.draw(this.trail, trailPiece.x, trailPiece.y)
        }
      }

      if (!this.killTrail && (this.trailArray.length >= (this.lastTrailLength + this.growth))) {
        this.killTrail = true
        this.lastTrailLength = this.trailArray.length
      }

      // erase trail from behind
      if (this.killTrail && this.trailArray[0]) {
        var nRemove = 1
        if (this.shrink) {
          if (this.trailArray.length <= this.shrinkSize) {
            this.shrink = false
          } else {
            nRemove = 4
          }
        }
        for (var i = 0; i < nRemove && this.trailArray.length > 0; i++) {
          trailPiece = this.trailArray.shift()
          ctx.clearRect(trailPiece.x - 9 * scale, trailPiece.y - 9 * scale, 18 * scale, 18 * scale)
        }

        if (this.trailArray.length > 0) {
          bmd.draw(this.trail, this.trailArray[0].x, this.trailArray[0].y)
        }
      }

      // Border's collisions
      if ((xx + colisionMargin * scale) <= borders[0]) {
        this.sprite.x = borders[1] - Math.cos(this.sprite.rotation) * 30 * scale
      } else if ((xx - colisionMargin * scale) >= borders[1]) {
        this.sprite.x = borders[0] - Math.cos(this.sprite.rotation) * 30 * scale
      }

      if ((yy + colisionMargin * scale) <= borders[2]) {
        this.sprite.y = borders[3] - Math.sin(this.sprite.rotation) * 30 * scale
      } else if ((yy - colisionMargin * scale) >= borders[3]) {
        this.sprite.y = borders[2] - Math.sin(this.sprite.rotation) * 30 * scale
      }
    }
    this.sprite.bringToTop()
  },

  keyPressed: function () {
    this.ready = true
    this.showOneKey = true
    this.showKeyTime = 2 + totalTime
    if (!this.dead) {
      if (this.direction === 1 && !gameOver && !paused) {
        this.direction = -1
        this.sprite.height *= -1
        this.distance = this.maxDistance
      } else if (!gameOver && !paused) {
        this.sprite.height *= -1
        this.direction = 1
        this.distance = this.maxDistance
      }
      if (this.keyText.alpha === 1) {
        this.textTween = this.game.add.tween(this.keyText).to({ alpha: 0 }, 2000, Phaser.Easing.Linear.None, true)

        this.game.add.tween(tempLabel).to({ alpha: 0 }, 2000, Phaser.Easing.Linear.None, true)
        this.game.add.tween(tempLabelText).to({ alpha: 0 }, 2000, Phaser.Easing.Linear.None, true)
      }
    }
  },

  click: function () {
    var x1 = w2 - 81
{'fraction_non_alphanumeric': 0.14077708316847354, 'fraction_numerical': 0.018675318509139827, 'mean_word_length': 2.0756875152105136, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '3918341', 'n_tokens_mistral': 4616, 'n_tokens_neox': 4353, 'n_words': 883}