<commit_before>var spaceship;
var blockSize;
var bullets;
var allowedBullets = 1;
var invasionWave;
var world;
var invaderSpeed = 2;

function setup() {
  createCanvas(400, 400);
  blockSize = 5;

  spaceship = new Spaceship();
  bullets = [];
  invasionWave = new InvasionWave(5,6);
  world = new World(4);
  // frameRate(10);
}

function draw() {
  background(0);
  spaceship.draw();

  let bulletHit;
  for (var i = 0; i < bullets.length; i++) {
    bullets[i].draw();
    bullets[i].tick();

    if (bullets[i].y < 0){
      bullets.splice(i, 1);
      continue;
    }

    bulletHit = world.collisionTest(bullets[i]);
    if (bulletHit) {
      bullets.splice(i, 1);
      continue;
    }

    bulletHit = invasionWave.collisionTest(bullets[i]);
    if (bulletHit) {
      bullets.splice(i, 1);
    }
  }

  world.draw();

  invasionWave.draw();
  invasionWave.tick();
}

function keyPressed() {
  if (keyCode === RIGHT_ARROW) {
    spaceship.move(RIGHT_ARROW);
  } else if (keyCode === LEFT_ARROW) {
    spaceship.move(LEFT_ARROW);
  } else if (keyCode === UP_ARROW) {
    spaceship.fireBullet();
  }
}

function xyInRect(x, y, rectX, rectY, rectWidth, rectHeight){
  return (rectX <= x && x <= (rectX + rectWidth)) &&
         (rectY <= y && y <= (rectY + rectHeight));
}

class Spaceship { 
  constructor(){
    this.x = width/2;
    this.y = height - 40;
  }

  draw(){
    rectMode(CENTER);
    fill(30,200,230);
    rect(this.x, this.y, 30, 10);
  }

  move(direction){
    if (keyCode === RIGHT_ARROW) {
      this.x += 10;
    } else if (keyCode === LEFT_ARROW) {
      this.x -= 10;
    }  
  }

  fireBullet(){
    if (bullets.length >= allowedBullets){
      return;
    }
    bullets.push(new Bullet(this.x, this.y - 10));
  }
}

class Bullet {
  constructor(x, y){
    this.x = x;
    this.y = y;
  }

  draw(){
    rectMode(CENTER);
    fill(200,200,30);
    rect(this.x, this.y, 5, 10);
  }

  tick(){
    this.y -= 10;
  }
}

class World {
  constructor(numBases){
    this.bases = [];<commit_msg>p5js/space-invaders - Add difficult setting for bullet speed<commit_after>var spaceship;
var blockSize;
var bullets;
var invasionWave;
var world;

// Difficulty Settings
var allowedBullets = 1;
var invaderSpeed = 2;
var bulletSpeed = 5;

function setup() {
  createCanvas(400, 400);
  blockSize = 5;

  spaceship = new Spaceship();
  bullets = [];
  invasionWave = new InvasionWave(5,6);
  world = new World(4);
  // frameRate(10);
}

function draw() {
  background(0);
  spaceship.draw();

  let bulletHit;
  for (var i = 0; i < bullets.length; i++) {
    bullets[i].draw();
    bullets[i].tick();

    if (bullets[i].y < 0){
      bullets.splice(i, 1);
      continue;
    }

    bulletHit = world.collisionTest(bullets[i]);
    if (bulletHit) {
      bullets.splice(i, 1);
      continue;
    }

    bulletHit = invasionWave.collisionTest(bullets[i]);
    if (bulletHit) {
      bullets.splice(i, 1);
    }
  }

  world.draw();

  invasionWave.draw();
  invasionWave.tick();
}

function keyPressed() {
  if (keyCode === RIGHT_ARROW) {
    spaceship.move(RIGHT_ARROW);
  } else if (keyCode === LEFT_ARROW) {
    spaceship.move(LEFT_ARROW);
  } else if (keyCode === UP_ARROW) {
    spaceship.fireBullet();
  }
}

function xyInRect(x, y, rectX, rectY, rectWidth, rectHeight){
  return (rectX <= x && x <= (rectX + rectWidth)) &&
         (rectY <= y && y <= (rectY + rectHeight));
}

class Spaceship { 
  constructor(){
    this.x = width/2;
    this.y = height - 40;
  }

  draw(){
    rectMode(CENTER);
    fill(30,200,230);
    rect(this.x, this.y, 30, 10);
  }

  move(direction){
    if (keyCode === RIGHT_ARROW) {
      this.x += 10;
    } else if (keyCode === LEFT_ARROW) {
      this.x -= 10;
    }  
  }

  fireBullet(){
    if (bullets.length >= allowedBullets){
      return;
    }
    bullets.push(new Bullet(this.x, this.y - 10));
  }
}

class Bullet {
  constructor(x, y){
    this.x = x;
    this.y = y;
  }

  draw(){
    rectMode(CENTER);
    fill(200,200,30);
    rect(this.x, this.y, 5, 10);
  }

  tick(){
    this.y -= bulletSpeed;
  }
}

class World {
  constructor(numBases){
    this.bases = [];
{'fraction_non_alphanumeric': 0.16654580613971476, 'fraction_numerical': 0.02610587382160986, 'mean_word_length': 2.691347011596789, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, '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': '1458402', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1561, 'n_words': 335}