Hi there, my assignment this time is an extension on my previous one (in the link above).

It consists of 2 parts (I have done the first one):

### Scoring (use functions and loops)

Every time an invader gets obliterated, the player gets five points. Points are silently accumulated until the game is over. When an invader reaches the danger zone, the game stops and displays the score. The screen no longer goes red, it just displays the score on the right hand side of the screen.

### Many Invaders (use arrays and strings)

As the one invader moves to the left, new invaders come in behind it. A new invader should appear as soon as the first one is 70 pixels to the left. Every 70 pixels that the invaders move, another appears to the right. When the cannon is fired, the left-most matching invader is obliterated. To obliterate more than one of the same number you have to hit ājā multiple times. Every time an invader is obliterated, the space it occupied is taken up by the invader to its left. i.e. obliterating an invader causes all the invaders to the left of it to move rightwards into the empty space.

This is what I have done so far:

```
int invader;
int gap;
int x;
int y;
int weapon;
int boundary;
int score;
int scoreDigits;
int[] invaderHorde = {invader};
void showDangerZone(int w){
rectMode(CORNER);
stroke(166, 25, 46);
fill(166, 25, 46);
rect(0,0,w,height);
}
void showNumber(int x, int y, int n){
stroke(214, 210, 196);
fill(55, 58, 54);
if (n == 0){
a(x,y);b(x,y);c(x,y);d(x,y);e(x,y);f(x,y);
} else if (n == 1){
b(x,y);c(x,y);
} else if (n == 2){
a(x,y);b(x,y);d(x,y);e(x,y);g(x,y);
} else if (n == 3){
a(x,y);b(x,y);c(x,y);d(x,y);g(x,y);
} else if (n == 4){
b(x,y);c(x,y);f(x,y);g(x,y);
} else if (n == 5){
a(x,y);c(x,y);d(x,y);f(x,y);g(x,y);
} else if (n == 6){
a(x,y);c(x,y);d(x,y);e(x,y);f(x,y);g(x,y);
} else if (n == 7){
a(x,y);b(x,y);c(x,y);
} else if (n == 8){
a(x,y);b(x,y);c(x,y);d(x,y);e(x,y);f(x,y);g(x,y);
} else if (n == 9) {
a(x,y);b(x,y);c(x,y);d(x,y);f(x,y);g(x,y);
}
}
void a(int x, int y) {
beginShape();
vertex(x+10, y+10);
vertex(x+20, y+ 0);
vertex(x+40, y+ 0);
vertex(x+50, y+10);
vertex(x+40, y+20);
vertex(x+20, y+20);
endShape(CLOSE);
}
void b(int x, int y) {
beginShape();
vertex(x+50, y+10);
vertex(x+60, y+20);
vertex(x+60, y+40);
vertex(x+50, y+50);
vertex(x+40, y+40);
vertex(x+40, y+20);
endShape(CLOSE);
}
void c(int x, int y) {
beginShape();
vertex(x+50, y+50);
vertex(x+60, y+60);
vertex(x+60, y+80);
vertex(x+50, y+90);
vertex(x+40, y+80);
vertex(x+40, y+60);
endShape(CLOSE);
}
void d(int x, int y) {
beginShape();
vertex(x+10, y+ 90);
vertex(x+20, y+ 80);
vertex(x+40, y+ 80);
vertex(x+50, y+ 90);
vertex(x+40, y+100);
vertex(x+20, y+100);
endShape(CLOSE);
}
void e(int x, int y) {
beginShape();
vertex(x+10, y+50);
vertex(x+20, y+60);
vertex(x+20, y+80);
vertex(x+10, y+90);
vertex(x+ 0, y+80);
vertex(x+ 0, y+60);
endShape(CLOSE);
}
void f(int x, int y) {
beginShape();
vertex(x+10, y+10);
vertex(x+20, y+20);
vertex(x+20, y+40);
vertex(x+10, y+50);
vertex(x+ 0, y+40);
vertex(x+ 0, y+20);
endShape(CLOSE);
}
void g(int x, int y) {
beginShape();
vertex(x+20, y+40);
vertex(x+40, y+40);
vertex(x+50, y+50);
vertex(x+40, y+60);
vertex(x+20, y+60);
vertex(x+10, y+50);
endShape(CLOSE);
}
void weaponChanging(char w) {
if (key == w) {
weapon = (weapon + 1) % 10;
}
}
void weaponFiring(char w) {
if (key == w) {
if (weapon == invader) {
x = 8*width/9;
invader = (int)random(0, 10);
score = score + 5;
} else {
boundary = boundary + width/7;
}
}
}
void showScore(int a, int b) {
if (x <= boundary) {
fill(214, 210, 196);
rectMode(CORNER);
rect(0, 0, width, height);
noLoop();
if (a != 0) {
while (a != 0) {
showNumber(b, height/4, a%10);
a = a/10;
b = b - 70;
}
} else {
showNumber(b, height/4, 0);
}
}
}
void setup() {
size(800, 200);
invader = (int)random(0, 10);
weapon = 0;
x = 8*width/9;
y = height/4;
boundary = width/7;
score = 0;
scoreDigits = width - 60;
gap = 70;
}
void draw() {
background(214, 210, 196);
showDangerZone(boundary);
showNumber(width/25, height/4, weapon);
showNumber(x, y, invader);
x--;
showScore(score, scoreDigits);
}
void keyPressed() {
weaponChanging('f');
weaponFiring('j');
}
```

I donāt know how to properly initialise and make use of the array (in this case āinvaderHordeā) , as well as the āgapā variable to satisfy the second requirement of my assignment.

Can anyone be so kind as to help me with this?