How can I add 2 asteroids every time one gets shot instead of 1 to my game?
in
Programming Questions
•
5 months ago
The game currently adds just one asteroid every time one is destroyed. How can I add 2 asteroids each time?
- PFont fontA;
- int sphereDiameter = 20;
- boolean shoot = false;
- int randx()
- {
- return int(random(1000));
- }
- int[] sphereXCoords = {randx(), randx(), randx(), randx(), randx(), randx(), randx(), randx(), randx(), randx(), randx(), randx()};
- int[] sphereYCoords = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- void setup()
- {
- size(1000, 620);
- }
- void draw()
- {
- background(255);
- fill(color(0, 255, 0));
- stroke(color(0, 255, 0));
- beginShape();
- fill(102);
- stroke(255);
- strokeWeight(2);
- vertex(mouseX, 530);
- vertex(mouseX+10, 550);
- vertex(mouseX+40,580);
- vertex(mouseX+50,585);
- vertex(mouseX+55, 570);
- vertex(mouseX+60, 575);
- vertex(mouseX+75, 590);
- vertex(mouseX+5, 605);
- vertex(mouseX+10, 615);
- vertex(mouseX-10, 625);
- vertex(mouseX-5, 605);
- vertex(mouseX-75, 590);
- vertex(mouseX-60, 585);
- vertex(mouseX-55,570);
- vertex(mouseX-50,585);
- vertex(mouseX-40,580);
- vertex(mouseX-10,550);
- endShape(CLOSE);
- fill(color(255, 0, 0));
- stroke(color(255, 0, 0));
- if (shoot==true)
- {
- sphereKiller(mouseX);
- shoot = false;
- }
- sphereDropper();
- gameEnder();
- }
- void mousePressed()
- {
- shoot = true;
- }
- void sphereDropper()
- {
- stroke(87,54,10);
- fill(87,54,10);
- for (int i=0; i<5; i++)
- {
- ellipse(sphereXCoords[i], sphereYCoords[i]++,
- sphereDiameter, sphereDiameter);
- }
- }
- void sphereKiller(int shotX)
- {
- boolean hit = false;
- for (int i=0; i<5; i++)
- {
- if ((shotX >= (sphereXCoords[i]-sphereDiameter/2)) &&
- (shotX <= (sphereXCoords[i]+sphereDiameter/2)))
- {
- hit = true;
- line(mouseX, 532, mouseX, sphereYCoords[i]);
- ellipse(sphereXCoords[i], sphereYCoords[i],
- sphereDiameter+25, sphereDiameter+25);
- sphereXCoords[i] = randx();
- sphereYCoords[i] = 0;
- }
- }
- if (hit == false)
- {
- line(mouseX, 532, mouseX, 0);
- }
- }
- void gameEnder()
- {
- for (int i=0; i<5; i++)
- {
- if (sphereYCoords[i]==600)
- {
- fill(color(255, 0, 0));
- noLoop();
- }
- }
- }
1