<commit_before>var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var width = 10;
var height = 20;
var maxWidth = canvas.width / 10;
var maxHeight = canvas.height / 20;

var enemies = [];
var score = 0;
var scoreSpan = document.getElementById('score');
var highScore = 0;
var highScoreSpan = document.getElementById('highScore');

var player = {
  x: maxWidth / 2,
  y: maxHeight / 2,
  width: 10,
  height: 20,
  color: 'black',
  clear: function () {
    context.clearRect(this.x * this.width, this.y * this.height, this.width, this.height);
  },
  draw: function () {
    checkCollision();
    context.beginPath();
    context.rect(this.x * this.width, this.y * this.height, this.width, this.height);
    context.fillStyle = this.color;
    context.fill();
  },
  blink: function () {
    this.clear();
    this.color = (this.color == 'black') ? 'white' : 'black';
    this.draw();
  },
  moveUp: function () {
    if (this.y - 1 < 0) return;
    this.clear();
    this.y -= 1;
    this.draw();
  },
  moveDown: function () {
    if (this.y + 1 >= maxHeight) return;
    this.clear();
    this.y += 1;
    this.draw();
  },
  moveLeft: function () {
    if (this.x - 1 < 0) return;
    this.clear();
    this.x -= 1;
    this.draw();
  },
  moveRight: function () {
    if (this.x + 1 >= maxWidth) return;
    this.clear();
    this.x += 1;
    this.draw();
  }
};

window.addEventListener('keydown', function (e) {
  if (e.keyCode == 72) { // h
    player.moveLeft();
  } else if (e.keyCode == 74) { // j
    player.moveDown();
  } else if (e.keyCode == 75) { // k
    player.moveUp();
  } else if (e.keyCode == 76) { // l
    player.moveRight();
  }
}, true);

window.setInterval(function () {
  enemies.push({
    x: Math.floor(Math.random() * maxWidth),
    y: 0,
    width: 10,
    height: 20,
    color: 'red',
    clear: function () {
      context.clearRect(this.x * this.width, this.y * this.height, this.width, this.height);
    },
    draw: function () {
      context.beginPath();
      context.rect(this.x * this.width, this.y * this.height, this.width, this.height);
      context.fillStyle = this.color;
      context.fill();
    },
    moveDown: function () {
      console.log(this);
      if (this.y + 1 >= maxHeight) return false;
      this.clear();
      this.y += 1;
      this.draw();
    },
  });
}, 50);

window.setInterval(function () {
  for (var i = 0; i < enemies.length; i++) {
    var remove = enemies[i].moveDown();

    if (remove === false) {
      enemies[i].clear();
      enemies.splice(i, 1);
      score++;
      highScore = Math.max(score, highScore);
    }
  }

  scoreSpan.innerHTML = score;
  highScoreSpan.innerHTML = highScore;
  player.blink();
}, 500);

function checkCollision() {
  enemies.forEach(function (e) {
    if (e.x == player.x && e.y == player.y) {
      score = 0;
      enemies = [];
      context.clearRect(0, 0, canvas.width, canvas.height);
    }
  });
};<commit_msg>added purple horizontally dudes and a nugget<commit_after>var highScoreSpan = document.getElementById('highScore');
var scoreSpan = document.getElementById('score');
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var height = 20;
var width = 10;
var maxHeight = canvas.height / height;
var maxWidth = canvas.width / width;

var enemies = [];
var score = 0;
var highScore = 0;

var nugget = {
  x: 0,
  y: 0,
  width: width,
  height: height,
  color: 'yellow',
  clear: function () {
    context.clearRect(this.x * this.width, this.y * this.height, this.width, this.height);
  },
  draw: function () {
    context.beginPath();
    context.rect(this.x * this.width, this.y * this.height, this.width, this.height);
    context.fillStyle = this.color;
    context.fill();
  },
  move: function () {
    this.clear();
    this.x = Math.floor(Math.random() * maxWidth),
    this.y = Math.floor(Math.random() * maxHeight),
    this.draw();
  }
};
nugget.move();

