Automatic Variable Change?

Thank you soo much for the quick reply!

I am glad to say that it mostly works

Now, the same will happen, but randomly.

EDIT: I just realised that the same thing does not happen, but the entire game seems to be resetting.

I don't think that it is because of:

if (index < 99){
    index++;
    }
    else{
      index = 0;
      }

Because I added a debug message to when the else statement happens, and it does not print.

Here is my updated code:

#include <LedControl.h>

#define SpeakerPin 48

//defining global variables
int pos = 3;

int bulletXs[100] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
int bulletYs[100] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int index = 0;
int amountOfBullets = 0;




LedControl lc1 = LedControl(12, 10, 11, 1);

//telling C++ that we are going to make these functions
void drawPlayer(int midX, int midY);
void ComputeInput();
void handleBullets();
void drawBullets();



void setup() {
  //wake up the MAX72XX from power-saving mode
  lc1.shutdown(0, false);
  //set a medium brightness for the Leds
  lc1.setIntensity(0, 8);

  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(2, INPUT_PULLUP);
  pinMode(SpeakerPin, OUTPUT);

  Serial.begin(9600);


}

void loop() {
  lc1.clearDisplay(0);



  //lc1.setColumn(0,0,255);

  Serial.println(pos);


  ComputeInput();
  handleBullets();
  drawBullets();

  drawPlayer(pos, 7);
  Serial.println("Drawing the player");

  delay(200);

}

void drawPlayer(int midX, int midY) {
  lc1.setLed(0, midX + 1, midY, true);
  lc1.setLed(0, midX, midY, true);
  lc1.setLed(0, midX - 1, midY, true);
  lc1.setLed(0, midX, midY - 1, true);
}

void ComputeInput() {
  if (analogRead(A2) >= 300) {
    pos++;
    Serial.println("Changing pos because the player is moving right");
    tone(8, 400, 200);
  }

  else if (analogRead(A2) == 0) {
    pos--;
    Serial.println("Changing pos because the player is moving left");
    tone(8, 200, 200);
  }
  if (digitalRead(2) == 0) {
    Serial.println("Creating A bullet!");

    bulletXs[index] = pos;
    bulletYs[index] = 6;

    if (index < 99){
    index++;
    }
    else{
      index = 0;
      }
    amountOfBullets++;

    int startTime = millis();
    int startPitch = 1000;
    int tempPos = pos;
    Serial.print("Creating a tempPos:");
    Serial.println(tempPos);

    while (millis() - startTime <= 100) {
      drawPlayer(pos, 7);
      drawBullets();

      tone(8, startPitch, 10);

      startPitch = startPitch - 100;

      delay(10);
    }

    pos = tempPos;
    Serial.println("Setting Pos to tempPos");



  }
}

void handleBullets() {

  if (amountOfBullets == 10) {
    for (int i = 0; i <= 100; i++) {
      bulletXs[i] = -1;
      bulletYs[i] = 0;

    }

  }
  for (int i = 0; i < 100; i++) {
    if (bulletYs[i] != 0) {
      bulletYs[i]--;
      tone(8, 1000, 50);

      Serial.println(bulletYs[i]);

      if (bulletYs[i] == 0 && bulletXs[i] != 0) {
        Serial.println("BAD BULLET BOY!");
        bulletYs[i] = 0;
        bulletXs[i] = 0;

      }
    }




  }



}



void drawBullets() {
  for (int i = 0; i <= 100; i++) {
    if (bulletXs[i] != -1) {
      lc1.setLed(0, bulletXs[i], bulletYs[i], true);
    }

  }


}

and PS. I have 2 more issues. 1 where there is a sort of ghost bullet, that follows the player, and every time you shoot, it comes down by 1 pixel.

  1. is that the first bullet you shoot, does not despawn, instead it stays at 0, 0.

But thank you for all of the help!