Sorry, but this code is really a bit hard to follow and highly inefficient. And I don’t have this device built to test any of this code. But in general since you are an admitted Cut and Paste guy, see if this will help.
Paste this subroutine (built from one section of your at the end of your Blaster Master code… (hint: subroutines allow you to run code inside of other code)
void shotUpdate(int shots, int maxAmmo) {
display.clearDisplay();
delay(50);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.setTextSize(1);
display.print("Shots Fired");
display.setCursor(100, 0);
display.setTextSize(1);
display.print(Shots);
display.setCursor(0, 12);
display.setTextSize(1);
display.print("E-11 Blaster");
display.setCursor(0, 24);
display.setTextSize(1);
display.print("Weapon Ammo");
display.setCursor(96, 15);
display.setTextSize(2);
if (shots < maxAmmo) {
display.print(maxAmmo-shots); //display number of shots remaining
display.drawRect(90, 12, 34, 20, 1);
} else {
display.print("EMPTY"); //show Empty
}
display.display();
delay(50);
}
You are checking buttonPushCounter to see which weapon is selected. Why not rename this something like weaponSelected instead so code is easier to read? Nobody cares that it is counting pushes the important bit is that it defines which weapon is selected. The same with buttonPushCounter2, etc. These are how many shots have been fired. Why not call them that instead like shotsFiredWeapon1, shotsFiredWeapon2, etc?
Anyway, when this is zero for example, weapon 1 is selected and inside that If statement you eventually play an mp3 sound effect and then do the fire LED lighting effects, and then eventually wait for the sound to finish with a delay(250). After this delay you need to add a call to the new shotUpdate subroutine like this (shown for weapon 1)…
shotUpdate(buttonPushCounter2, 21); //<- first number is the current shot count, second number is the maximum shots for this weapon
The if (buttonPushCounter2 <= 21) code block for weapon 1 ammo available would look like this…
if (buttonPushCounter2 <= 21) { // AMMO AVAILABLE
// play file 007.mp3 in folder advert01
mp3_play (7);
delay(30); // pause to wait mp3 start
digitalWrite(ledPin, HIGH); //red
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin9, HIGH);
delay(1);
digitalWrite(ledPin10, LOW);
digitalWrite(ledPin9, LOW);
delay(80); // partial lenght of sound
digitalWrite(ledPin, LOW);
delay(250); // pause to wait the sound finish
shotUpdate(buttonPushCounter2, 21); //<-- Add this line for each weapon
}
You will need to add this subroutine call for each weapon after the delay statement that pauses to wait for the sound effect to finish. Using the right buttonPushCounter# and maxAmmo number for each weapon.
Like I said. No way for me to ever test or debug this so all I can hope is that this gets you closer to what you want to do. You are sort of on your own from here. Hopefully you will eventually consider learning what each of the code statements is actually doing and improving the code some. Maybe start with naming variables with something more descriptive of their actual function. Then defining/storing weapon parameters in a structure or array and use some subroutines to reuse rather than repeat so much of the same code for each weapon. This looks like a really fun project and a great chance to learn more programming. Best of luck.