var player = {
  x: maxWidth / 2,
  y: maxHeight / 2,
  width: width,
  height: height,
  color: 'white',
  clear: function () {
    context.clearRect(this.x * this.width, this.y * this.height, this.width, this.height);
  },
  draw: function () {
    checkCollision();
    context.beginPath();
    context.rect(this.x * this.width, this.y * this.height, this.width, this.height);
    context.fillStyle = this.color;
    context.fill();
  },
  blink: function () {
    this.clear();
    this.color = (this.color == 'white') ? 'black' : 'white';
    this.draw();
  },
  moveUp: function () {
    if (this.y - 1 < 0) return;
    this.clear();
    this.y -= 1;
    this.draw();
  },
  moveDown: function () {
    if (this.y + 1 >= maxHeight) return;
    this.clear();
    this.y += 1;
    this.draw();
  },
  moveLeft: function () {
    if (this.x - 1 < 0) return;
    this.clear();
    this.x -= 1;
    this.draw();
  },
  moveRight: function () {
    if (this.x + 1 >= maxWidth) return;
    this.clear();
    this.x += 1;
    this.draw();
  }
};
player.draw();

window.addEventListener('keydown', function (e) {
  if (e.keyCode == 72) { // h
    player.moveLeft();
  } else if (e.keyCode == 74) { // j
    player.moveDown();
  } else if (e.keyCode == 75) { // k
    player.moveUp();
  } else if (e.keyCode == 76) { // l
    player.moveRight();
  }
}, true);

window.setInterval(function () {
  var enemy = {
    x: Math.floor(Math.random() * maxWidth),
    y: 0,
    width: width,
    height: height,
    color: 'red',
    clear: function () {
      context.clearRect(this.x * this.width, this.y * this.height, this.width, this.height);
    },
    draw: function () {
      context.beginPath();
      context.rect(this.x * this.width, this.y * this.height, this.width, this.height);
      context.fillStyle = this.color;
      context.fill();
    },
    move: function () {
      if (this.y + 1 >= maxHeight) return false;
      this.y += 1;
      this.draw();
    },
  };
  enemies.push(enemy);
  enemy.draw();
}, 100);

window.setInterval(function () {
  var enemy = {
    x: 0,
    y: Math.floor(Math.random() * maxHeight),
    width: width,
    height: height,
    color: 'purple',
    clear: function () {
      context.clearRect(this.x * this.width, this.y * this.height, this.width, this.height);
    },
    draw: function () {
      context.beginPath();
      context.rect(this.x * this.width, this.y * this.height, this.width, this.height);
      context.fillStyle = this.color;
      context.fill();
    },
    move: function () {
      if (this.x + 1 >= maxWidth) return false;
      this.x += 1;
      this.draw();
    },
  };
  enemies.push(enemy);
  enemy.draw();
}, 200);

window.setInterval(function () {
  enemies.forEach(function (enemy) {
    enemy.clear();
  });

  nugget.draw();

  for (var i = 0; i < enemies.length; i++) {
    var keep = enemies[i].move();

    if (keep === false) {
      enemies[i].clear();
      enemies[i] = null;
      enemies.splice(i, 1);
      score++;
      highScore = Math.max(score, highScore);
    }
  }

  checkCollision();

  scoreSpan.innerHTML = score;
  highScoreSpan.innerHTML = highScore;
}, 500);

function checkCollision() {
  if (nugget.x == player.x && nugget.y == player.y) {
    score += 500;
    highScore = Math.max(score, highScore);
    nugget.move();
  }

  for (var i = 0; i < enemies.length; i++) {
    var e = enemies[i];

    if (e.x == player.x && e.y == player.y) {
      score = 0;
      enemies = [];
      context.clearRect(0, 0, canvas.width, canvas.height);
      player.draw();
      break;
    }
  }
}
{'fraction_non_alphanumeric': 0.18024102767845318, 'fraction_numerical': 0.013905442987683751, 'mean_word_length': 2.5589066918001886, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2660693', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2633, 'n_words': 604}